diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -4,7 +4,6 @@ #include "bench.h" -#include "chainparams.h" #include "config.h" #include "consensus/validation.h" #include "streams.h" @@ -42,8 +41,6 @@ stream.write(&a, 1); // Prevent compaction const Config &config = GetConfig(); - Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus(); - while (state.KeepRunning()) { // Note that CBlock caches its checked state, so we need to recreate it // here. @@ -52,7 +49,7 @@ assert(stream.Rewind(sizeof(block_bench::block413567))); CValidationState validationState; - assert(CheckBlock(config, block, validationState, params)); + assert(CheckBlock(config, block, validationState)); } } diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -217,7 +217,7 @@ if (vtx_missing.size() != tx_missing_offset) return READ_STATUS_INVALID; CValidationState state; - if (!CheckBlock(*config, block, state, Params().GetConsensus())) { + if (!CheckBlock(*config, block, state)) { // TODO: We really want to just check merkle tree manually here, but // that is expensive, and CheckBlock caches a block's "checked-status" // (in the CBlock?). CBlock should be able to check its own merkle root diff --git a/src/test/blockcheck_tests.cpp b/src/test/blockcheck_tests.cpp --- a/src/test/blockcheck_tests.cpp +++ b/src/test/blockcheck_tests.cpp @@ -17,8 +17,7 @@ static void RunCheckOnBlockImpl(const GlobalConfig &config, const CBlock &block, CValidationState &state, bool expected) { block.fChecked = false; - const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); - bool fValid = CheckBlock(config, block, state, params, false, false); + bool fValid = CheckBlock(config, block, state, false, false); BOOST_CHECK_EQUAL(fValid, expected); BOOST_CHECK_EQUAL(fValid, state.IsValid()); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -557,12 +557,8 @@ /** Functions for validating blocks and updating the block tree */ /** Context-independent validity checks */ -bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, - const Consensus::Params &consensusParams, - bool fCheckPOW = true); bool CheckBlock(const Config &Config, const CBlock &block, - CValidationState &state, - const Consensus::Params &consensusParams, bool fCheckPOW = true, + CValidationState &state, bool fCheckPOW = true, bool fCheckMerkleRoot = true); /** diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1875,8 +1875,7 @@ int64_t nTimeStart = GetTimeMicros(); // Check it again in case a previous version let a bad block in - if (!CheckBlock(config, block, state, chainparams.GetConsensus(), - !fJustCheck, !fJustCheck)) { + if (!CheckBlock(config, block, state, !fJustCheck, !fJustCheck)) { return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); } @@ -3195,21 +3194,23 @@ return true; } -bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, - const Consensus::Params &consensusParams, - bool fCheckPOW) { +static bool CheckBlockHeader(const Config &config, const CBlockHeader &block, + CValidationState &state, bool fCheckPOW = true) { + const Consensus::Params &consensusParams = + config.GetChainParams().GetConsensus(); + // Check proof of work matches claimed amount if (fCheckPOW && - !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) + !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) { return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); + } return true; } bool CheckBlock(const Config &config, const CBlock &block, - CValidationState &state, - const Consensus::Params &consensusParams, bool fCheckPOW, + CValidationState &state, bool fCheckPOW, bool fCheckMerkleRoot) { // These are checks that are independent of context. if (block.fChecked) { @@ -3218,7 +3219,7 @@ // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. - if (!CheckBlockHeader(block, state, consensusParams, fCheckPOW)) { + if (!CheckBlockHeader(config, block, state, fCheckPOW)) { return false; } @@ -3512,7 +3513,7 @@ return true; } - if (!CheckBlockHeader(block, state, chainparams.GetConsensus())) { + if (!CheckBlockHeader(config, block, state)) { return error("%s: Consensus::CheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state)); } @@ -3653,7 +3654,7 @@ } const CChainParams &chainparams = config.GetChainParams(); - if (!CheckBlock(config, block, state, chainparams.GetConsensus()) || + if (!CheckBlock(config, block, state) || !ContextualCheckBlock(config, block, state, chainparams.GetConsensus(), pindex->pprev)) { if (state.IsInvalid() && !state.CorruptionPossible()) { @@ -3717,8 +3718,7 @@ CValidationState state; // Ensure that CheckBlock() passes before calling AcceptBlock, as // belt-and-suspenders. - bool ret = - CheckBlock(config, *pblock, state, chainparams.GetConsensus()); + bool ret = CheckBlock(config, *pblock, state); LOCK(cs_main); @@ -3768,8 +3768,7 @@ return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, FormatStateMessage(state)); } - if (!CheckBlock(config, block, state, chainparams.GetConsensus(), fCheckPOW, - fCheckMerkleRoot)) { + if (!CheckBlock(config, block, state, fCheckPOW, fCheckMerkleRoot)) { return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); } @@ -4200,8 +4199,7 @@ } // check level 1: verify block validity - if (nCheckLevel >= 1 && - !CheckBlock(config, block, state, chainparams.GetConsensus())) { + if (nCheckLevel >= 1 && !CheckBlock(config, block, state)) { return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__, pindex->nHeight, pindex->GetBlockHash().ToString(),