@@ -2228,7 +2228,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2228
2228
int64_t nTimeStart = GetTimeMicros ();
2229
2229
2230
2230
// Check it again in case a previous version let a bad block in
2231
- if (!CheckBlock (block, state, !fJustCheck , !fJustCheck ))
2231
+ if (!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime (), !fJustCheck , !fJustCheck ))
2232
2232
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
2233
2233
2234
2234
// verify that the view's current state corresponds to the previous block
@@ -3243,20 +3243,20 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
3243
3243
return true ;
3244
3244
}
3245
3245
3246
- bool CheckBlockHeader (const CBlockHeader& block, CValidationState& state, bool fCheckPOW )
3246
+ bool CheckBlockHeader (const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, int64_t nAdjustedTime, bool fCheckPOW )
3247
3247
{
3248
3248
// Check proof of work matches claimed amount
3249
- if (fCheckPOW && !CheckProofOfWork (block.GetHash (), block.nBits , Params (). GetConsensus () ))
3249
+ if (fCheckPOW && !CheckProofOfWork (block.GetHash (), block.nBits , consensusParams ))
3250
3250
return state.DoS (50 , false , REJECT_INVALID, " high-hash" , false , " proof of work failed" );
3251
3251
3252
3252
// Check timestamp
3253
- if (block.GetBlockTime () > GetAdjustedTime () + 2 * 60 * 60 )
3253
+ if (block.GetBlockTime () > nAdjustedTime + 2 * 60 * 60 )
3254
3254
return state.Invalid (false , REJECT_INVALID, " time-too-new" , " block timestamp too far in the future" );
3255
3255
3256
3256
return true ;
3257
3257
}
3258
3258
3259
- bool CheckBlock (const CBlock& block, CValidationState& state, bool fCheckPOW , bool fCheckMerkleRoot )
3259
+ bool CheckBlock (const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, int64_t nAdjustedTime, bool fCheckPOW , bool fCheckMerkleRoot )
3260
3260
{
3261
3261
// These are checks that are independent of context.
3262
3262
@@ -3265,7 +3265,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
3265
3265
3266
3266
// Check that the header is valid (particularly PoW). This is mostly
3267
3267
// redundant with the call in AcceptBlockHeader.
3268
- if (!CheckBlockHeader (block, state, fCheckPOW ))
3268
+ if (!CheckBlockHeader (block, state, consensusParams, nAdjustedTime, fCheckPOW ))
3269
3269
return false ;
3270
3270
3271
3271
// Check the merkle root.
@@ -3331,9 +3331,8 @@ static bool CheckIndexAgainstCheckpoint(const CBlockIndex* pindexPrev, CValidati
3331
3331
return true ;
3332
3332
}
3333
3333
3334
- bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev)
3334
+ bool ContextualCheckBlockHeader (const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex * const pindexPrev)
3335
3335
{
3336
- const Consensus::Params& consensusParams = Params ().GetConsensus ();
3337
3336
// Check proof of work
3338
3337
if (block.nBits != GetNextWorkRequired (pindexPrev, &block, consensusParams))
3339
3338
return state.DoS (100 , false , REJECT_INVALID, " bad-diffbits" , false , " incorrect proof of work" );
@@ -3406,7 +3405,7 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3406
3405
return true ;
3407
3406
}
3408
3407
3409
- if (!CheckBlockHeader (block, state))
3408
+ if (!CheckBlockHeader (block, state, chainparams. GetConsensus (), GetAdjustedTime () ))
3410
3409
return error (" %s: Consensus::CheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
3411
3410
3412
3411
// Get prev block index
@@ -3422,7 +3421,7 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3422
3421
if (fCheckpointsEnabled && !CheckIndexAgainstCheckpoint (pindexPrev, state, chainparams, hash))
3423
3422
return error (" %s: CheckIndexAgainstCheckpoint(): %s" , __func__, state.GetRejectReason ().c_str ());
3424
3423
3425
- if (!ContextualCheckBlockHeader (block, state, pindexPrev))
3424
+ if (!ContextualCheckBlockHeader (block, state, chainparams. GetConsensus (), pindexPrev))
3426
3425
return error (" %s: Consensus::ContextualCheckBlockHeader: %s, %s" , __func__, hash.ToString (), FormatStateMessage (state));
3427
3426
}
3428
3427
if (pindex == NULL )
@@ -3466,7 +3465,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
3466
3465
if (fTooFarAhead ) return true ; // Block height is too high
3467
3466
}
3468
3467
3469
- if ((!CheckBlock (block, state)) || !ContextualCheckBlock (block, state, pindex->pprev )) {
3468
+ if ((!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime () )) || !ContextualCheckBlock (block, state, pindex->pprev )) {
3470
3469
if (state.IsInvalid () && !state.CorruptionPossible ()) {
3471
3470
pindex->nStatus |= BLOCK_FAILED_VALID;
3472
3471
setDirtyBlockIndex.insert (pindex);
@@ -3551,9 +3550,9 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
3551
3550
indexDummy.nHeight = pindexPrev->nHeight + 1 ;
3552
3551
3553
3552
// NOTE: CheckBlockHeader is called by CheckBlock
3554
- if (!ContextualCheckBlockHeader (block, state, pindexPrev))
3553
+ if (!ContextualCheckBlockHeader (block, state, chainparams. GetConsensus (), pindexPrev))
3555
3554
return error (" %s: Consensus::ContextualCheckBlockHeader: %s" , __func__, FormatStateMessage (state));
3556
- if (!CheckBlock (block, state, fCheckPOW , fCheckMerkleRoot ))
3555
+ if (!CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime (), fCheckPOW , fCheckMerkleRoot ))
3557
3556
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
3558
3557
if (!ContextualCheckBlock (block, state, pindexPrev))
3559
3558
return error (" %s: Consensus::ContextualCheckBlock: %s" , __func__, FormatStateMessage (state));
@@ -3890,7 +3889,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3890
3889
if (!ReadBlockFromDisk (block, pindex, chainparams.GetConsensus ()))
3891
3890
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3892
3891
// check level 1: verify block validity
3893
- if (nCheckLevel >= 1 && !CheckBlock (block, state))
3892
+ if (nCheckLevel >= 1 && !CheckBlock (block, state, chainparams. GetConsensus (), GetAdjustedTime () ))
3894
3893
return error (" %s: *** found bad block at %d, hash=%s (%s)\n " , __func__,
3895
3894
pindex->nHeight , pindex->GetBlockHash ().ToString (), FormatStateMessage (state));
3896
3895
// check level 2: verify undo validity
0 commit comments