From d7f1e234c5c7240f66ff9649b175cc699919cae6 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:46:44 +0000 Subject: [PATCH] validation: VerifyDB only needs Consensus::Params --- src/init.cpp | 5 +++-- src/node/chainstate.cpp | 21 +++++++++++---------- src/node/chainstate.h | 11 ++++++++--- src/rpc/blockchain.cpp | 2 +- src/test/evo_deterministicmns_tests.cpp | 4 ++-- src/validation.cpp | 8 ++++---- src/validation.h | 2 +- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 023f07f678..feb69482fe 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1890,7 +1890,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX), args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX), args.GetBoolArg("-txindex", DEFAULT_TXINDEX), - chainparams, + chainparams.GetConsensus(), + chainparams.NetworkIDString(), fReindexChainState, nBlockTreeDBCache, nCoinDBCache, @@ -1970,7 +1971,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) *Assert(node.evodb.get()), fReset, fReindexChainState, - chainparams, + chainparams.GetConsensus(), check_blocks, args.GetArg("-checklevel", DEFAULT_CHECKLEVEL), static_cast(GetTime)); diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 1fbf0b3d00..8923f6a81f 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 DeploymentActiveAfter #include // for CleanupBlockRevFiles, fHavePruned, fReindex #include // for a lot of things @@ -42,7 +42,8 @@ std::optional LoadChainstate(bool fReset, bool is_spentindex_enabled, bool is_timeindex_enabled, bool is_txindex_enabled, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, + const std::string& network_id, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, @@ -97,7 +98,7 @@ std::optional LoadChainstate(bool fReset, chain_helper.reset(); chain_helper = std::make_unique(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman, - chainparams.GetConsensus(), mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman)); + consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman)); if (fReset) { pblocktree->WriteReindexing(true); @@ -119,17 +120,17 @@ std::optional LoadChainstate(bool fReset, // TODO: Remove this when pruning is fixed. // See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743 - if (is_governance_enabled && !is_txindex_enabled && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { + if (is_governance_enabled && !is_txindex_enabled && network_id != CBaseChainParams::REGTEST) { return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED; } if (!chainman.BlockIndex().empty() && - !chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) { + !chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) { return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK; } - if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() && - !chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) { + if (!consensus_params.hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() && + !chainman.m_blockman.LookupBlockIndex(consensus_params.hashDevnetGenesisBlock)) { return ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK; } @@ -230,7 +231,7 @@ std::optional VerifyLoadedChainstate(ChainstateManage CEvoDB& evodb, 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) @@ -248,14 +249,14 @@ std::optional VerifyLoadedChainstate(ChainstateManage if (tip && tip->nTime > get_unix_time_seconds() + 2 * 60 * 60) { return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE; } - const bool v19active{DeploymentActiveAfter(tip, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19)}; + const bool v19active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V19)}; if (v19active) { bls::bls_legacy_scheme.store(false); LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load()); } if (!CVerifyDB().VerifyDB( - *chainstate, chainparams, chainstate->CoinsDB(), + *chainstate, consensus_params, chainstate->CoinsDB(), evodb, check_level, check_blocks)) { diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 2c023a538b..c2aa6d827f 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -9,9 +9,9 @@ #include // for std::function #include // for std::unique_ptr #include // for std::optional +#include // for std::string class CActiveMasternodeManager; -class CChainParams; class CChainstateHelper; class CCreditPoolManager; class CDeterministicMNManager; @@ -31,6 +31,10 @@ class CInstantSendManager; class CQuorumSnapshotManager; } +namespace Consensus { +struct Params; +} + enum class ChainstateLoadingError { ERROR_LOADING_BLOCK_DB, ERROR_BAD_GENESIS_BLOCK, @@ -100,7 +104,8 @@ std::optional LoadChainstate(bool fReset, bool is_spentindex_enabled, bool is_timeindex_enabled, bool is_txindex_enabled, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, + const std::string& network_id, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, @@ -119,7 +124,7 @@ std::optional VerifyLoadedChainstate(ChainstateManage CEvoDB& evodb, 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 3f44150ce5..2eb41cee62 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1642,7 +1642,7 @@ static RPCHelpMan verifychain() CChainState& active_chainstate = chainman.ActiveChainstate(); return CVerifyDB().VerifyDB( - active_chainstate, Params(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth); + active_chainstate, Params().GetConsensus(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth); }, }; } diff --git a/src/test/evo_deterministicmns_tests.cpp b/src/test/evo_deterministicmns_tests.cpp index ae82700ad2..8783081f9c 100644 --- a/src/test/evo_deterministicmns_tests.cpp +++ b/src/test/evo_deterministicmns_tests.cpp @@ -816,8 +816,8 @@ void FuncVerifyDB(TestChainSetup& setup) // Verify db consistency LOCK(cs_main); - BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params(), chainman.ActiveChainstate().CoinsTip(), - *(setup.m_node.evodb), 4, 2)); + BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params().GetConsensus(), + chainman.ActiveChainstate().CoinsTip(), *(setup.m_node.evodb), 4, 2)); } BOOST_AUTO_TEST_SUITE(evo_dip3_activation_tests) diff --git a/src/validation.cpp b/src/validation.cpp index 5f093aa1b2..7f4cc03148 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4139,7 +4139,7 @@ CVerifyDB::~CVerifyDB() bool CVerifyDB::VerifyDB( CChainState& chainstate, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, CCoinsView& coinsview, CEvoDB& evoDb, int nCheckLevel, int nCheckDepth) @@ -4185,10 +4185,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 @@ -4236,7 +4236,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 1644549a3c..ab12d9378d 100644 --- a/src/validation.h +++ b/src/validation.h @@ -367,7 +367,7 @@ public: ~CVerifyDB(); bool VerifyDB( CChainState& chainstate, - const CChainParams& chainparams, + const Consensus::Params& consensus_params, CCoinsView& coinsview, CEvoDB& evoDb, int nCheckLevel,