Skip to content

Commit d7f1e23

Browse files
committed
validation: VerifyDB only needs Consensus::Params
1 parent c405492 commit d7f1e23

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

src/init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18901890
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
18911891
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
18921892
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
1893-
chainparams,
1893+
chainparams.GetConsensus(),
1894+
chainparams.NetworkIDString(),
18941895
fReindexChainState,
18951896
nBlockTreeDBCache,
18961897
nCoinDBCache,
@@ -1970,7 +1971,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19701971
*Assert(node.evodb.get()),
19711972
fReset,
19721973
fReindexChainState,
1973-
chainparams,
1974+
chainparams.GetConsensus(),
19741975
check_blocks,
19751976
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
19761977
static_cast<int64_t(*)()>(GetTime));

src/node/chainstate.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <node/chainstate.h>
66

7-
#include <chainparams.h> // for CChainParams
7+
#include <consensus/params.h> // for Consensus::Params
88
#include <deploymentstatus.h> // for DeploymentActiveAfter
99
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
1010
#include <validation.h> // for a lot of things
@@ -42,7 +42,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
4242
bool is_spentindex_enabled,
4343
bool is_timeindex_enabled,
4444
bool is_txindex_enabled,
45-
const CChainParams& chainparams,
45+
const Consensus::Params& consensus_params,
46+
const std::string& network_id,
4647
bool fReindexChainState,
4748
int64_t nBlockTreeDBCache,
4849
int64_t nCoinDBCache,
@@ -97,7 +98,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
9798

9899
chain_helper.reset();
99100
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman,
100-
chainparams.GetConsensus(), mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman));
101+
consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman));
101102

102103
if (fReset) {
103104
pblocktree->WriteReindexing(true);
@@ -119,17 +120,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
119120

120121
// TODO: Remove this when pruning is fixed.
121122
// See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
122-
if (is_governance_enabled && !is_txindex_enabled && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) {
123+
if (is_governance_enabled && !is_txindex_enabled && network_id != CBaseChainParams::REGTEST) {
123124
return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED;
124125
}
125126

126127
if (!chainman.BlockIndex().empty() &&
127-
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
128+
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) {
128129
return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK;
129130
}
130131

131-
if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
132-
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) {
132+
if (!consensus_params.hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
133+
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashDevnetGenesisBlock)) {
133134
return ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK;
134135
}
135136

@@ -230,7 +231,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
230231
CEvoDB& evodb,
231232
bool fReset,
232233
bool fReindexChainState,
233-
const CChainParams& chainparams,
234+
const Consensus::Params& consensus_params,
234235
unsigned int check_blocks,
235236
unsigned int check_level,
236237
std::function<int64_t()> get_unix_time_seconds)
@@ -248,14 +249,14 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
248249
if (tip && tip->nTime > get_unix_time_seconds() + 2 * 60 * 60) {
249250
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
250251
}
251-
const bool v19active{DeploymentActiveAfter(tip, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19)};
252+
const bool v19active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V19)};
252253
if (v19active) {
253254
bls::bls_legacy_scheme.store(false);
254255
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
255256
}
256257

257258
if (!CVerifyDB().VerifyDB(
258-
*chainstate, chainparams, chainstate->CoinsDB(),
259+
*chainstate, consensus_params, chainstate->CoinsDB(),
259260
evodb,
260261
check_level,
261262
check_blocks)) {

src/node/chainstate.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <functional> // for std::function
1010
#include <memory> // for std::unique_ptr
1111
#include <optional> // for std::optional
12+
#include <string> // for std::string
1213

1314
class CActiveMasternodeManager;
14-
class CChainParams;
1515
class CChainstateHelper;
1616
class CCreditPoolManager;
1717
class CDeterministicMNManager;
@@ -31,6 +31,10 @@ class CInstantSendManager;
3131
class CQuorumSnapshotManager;
3232
}
3333

34+
namespace Consensus {
35+
struct Params;
36+
}
37+
3438
enum class ChainstateLoadingError {
3539
ERROR_LOADING_BLOCK_DB,
3640
ERROR_BAD_GENESIS_BLOCK,
@@ -100,7 +104,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
100104
bool is_spentindex_enabled,
101105
bool is_timeindex_enabled,
102106
bool is_txindex_enabled,
103-
const CChainParams& chainparams,
107+
const Consensus::Params& consensus_params,
108+
const std::string& network_id,
104109
bool fReindexChainState,
105110
int64_t nBlockTreeDBCache,
106111
int64_t nCoinDBCache,
@@ -119,7 +124,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
119124
CEvoDB& evodb,
120125
bool fReset,
121126
bool fReindexChainState,
122-
const CChainParams& chainparams,
127+
const Consensus::Params& consensus_params,
123128
unsigned int check_blocks,
124129
unsigned int check_level,
125130
std::function<int64_t()> get_unix_time_seconds);

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ static RPCHelpMan verifychain()
16421642

16431643
CChainState& active_chainstate = chainman.ActiveChainstate();
16441644
return CVerifyDB().VerifyDB(
1645-
active_chainstate, Params(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth);
1645+
active_chainstate, Params().GetConsensus(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth);
16461646
},
16471647
};
16481648
}

src/test/evo_deterministicmns_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,8 @@ void FuncVerifyDB(TestChainSetup& setup)
816816

817817
// Verify db consistency
818818
LOCK(cs_main);
819-
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params(), chainman.ActiveChainstate().CoinsTip(),
820-
*(setup.m_node.evodb), 4, 2));
819+
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params().GetConsensus(),
820+
chainman.ActiveChainstate().CoinsTip(), *(setup.m_node.evodb), 4, 2));
821821
}
822822

823823
BOOST_AUTO_TEST_SUITE(evo_dip3_activation_tests)

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,7 +4139,7 @@ CVerifyDB::~CVerifyDB()
41394139

41404140
bool CVerifyDB::VerifyDB(
41414141
CChainState& chainstate,
4142-
const CChainParams& chainparams,
4142+
const Consensus::Params& consensus_params,
41434143
CCoinsView& coinsview,
41444144
CEvoDB& evoDb,
41454145
int nCheckLevel, int nCheckDepth)
@@ -4185,10 +4185,10 @@ bool CVerifyDB::VerifyDB(
41854185
}
41864186
CBlock block;
41874187
// check level 0: read from disk
4188-
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
4188+
if (!ReadBlockFromDisk(block, pindex, consensus_params))
41894189
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
41904190
// check level 1: verify block validity
4191-
if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus()))
4191+
if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params))
41924192
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
41934193
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
41944194
// check level 2: verify undo validity
@@ -4236,7 +4236,7 @@ bool CVerifyDB::VerifyDB(
42364236
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
42374237
pindex = chainstate.m_chain.Next(pindex);
42384238
CBlock block;
4239-
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
4239+
if (!ReadBlockFromDisk(block, pindex, consensus_params))
42404240
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
42414241
if (!chainstate.ConnectBlock(block, state, pindex, coins))
42424242
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class CVerifyDB {
367367
~CVerifyDB();
368368
bool VerifyDB(
369369
CChainState& chainstate,
370-
const CChainParams& chainparams,
370+
const Consensus::Params& consensus_params,
371371
CCoinsView& coinsview,
372372
CEvoDB& evoDb,
373373
int nCheckLevel,

0 commit comments

Comments
 (0)