Skip to content

Commit eaa2e3f

Browse files
committed
validation: move UpdateUncommittedBlockStructures and GenerateCoinbaseCommitment into ChainstateManager
1 parent 5c67e84 commit eaa2e3f

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int main(int argc, char* argv[])
163163
LOCK(cs_main);
164164
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
165165
if (pindex) {
166-
UpdateUncommittedBlockStructures(block, pindex, chainparams.GetConsensus());
166+
chainman.UpdateUncommittedBlockStructures(block, pindex);
167167
}
168168
}
169169

src/node/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
5151
block.vtx.at(0) = MakeTransactionRef(tx);
5252

5353
const CBlockIndex* prev_block = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
54-
GenerateCoinbaseCommitment(block, prev_block, Params().GetConsensus());
54+
chainman.GenerateCoinbaseCommitment(block, prev_block);
5555

5656
block.hashMerkleRoot = BlockMerkleRoot(block);
5757
}
@@ -154,7 +154,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
154154
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
155155
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
156156
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
157-
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
157+
pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
158158
pblocktemplate->vTxFees[0] = -nFees;
159159

160160
LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static RPCHelpMan submitblock()
993993
LOCK(cs_main);
994994
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
995995
if (pindex) {
996-
UpdateUncommittedBlockStructures(block, pindex, Params().GetConsensus());
996+
chainman.UpdateUncommittedBlockStructures(block, pindex);
997997
}
998998
}
999999

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
8989
std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock> pblock)
9090
{
9191
const CBlockIndex* prev_block{WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(pblock->hashPrevBlock))};
92-
GenerateCoinbaseCommitment(*pblock, prev_block, Params().GetConsensus());
92+
m_node.chainman->GenerateCoinbaseCommitment(*pblock, prev_block);
9393

9494
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
9595

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,19 +3398,19 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
33983398
return true;
33993399
}
34003400

3401-
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
3401+
void ChainstateManager::UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const
34023402
{
34033403
int commitpos = GetWitnessCommitmentIndex(block);
34043404
static const std::vector<unsigned char> nonce(32, 0x00);
3405-
if (commitpos != NO_WITNESS_COMMITMENT && DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT) && !block.vtx[0]->HasWitness()) {
3405+
if (commitpos != NO_WITNESS_COMMITMENT && DeploymentActiveAfter(pindexPrev, GetConsensus(), Consensus::DEPLOYMENT_SEGWIT) && !block.vtx[0]->HasWitness()) {
34063406
CMutableTransaction tx(*block.vtx[0]);
34073407
tx.vin[0].scriptWitness.stack.resize(1);
34083408
tx.vin[0].scriptWitness.stack[0] = nonce;
34093409
block.vtx[0] = MakeTransactionRef(std::move(tx));
34103410
}
34113411
}
34123412

3413-
std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
3413+
std::vector<unsigned char> ChainstateManager::GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const
34143414
{
34153415
std::vector<unsigned char> commitment;
34163416
int commitpos = GetWitnessCommitmentIndex(block);
@@ -3433,7 +3433,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
34333433
tx.vout.push_back(out);
34343434
block.vtx[0] = MakeTransactionRef(std::move(tx));
34353435
}
3436-
UpdateUncommittedBlockStructures(block, pindexPrev, consensusParams);
3436+
UpdateUncommittedBlockStructures(block, pindexPrev);
34373437
return commitment;
34383438
}
34393439

src/validation.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,6 @@ bool TestBlockValidity(BlockValidationState& state,
362362
bool fCheckPOW = true,
363363
bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
364364

365-
/** Update uncommitted block structures (currently: only the witness reserved value). This is safe for submitted blocks. */
366-
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
367-
368-
/** Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). */
369-
std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
370-
371365
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
372366
class CVerifyDB {
373367
public:
@@ -1000,6 +994,12 @@ class ChainstateManager
1000994
//! ResizeCoinsCaches() as needed.
1001995
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1002996

997+
/** Update uncommitted block structures (currently: only the witness reserved value). This is safe for submitted blocks. */
998+
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const;
999+
1000+
/** Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). */
1001+
std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const;
1002+
10031003
~ChainstateManager();
10041004
};
10051005

0 commit comments

Comments
 (0)