Skip to content

Commit d363d06

Browse files
committed
validation: Pass in blockman to ContextualCheckBlockHeader
[META] This commit should be followed up by removing the comments and assertions meant only to show that the change is correct.
1 parent f11d116 commit d363d06

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,7 +3426,7 @@ CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
34263426
* in ConnectBlock().
34273427
* Note that -reindex-chainstate skips the validation that happens here!
34283428
*/
3429-
static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidationState& state, const CChainParams& params, const CBlockIndex* pindexPrev, int64_t nAdjustedTime) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
3429+
static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidationState& state, BlockManager& blockman, const CChainParams& params, const CBlockIndex* pindexPrev, int64_t nAdjustedTime) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
34303430
{
34313431
assert(pindexPrev != nullptr);
34323432
const int nHeight = pindexPrev->nHeight + 1;
@@ -3441,7 +3441,8 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
34413441
// Don't accept any forks from the main chain prior to last checkpoint.
34423442
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
34433443
// BlockIndex().
3444-
CBlockIndex* pcheckpoint = g_chainman.m_blockman.GetLastCheckpoint(params.Checkpoints());
3444+
assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman));
3445+
CBlockIndex* pcheckpoint = blockman.GetLastCheckpoint(params.Checkpoints());
34453446
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
34463447
LogPrintf("ERROR: %s: forked chain older than last checkpoint (height %d)\n", __func__, nHeight);
34473448
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "bad-fork-prior-to-checkpoint");
@@ -3592,7 +3593,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
35923593
LogPrintf("ERROR: %s: prev block invalid\n", __func__);
35933594
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
35943595
}
3595-
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
3596+
if (!ContextualCheckBlockHeader(block, state, *this, chainparams, pindexPrev, GetAdjustedTime()))
35963597
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), state.ToString());
35973598

35983599
/* Determine if this block descends from any block which has been found
@@ -3820,7 +3821,7 @@ bool TestBlockValidity(BlockValidationState& state, const CChainParams& chainpar
38203821
indexDummy.phashBlock = &block_hash;
38213822

38223823
// NOTE: CheckBlockHeader is called by CheckBlock
3823-
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
3824+
if (!ContextualCheckBlockHeader(block, state, g_chainman.m_blockman, chainparams, pindexPrev, GetAdjustedTime()))
38243825
return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString());
38253826
if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot))
38263827
return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());

0 commit comments

Comments
 (0)