Skip to content

Commit

Permalink
validation: VerifyDB only needs Consensus::Params
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Dec 16, 2024
1 parent c405492 commit d7f1e23
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<int64_t(*)()>(GetTime));
Expand Down
21 changes: 11 additions & 10 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <node/chainstate.h>

#include <chainparams.h> // for CChainParams
#include <consensus/params.h> // for Consensus::Params
#include <deploymentstatus.h> // for DeploymentActiveAfter
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
#include <validation.h> // for a lot of things
Expand Down Expand Up @@ -42,7 +42,8 @@ std::optional<ChainstateLoadingError> 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,
Expand Down Expand Up @@ -97,7 +98,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,

chain_helper.reset();
chain_helper = std::make_unique<CChainstateHelper>(*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);
Expand All @@ -119,17 +120,17 @@ std::optional<ChainstateLoadingError> 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;
}

Expand Down Expand Up @@ -230,7 +231,7 @@ std::optional<ChainstateLoadVerifyError> 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<int64_t()> get_unix_time_seconds)
Expand All @@ -248,14 +249,14 @@ std::optional<ChainstateLoadVerifyError> 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)) {
Expand Down
11 changes: 8 additions & 3 deletions src/node/chainstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <functional> // for std::function
#include <memory> // for std::unique_ptr
#include <optional> // for std::optional
#include <string> // for std::string

class CActiveMasternodeManager;
class CChainParams;
class CChainstateHelper;
class CCreditPoolManager;
class CDeterministicMNManager;
Expand All @@ -31,6 +31,10 @@ class CInstantSendManager;
class CQuorumSnapshotManager;
}

namespace Consensus {
struct Params;
}

enum class ChainstateLoadingError {
ERROR_LOADING_BLOCK_DB,
ERROR_BAD_GENESIS_BLOCK,
Expand Down Expand Up @@ -100,7 +104,8 @@ std::optional<ChainstateLoadingError> 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,
Expand All @@ -119,7 +124,7 @@ std::optional<ChainstateLoadVerifyError> 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<int64_t()> get_unix_time_seconds);
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/evo_deterministicmns_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class CVerifyDB {
~CVerifyDB();
bool VerifyDB(
CChainState& chainstate,
const CChainParams& chainparams,
const Consensus::Params& consensus_params,
CCoinsView& coinsview,
CEvoDB& evoDb,
int nCheckLevel,
Expand Down

0 comments on commit d7f1e23

Please sign in to comment.