diff options
author | Carl Dong <contact@carldong.me> | 2020-09-30 17:02:51 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-01-28 14:15:26 -0500 |
commit | 9c300cc8b3ce3d82874982fbf3087e48a6ac0ef2 (patch) | |
tree | c97b5a6ae6098a87906879fcf2d19224a1a9c1a4 /src/validation.cpp | |
parent | 0e17c833cda67cdba5338bd7409061772b6d5edb (diff) |
validation: Pass in chainstate to TestBlockValidity
[META] This commit should be followed up by removing the comments and
assertions meant only to show that the change is correct.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 3a9ad5844e..f7aca45e66 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3809,11 +3809,12 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s return true; } -bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) +bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainparams, CChainState& chainstate, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) { AssertLockHeld(cs_main); - assert(pindexPrev && pindexPrev == ::ChainActive().Tip()); - CCoinsViewCache viewNew(&::ChainstateActive().CoinsTip()); + assert(std::addressof(::ChainstateActive()) == std::addressof(chainstate)); + assert(pindexPrev && pindexPrev == chainstate.m_chain.Tip()); + CCoinsViewCache viewNew(&chainstate.CoinsTip()); uint256 block_hash(block.GetHash()); CBlockIndex indexDummy(block); indexDummy.pprev = pindexPrev; @@ -3821,13 +3822,14 @@ bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainpar indexDummy.phashBlock = &block_hash; // NOTE: CheckBlockHeader is called by CheckBlock - if (!ContextualCheckBlockHeader(block, state, g_chainman.m_blockman, chainparams, pindexPrev, GetAdjustedTime())) + assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainstate.m_blockman)); + if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainparams, pindexPrev, GetAdjustedTime())) return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString()); if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString()); if (!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindexPrev)) return error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString()); - if (!::ChainstateActive().ConnectBlock(block, state, &indexDummy, viewNew, chainparams, true)) + if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, chainparams, true)) return false; assert(state.IsValid()); |