Skip to content

Commit cced0f4

Browse files
committed
miner: Pass in previous CBlockIndex to RegenerateCommitments
1 parent 66daf4c commit cced0f4

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/miner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
3939
return nNewTime - nOldTime;
4040
}
4141

42-
void RegenerateCommitments(CBlock& block, BlockManager& blockman)
42+
void RegenerateCommitments(CBlock& block, CBlockIndex* prev_block)
4343
{
4444
CMutableTransaction tx{*block.vtx.at(0)};
4545
tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
4646
block.vtx.at(0) = MakeTransactionRef(tx);
4747

48-
GenerateCoinbaseCommitment(block, WITH_LOCK(::cs_main, assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); return blockman.LookupBlockIndex(block.hashPrevBlock)), Params().GetConsensus());
48+
WITH_LOCK(::cs_main, assert(g_chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock) == prev_block));
49+
GenerateCoinbaseCommitment(block, prev_block, Params().GetConsensus());
4950

5051
block.hashMerkleRoot = BlockMerkleRoot(block);
5152
}

src/miner.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ class BlockAssembler
202202
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
203203
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
204204

205-
// TODO just accept a CBlockIndex*
206205
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
207-
void RegenerateCommitments(CBlock& block, BlockManager& blockman);
206+
void RegenerateCommitments(CBlock& block, CBlockIndex* prev_block);
208207

209208
#endif // BITCOIN_MINER_H

src/rpc/mining.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ static RPCHelpMan generateblock()
369369

370370
// Add transactions
371371
block.vtx.insert(block.vtx.end(), txs.begin(), txs.end());
372-
RegenerateCommitments(block, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)));
372+
CBlockIndex* prev_block = WITH_LOCK(::cs_main, return g_chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
373+
RegenerateCommitments(block, prev_block);
373374

374375
{
375376
LOCK(cs_main);

src/test/util/setup_common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransa
253253
for (const CMutableTransaction& tx : txns) {
254254
block.vtx.push_back(MakeTransactionRef(tx));
255255
}
256-
RegenerateCommitments(block, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)));
256+
CBlockIndex* prev_block = WITH_LOCK(::cs_main, return g_chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
257+
RegenerateCommitments(block, prev_block);
257258

258259
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
259260

0 commit comments

Comments
 (0)