Skip to content

Commit 5b669ff

Browse files
Cache the result of chainparams.GetConsensus() in miner code
1 parent 2941d41 commit 5b669ff

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/node/miner.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
134134
assert(pindexPrev != nullptr);
135135
nHeight = pindexPrev->nHeight + 1;
136136

137-
pblock->nVersion = m_chainstate.m_chainman.m_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
137+
const Consensus::Params& consensusParams = chainparams.GetConsensus();
138+
139+
pblock->nVersion = m_chainstate.m_chainman.m_versionbitscache.ComputeBlockVersion(pindexPrev, consensusParams);
138140
// -regtest only: allow overriding block.nVersion with
139141
// -blockversion=N to test forking scenarios
140142
if (chainparams.MineBlocksOnDemand()) {
@@ -161,7 +163,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
161163
coinbaseTx.vin[0].prevout.SetNull();
162164
coinbaseTx.vout.resize(1);
163165
coinbaseTx.vout[0].scriptPubKey = m_options.coinbase_output_script;
164-
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
166+
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, consensusParams);
165167
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
166168
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
167169
pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
@@ -171,8 +173,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
171173

172174
// Fill in header
173175
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
174-
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
175-
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
176+
UpdateTime(pblock, consensusParams, pindexPrev);
177+
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
176178
pblock->nNonce = 0;
177179
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
178180

0 commit comments

Comments
 (0)