88#include < arith_uint256.h>
99#include < chain.h>
1010#include < chainparams.h>
11- #include < checkpoints.h>
1211#include < checkqueue.h>
1312#include < consensus/consensus.h>
1413#include < consensus/merkle.h>
3534#include < txdb.h>
3635#include < txmempool.h>
3736#include < ui_interface.h>
37+ #include < uint256.h>
3838#include < undo.h>
3939#include < util/moneystr.h>
4040#include < util/strencodings.h>
@@ -3196,6 +3196,22 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
31963196 return commitment;
31973197}
31983198
3199+ // ! Returns last CBlockIndex* that is a checkpoint
3200+ static CBlockIndex* GetLastCheckpoint (const CCheckpointData& data)
3201+ {
3202+ const MapCheckpoints& checkpoints = data.mapCheckpoints ;
3203+
3204+ for (const MapCheckpoints::value_type& i : reverse_iterate (checkpoints))
3205+ {
3206+ const uint256& hash = i.second ;
3207+ CBlockIndex* pindex = LookupBlockIndex (hash);
3208+ if (pindex) {
3209+ return pindex;
3210+ }
3211+ }
3212+ return nullptr ;
3213+ }
3214+
31993215/* * Context-dependent validity checks.
32003216 * By "context", we mean only the previous block headers, but not the UTXO
32013217 * set; UTXO-related validity checks are done in ConnectBlock().
@@ -3220,7 +3236,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
32203236 // Don't accept any forks from the main chain prior to last checkpoint.
32213237 // GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
32223238 // MapBlockIndex.
3223- CBlockIndex* pcheckpoint = Checkpoints:: GetLastCheckpoint (params.Checkpoints ());
3239+ CBlockIndex* pcheckpoint = GetLastCheckpoint (params.Checkpoints ());
32243240 if (pcheckpoint && nHeight < pcheckpoint->nHeight )
32253241 return state.DoS (100 , error (" %s: forked chain older than last checkpoint (height %d)" , __func__, nHeight), REJECT_CHECKPOINT, " bad-fork-prior-to-checkpoint" );
32263242 }
0 commit comments