@@ -2223,7 +2223,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2223
2223
int64_t nTimeStart = GetTimeMicros ();
2224
2224
2225
2225
// Check it again in case a previous version let a bad block in
2226
- if (!CheckBlock (block, state, !fJustCheck , !fJustCheck ))
2226
+ if (!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime (), !fJustCheck , !fJustCheck ))
2227
2227
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
2228
2228
2229
2229
// verify that the view's current state corresponds to the previous block
@@ -3234,20 +3234,20 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
3234
3234
return true ;
3235
3235
}
3236
3236
3237
- bool CheckBlockHeader (const CBlockHeader& block, CValidationState& state, bool fCheckPOW )
3237
+ bool CheckBlockHeader (const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, int64_t nAdjustedTime, bool fCheckPOW )
3238
3238
{
3239
3239
// Check proof of work matches claimed amount
3240
- if (fCheckPOW && !CheckProofOfWork (block.GetHash (), block.nBits , Params (). GetConsensus () ))
3240
+ if (fCheckPOW && !CheckProofOfWork (block.GetHash (), block.nBits , consensusParams ))
3241
3241
return state.DoS (50 , false , REJECT_INVALID, " high-hash" , false , " proof of work failed" );
3242
3242
3243
3243
// Check timestamp
3244
- if (block.GetBlockTime () > GetAdjustedTime () + 2 * 60 * 60 )
3244
+ if (block.GetBlockTime () > nAdjustedTime + 2 * 60 * 60 )
3245
3245
return state.Invalid (false , REJECT_INVALID, " time-too-new" , " block timestamp too far in the future" );
3246
3246
3247
3247
return true ;
3248
3248
}
3249
3249
3250
- bool CheckBlock (const CBlock& block, CValidationState& state, bool fCheckPOW , bool fCheckMerkleRoot )
3250
+ bool CheckBlock (const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, int64_t nAdjustedTime, bool fCheckPOW , bool fCheckMerkleRoot )
3251
3251
{
3252
3252
// These are checks that are independent of context.
3253
3253
@@ -3256,7 +3256,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
3256
3256
3257
3257
// Check that the header is valid (particularly PoW). This is mostly
3258
3258
// redundant with the call in AcceptBlockHeader.
3259
- if (!CheckBlockHeader (block, state, fCheckPOW ))
3259
+ if (!CheckBlockHeader (block, state, consensusParams, nAdjustedTime, fCheckPOW ))
3260
3260
return false ;
3261
3261
3262
3262
// Check the merkle root.
@@ -3322,9 +3322,8 @@ static bool CheckIndexAgainstCheckpoint(const CBlockIndex* pindexPrev, CValidati
3322
3322
return true ;
3323
3323
}
3324
3324
3325
- bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev)
3325
+ bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex * const pindexPrev)
3326
3326
{
3327
- const Consensus::Params& consensusParams = Params ().GetConsensus ();
3328
3327
// Check proof of work
3329
3328
if (block.nBits != GetNextWorkRequired (pindexPrev, &block, consensusParams))
3330
3329
return state.DoS (100 , false , REJECT_INVALID, " bad-diffbits" , false , " incorrect proof of work" );
@@ -3397,7 +3396,7 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3397
3396
return true ;
3398
3397
}
3399
3398
3400
- if (!CheckBlockHeader (block, state))
3399
+ if (!CheckBlockHeader (block, state, chainparams. GetConsensus (), GetAdjustedTime () ))
3401
3400
return error (" %s: Consensus::CheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
3402
3401
3403
3402
// Get prev block index
@@ -3413,7 +3412,7 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3413
3412
if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint (pindexPrev, state, chainparams, hash))
3414
3413
return error (" %s: CheckIndexAgainstCheckpoint(): %s" , __func__, state.GetRejectReason ().c_str ());
3415
3414
3416
- if (!ContextualCheckBlockHeader (block, state, pindexPrev))
3415
+ if (!ContextualCheckBlockHeader (block, state, chainparams. GetConsensus (), pindexPrev))
3417
3416
return error (" %s: Consensus::ContextualCheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
3418
3417
}
3419
3418
if (pindex == NULL )
@@ -3457,7 +3456,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
3457
3456
if (fTooFarAhead ) return true ; // Block height is too high
3458
3457
}
3459
3458
3460
- if ((!CheckBlock (block, state)) || !ContextualCheckBlock (block, state, pindex->pprev )) {
3459
+ if ((!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime () )) || !ContextualCheckBlock (block, state, pindex->pprev )) {
3461
3460
if (state.IsInvalid () && !state.CorruptionPossible ()) {
3462
3461
pindex->nStatus |= BLOCK_FAILED_VALID;
3463
3462
setDirtyBlockIndex.insert (pindex);
@@ -3542,9 +3541,9 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
3542
3541
indexDummy.nHeight = pindexPrev->nHeight + 1 ;
3543
3542
3544
3543
// NOTE: CheckBlockHeader is called by CheckBlock
3545
- if (!ContextualCheckBlockHeader (block, state, pindexPrev))
3544
+ if (!ContextualCheckBlockHeader (block, state, chainparams. GetConsensus (), pindexPrev))
3546
3545
return error (" %s: Consensus::ContextualCheckBlockHeader: %s" , __func__, FormatStateMessage (state));
3547
- if (!CheckBlock (block, state, fCheckPOW , fCheckMerkleRoot ))
3546
+ if (!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime (), fCheckPOW , fCheckMerkleRoot ))
3548
3547
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
3549
3548
if (!ContextualCheckBlock (block, state, pindexPrev))
3550
3549
return error (" %s: Consensus::ContextualCheckBlock: %s" , __func__, FormatStateMessage (state));
@@ -3876,7 +3875,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3876
3875
if (!ReadBlockFromDisk (block, pindex, chainparams.GetConsensus ()))
3877
3876
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3878
3877
// check level 1: verify block validity
3879
- if (nCheckLevel >= 1 && !CheckBlock (block, state))
3878
+ if (nCheckLevel >= 1 && !CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime () ))
3880
3879
return error (" %s: *** found bad block at %d, hash=%s (%s)\n " , __func__,
3881
3880
pindex->nHeight , pindex->GetBlockHash ().ToString (), FormatStateMessage (state));
3882
3881
// check level 2: verify undo validity
0 commit comments