@@ -100,6 +100,11 @@ Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
100
100
Optional<int64_t > BlockAssembler::m_last_block_weight{nullopt};
101
101
102
102
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock (const CScript& scriptPubKeyIn)
103
+ {
104
+ return CreateNewBlock (::ChainstateActive (), scriptPubKeyIn);
105
+ }
106
+
107
+ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock (CChainState& chainstate, const CScript& scriptPubKeyIn)
103
108
{
104
109
int64_t nTimeStart = GetTimeMicros ();
105
110
@@ -117,7 +122,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
117
122
pblocktemplate->vTxSigOpsCost .push_back (-1 ); // updated at end
118
123
119
124
LOCK2 (cs_main, m_mempool.cs );
120
- CBlockIndex* pindexPrev = ::ChainActive ().Tip ();
125
+ assert (std::addressof (*::ChainActive ().Tip ()) == std::addressof (*chainstate.m_chain .Tip ()));
126
+ CBlockIndex* pindexPrev = chainstate.m_chain .Tip ();
121
127
assert (pindexPrev != nullptr );
122
128
nHeight = pindexPrev->nHeight + 1 ;
123
129
@@ -176,7 +182,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
176
182
pblocktemplate->vTxSigOpsCost [0 ] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount (*pblock->vtx [0 ]);
177
183
178
184
BlockValidationState state;
179
- if (!TestBlockValidity (state, chainparams, ::ChainstateActive (), *pblock, pindexPrev, false , false )) {
185
+ assert (std::addressof (::ChainstateActive ()) == std::addressof (chainstate));
186
+ if (!TestBlockValidity (state, chainparams, chainstate, *pblock, pindexPrev, false , false )) {
180
187
throw std::runtime_error (strprintf (" %s: TestBlockValidity failed: %s" , __func__, state.ToString ()));
181
188
}
182
189
int64_t nTime2 = GetTimeMicros ();
0 commit comments