mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-03 09:23:01 +01:00
miner: Pass in chainman to RegenerateCommitments
Pass in chainman instead of prev_block so that we can enforce the block.hashPrevBlock refers to prev_block invariant in the function itself. We should probably rethink BlockAssembler's API and somehow include commitment regeneration functionality in there. Something like a variant of CreateNewBlock that takes in a std::vector<TxRef> and return a CBlock instead of CBlockTemplate. That could avoid reaching for LookupBlockIndex at all.
This commit is contained in:
@@ -39,13 +39,21 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
|
||||
return nNewTime - nOldTime;
|
||||
}
|
||||
|
||||
void RegenerateCommitments(CBlock& block, CBlockIndex* prev_block)
|
||||
void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
|
||||
{
|
||||
CMutableTransaction tx{*block.vtx.at(0)};
|
||||
tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
|
||||
block.vtx.at(0) = MakeTransactionRef(tx);
|
||||
|
||||
WITH_LOCK(::cs_main, assert(g_chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock) == prev_block));
|
||||
CBlockIndex* prev_block;
|
||||
{
|
||||
// TODO: Temporary scope to check correctness of refactored code.
|
||||
// Should be removed manually after merge of
|
||||
// https://github.com/bitcoin/bitcoin/pull/20158
|
||||
LOCK(::cs_main);
|
||||
assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman.m_blockman));
|
||||
prev_block = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
|
||||
}
|
||||
GenerateCoinbaseCommitment(block, prev_block, Params().GetConsensus());
|
||||
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
|
||||
Reference in New Issue
Block a user