Skip to content

Commit f11d116

Browse files
committed
validation: Move GetLastCheckpoint to BlockManager
[META] This commit should be followed up by removing the comments and assertions meant only to show that the change is correct. GetLastCheckPoint mainly acts on BlockManager.
1 parent e4b95ee commit f11d116

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,15 +3401,15 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
34013401
return commitment;
34023402
}
34033403

3404-
//! Returns last CBlockIndex* that is a checkpoint
3405-
static CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
3404+
CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
34063405
{
34073406
const MapCheckpoints& checkpoints = data.mapCheckpoints;
34083407

34093408
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
34103409
{
34113410
const uint256& hash = i.second;
3412-
CBlockIndex* pindex = g_chainman.m_blockman.LookupBlockIndex(hash);
3411+
assert(std::addressof(g_chainman.m_blockman) == std::addressof(*this));
3412+
CBlockIndex* pindex = LookupBlockIndex(hash);
34133413
if (pindex) {
34143414
return pindex;
34153415
}
@@ -3441,7 +3441,7 @@ 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 = GetLastCheckpoint(params.Checkpoints());
3444+
CBlockIndex* pcheckpoint = g_chainman.m_blockman.GetLastCheckpoint(params.Checkpoints());
34453445
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
34463446
LogPrintf("ERROR: %s: forked chain older than last checkpoint (height %d)\n", __func__, nHeight);
34473447
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "bad-fork-prior-to-checkpoint");

src/validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CBlockIndex;
4040
class CBlockTreeDB;
4141
class CBlockUndo;
4242
class CChainParams;
43+
class CCheckpointData;
4344
class CInv;
4445
class CConnman;
4546
class CScriptCheck;
@@ -433,6 +434,9 @@ class BlockManager
433434
/** Find the last common block between the parameter chain and a locator. */
434435
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
435436

437+
//! Returns last CBlockIndex* that is a checkpoint
438+
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
439+
436440
/**
437441
* Return the spend height, which is one more than the inputs.GetBestBlock().
438442
* While checking, GetBestBlock() refers to the parent block. (protected by cs_main)

0 commit comments

Comments
 (0)