aboutsummaryrefslogtreecommitdiff
path: root/src/miner.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-11-04 19:25:46 -0500
committerCarl Dong <contact@carldong.me>2021-03-08 15:54:31 -0500
commitd0de61b764fc7e9c670b69d8210705da296dd245 (patch)
treef77ba3e226caf128dd2cf2a826d87c6ce812376e /src/miner.cpp
parenta04aac493fd564894166d58ed4cdfd9ad4f561cb (diff)
downloadbitcoin-d0de61b764fc7e9c670b69d8210705da296dd245.tar.xz
miner: Pass in chainstate to BlockAssembler::CreateNewBlock
Diffstat (limited to 'src/miner.cpp')
-rw-r--r--src/miner.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/miner.cpp b/src/miner.cpp
index 076d43c951..e0e5ad41fe 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -101,6 +101,11 @@ Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
{
+ return CreateNewBlock(::ChainstateActive(), scriptPubKeyIn);
+}
+
+std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn)
+{
int64_t nTimeStart = GetTimeMicros();
resetBlock();
@@ -117,7 +122,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
LOCK2(cs_main, m_mempool.cs);
- CBlockIndex* pindexPrev = ::ChainActive().Tip();
+ assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*chainstate.m_chain.Tip()));
+ CBlockIndex* pindexPrev = chainstate.m_chain.Tip();
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1;
@@ -176,7 +182,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
BlockValidationState state;
- if (!TestBlockValidity(state, chainparams, ::ChainstateActive(), *pblock, pindexPrev, false, false)) {
+ assert(std::addressof(::ChainstateActive()) == std::addressof(chainstate));
+ if (!TestBlockValidity(state, chainparams, chainstate, *pblock, pindexPrev, false, false)) {
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
}
int64_t nTime2 = GetTimeMicros();