diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3689,16 +3689,14 @@ * in ConnectBlock(). * Note that -reindex-chainstate skips the validation that happens here! */ -static bool ContextualCheckBlock(const Config &config, const CBlock &block, - CValidationState &state, +static bool ContextualCheckBlock(const Consensus::Params ¶ms, + const CBlock &block, CValidationState &state, const CBlockIndex *pindexPrev) { const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); // Start enforcing BIP113 (Median Time Past). int nLockTimeFlags = 0; - if (nHeight >= consensusParams.CSVHeight) { + if (nHeight >= params.CSVHeight) { nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST; } @@ -3710,7 +3708,7 @@ : block.GetBlockTime(); const bool fIsMagneticAnomalyEnabled = - IsMagneticAnomalyEnabled(consensusParams, pindexPrev); + IsMagneticAnomalyEnabled(params, pindexPrev); // Check that all transactions are finalized const CTransaction *prevTx = nullptr; @@ -3737,7 +3735,7 @@ } } - if (!ContextualCheckTransaction(consensusParams, tx, state, nHeight, + if (!ContextualCheckTransaction(params, tx, state, nHeight, nLockTimeCutoff, nMedianTimePast)) { // state set by ContextualCheckTransaction. return false; @@ -3745,7 +3743,7 @@ } // Enforce rule that the coinbase starts with serialized block height - if (nHeight >= consensusParams.BIP34Height) { + if (nHeight >= params.BIP34Height) { CScript expect = CScript() << nHeight; if (block.vtx[0]->vin[0].scriptSig.size() < expect.size() || !std::equal(expect.begin(), expect.end(), @@ -4013,8 +4011,11 @@ *fNewBlock = true; } + const CChainParams &chainparams = config.GetChainParams(); + if (!CheckBlock(config, block, state) || - !ContextualCheckBlock(config, block, state, pindex->pprev)) { + !ContextualCheckBlock(chainparams.GetConsensus(), block, state, + pindex->pprev)) { if (state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus = pindex->nStatus.withFailed(); setDirtyBlockIndex.insert(pindex); @@ -4045,8 +4046,6 @@ GetMainSignals().NewPoWValidBlock(pindex, pblock); } - const CChainParams &chainparams = config.GetChainParams(); - // Write block to history file try { FlatFilePos blockPos = @@ -4141,7 +4140,8 @@ FormatStateMessage(state)); } - if (!ContextualCheckBlock(config, block, state, pindexPrev)) { + if (!ContextualCheckBlock(config.GetChainParams().GetConsensus(), block, + state, pindexPrev)) { return error("%s: Consensus::ContextualCheckBlock: %s", __func__, FormatStateMessage(state)); }