From 15f2e33bb3d1ad3bc997f6a84956337f46495091 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 20 Sep 2021 14:02:07 -0400 Subject: [PATCH] validation: VerifyDB only needs Consensus::Params Previously we were passing in CChainParams, when VerifyDB only needed the Consensus::Params subset. --- src/init.cpp | 4 ++-- src/node/chainstate.cpp | 10 +++++----- src/node/chainstate.h | 8 +++++--- src/rpc/blockchain.cpp | 2 +- src/validation.cpp | 8 ++++---- src/validation.h | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 67ae94eb2c..e6f00717fb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1425,7 +1425,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) chainman, Assert(node.mempool.get()), fPruneMode, - chainparams, + chainparams.GetConsensus(), fReindexChainState, nBlockTreeDBCache, nCoinDBCache, @@ -1486,7 +1486,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) rv2 = VerifyLoadedChainstate(chainman, fReset, fReindexChainState, - chainparams, + chainparams.GetConsensus(), check_blocks, args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL), static_cast(GetTime)); diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index c112bc949a..b4264655d5 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -4,7 +4,7 @@ #include -#include // for CChainParams +#include // for Consensus::Params #include // for CleanupBlockRevFiles, fHavePruned, fReindex #include // for a lot of things @@ -12,7 +12,7 @@ std::optional LoadChainstate(bool fReset, ChainstateManager& chainman, CTxMemPool* mempool, bool fPruneMode, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, @@ -57,7 +57,7 @@ std::optional LoadChainstate(bool fReset, } if (!chainman.BlockIndex().empty() && - !chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) { + !chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) { return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK; } @@ -128,7 +128,7 @@ std::optional LoadChainstate(bool fReset, std::optional VerifyLoadedChainstate(ChainstateManager& chainman, bool fReset, bool fReindexChainState, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, unsigned int check_blocks, unsigned int check_level, std::function get_unix_time_seconds) @@ -148,7 +148,7 @@ std::optional VerifyLoadedChainstate(ChainstateManage } if (!CVerifyDB().VerifyDB( - *chainstate, chainparams, chainstate->CoinsDB(), + *chainstate, consensus_params, chainstate->CoinsDB(), check_level, check_blocks)) { return ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB; diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 735906a540..e3369eb47c 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -9,8 +9,10 @@ #include // for std::function #include // for std::optional -class CChainParams; class ChainstateManager; +namespace Consensus { + struct Params; +} class CTxMemPool; enum class ChainstateLoadingError { @@ -56,7 +58,7 @@ std::optional LoadChainstate(bool fReset, ChainstateManager& chainman, CTxMemPool* mempool, bool fPruneMode, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, @@ -73,7 +75,7 @@ enum class ChainstateLoadVerifyError { std::optional VerifyLoadedChainstate(ChainstateManager& chainman, bool fReset, bool fReindexChainState, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, unsigned int check_blocks, unsigned int check_level, std::function get_unix_time_seconds); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bd11d76866..4af1f206a5 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1364,7 +1364,7 @@ static RPCHelpMan verifychain() CChainState& active_chainstate = chainman.ActiveChainstate(); return CVerifyDB().VerifyDB( - active_chainstate, Params(), active_chainstate.CoinsTip(), check_level, check_depth); + active_chainstate, Params().GetConsensus(), active_chainstate.CoinsTip(), check_level, check_depth); }, }; } diff --git a/src/validation.cpp b/src/validation.cpp index 91ef961964..d9f57d03de 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3860,7 +3860,7 @@ CVerifyDB::~CVerifyDB() bool CVerifyDB::VerifyDB( CChainState& chainstate, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, CCoinsView& coinsview, int nCheckLevel, int nCheckDepth) { @@ -3902,10 +3902,10 @@ bool CVerifyDB::VerifyDB( } CBlock block; // check level 0: read from disk - if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus())) + if (!ReadBlockFromDisk(block, pindex, consensus_params)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity - if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus())) + if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params)) return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__, pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); // check level 2: verify undo validity @@ -3953,7 +3953,7 @@ bool CVerifyDB::VerifyDB( uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false); pindex = chainstate.m_chain.Next(pindex); CBlock block; - if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus())) + if (!ReadBlockFromDisk(block, pindex, consensus_params)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); if (!chainstate.ConnectBlock(block, state, pindex, coins)) { return error("VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString()); diff --git a/src/validation.h b/src/validation.h index 2609538ece..cc0cc0210f 100644 --- a/src/validation.h +++ b/src/validation.h @@ -344,7 +344,7 @@ public: ~CVerifyDB(); bool VerifyDB( CChainState& chainstate, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, CCoinsView& coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);