Skip to content

Commit d0de61b

Browse files
committed
miner: Pass in chainstate to BlockAssembler::CreateNewBlock
1 parent a04aac4 commit d0de61b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/miner.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
100100
Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
101101

102102
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)
103108
{
104109
int64_t nTimeStart = GetTimeMicros();
105110

@@ -117,7 +122,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
117122
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
118123

119124
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();
121127
assert(pindexPrev != nullptr);
122128
nHeight = pindexPrev->nHeight + 1;
123129

@@ -176,7 +182,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
176182
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
177183

178184
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)) {
180187
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
181188
}
182189
int64_t nTime2 = GetTimeMicros();

src/miner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class BlockAssembler
159159

160160
/** Construct a new block template with coinbase to scriptPubKeyIn */
161161
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);
162+
std::unique_ptr<CBlockTemplate> CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn);
162163

163164
static Optional<int64_t> m_last_block_num_txs;
164165
static Optional<int64_t> m_last_block_weight;

0 commit comments

Comments
 (0)