@@ -2999,20 +2999,6 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
2999
2999
return true ;
3000
3000
}
3001
3001
3002
- static bool CheckIndexAgainstCheckpoint (const CBlockIndex* pindexPrev, CValidationState& state, const CChainParams& chainparams, const uint256& hash)
3003
- {
3004
- if (*pindexPrev->phashBlock == chainparams.GetConsensus (0 ).hashGenesisBlock )
3005
- return true ;
3006
-
3007
- int nHeight = pindexPrev->nHeight +1 ;
3008
- // Don't accept any forks from the main chain prior to last checkpoint
3009
- CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint (chainparams.Checkpoints ());
3010
- if (pcheckpoint && nHeight < pcheckpoint->nHeight )
3011
- return state.DoS (100 , error (" %s: forked chain older than last checkpoint (height %d)" , __func__, nHeight));
3012
-
3013
- return true ;
3014
- }
3015
-
3016
3002
bool IsWitnessEnabled (const CBlockIndex* pindexPrev, const Consensus::Params& params)
3017
3003
{
3018
3004
// Dogecoin: Disable SegWit
@@ -3080,7 +3066,8 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
3080
3066
bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
3081
3067
{
3082
3068
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1 ;
3083
- const Consensus::Params& consensusParams = Params ().GetConsensus (nHeight);
3069
+ const CChainParams& params = Params ();
3070
+ const Consensus::Params& consensusParams = params.GetConsensus (nHeight);
3084
3071
3085
3072
// Disallow legacy blocks after merge-mining start.
3086
3073
if (!consensusParams.fAllowLegacyBlocks
@@ -3102,6 +3089,16 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
3102
3089
if (block.nBits != GetNextWorkRequired (pindexPrev, &block, consensusParams))
3103
3090
return state.DoS (100 , false , REJECT_INVALID, " bad-diffbits" , false , " incorrect proof of work" );
3104
3091
3092
+ // Check against checkpoints
3093
+ if (fCheckpointsEnabled ) {
3094
+ // Don't accept any forks from the main chain prior to last checkpoint.
3095
+ // GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
3096
+ // MapBlockIndex.
3097
+ CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint (params.Checkpoints ());
3098
+ if (pcheckpoint && nHeight < pcheckpoint->nHeight )
3099
+ return state.DoS (100 , error (" %s: forked chain older than last checkpoint (height %d)" , __func__, nHeight), REJECT_CHECKPOINT, " bad-fork-prior-to-checkpoint" );
3100
+ }
3101
+
3105
3102
// Check timestamp against prev
3106
3103
if (block.GetBlockTime () <= pindexPrev->GetMedianTimePast ())
3107
3104
return state.Invalid (false , REJECT_INVALID, " time-too-old" , " block's timestamp is too early" );
@@ -3237,8 +3234,6 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3237
3234
return state.DoS (100 , error (" %s: prev block invalid" , __func__), REJECT_INVALID, " bad-prevblk" );
3238
3235
3239
3236
assert (pindexPrev);
3240
- if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint (pindexPrev, state, chainparams, hash))
3241
- return error (" %s: CheckIndexAgainstCheckpoint(): %s" , __func__, state.GetRejectReason ().c_str ());
3242
3237
3243
3238
if (!ContextualCheckBlockHeader (block, state, pindexPrev, GetAdjustedTime ()))
3244
3239
return error (" %s: Consensus::ContextualCheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
@@ -3418,9 +3413,6 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
3418
3413
{
3419
3414
AssertLockHeld (cs_main);
3420
3415
assert (pindexPrev && pindexPrev == chainActive.Tip ());
3421
- if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint (pindexPrev, state, chainparams, block.GetHash ()))
3422
- return error (" %s: CheckIndexAgainstCheckpoint(): %s" , __func__, state.GetRejectReason ().c_str ());
3423
-
3424
3416
CCoinsViewCache viewNew (pcoinsTip);
3425
3417
CBlockIndex indexDummy (block);
3426
3418
indexDummy.pprev = pindexPrev;
0 commit comments