mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
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.
This commit is contained in:
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user