aboutsummaryrefslogtreecommitdiff
path: root/src/miner.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-03-17 16:32:24 -0400
committerCarl Dong <contact@carldong.me>2021-03-24 15:40:56 -0400
commit7b8e976cd5ac78a22f1be2b2fed8562c693af5d9 (patch)
tree7cc8c7b03ef9b139d8dc5bc258cd848fc9dfc5a1 /src/miner.cpp
parente62067e7bcad5a559899afff2e4a8e8b7e9f4301 (diff)
downloadbitcoin-7b8e976cd5ac78a22f1be2b2fed8562c693af5d9.tar.xz
miner: Add chainstate member to BlockAssembler
Diffstat (limited to 'src/miner.cpp')
-rw-r--r--src/miner.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/miner.cpp b/src/miner.cpp
index da2413d06b..8a9406f810 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -55,9 +55,10 @@ BlockAssembler::Options::Options() {
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
}
-BlockAssembler::BlockAssembler(const CTxMemPool& mempool, const CChainParams& params, const Options& options)
+BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options)
: chainparams(params),
- m_mempool(mempool)
+ m_mempool(mempool),
+ m_chainstate(chainstate)
{
blockMinFeeRate = options.blockMinFeeRate;
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
@@ -79,8 +80,8 @@ static BlockAssembler::Options DefaultOptions()
return options;
}
-BlockAssembler::BlockAssembler(const CTxMemPool& mempool, const CChainParams& params)
- : BlockAssembler(mempool, params, DefaultOptions()) {}
+BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params)
+ : BlockAssembler(chainstate, mempool, params, DefaultOptions()) {}
void BlockAssembler::resetBlock()
{
@@ -114,7 +115,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(*m_chainstate.m_chain.Tip()));
+ CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1;
@@ -173,7 +175,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(m_chainstate));
+ if (!TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev, false, false)) {
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
}
int64_t nTime2 = GetTimeMicros();