Skip to content

Commit 15f2e33

Browse files
committed
validation: VerifyDB only needs Consensus::Params
Previously we were passing in CChainParams, when VerifyDB only needed the Consensus::Params subset.
1 parent 4da9c07 commit 15f2e33

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14251425
chainman,
14261426
Assert(node.mempool.get()),
14271427
fPruneMode,
1428-
chainparams,
1428+
chainparams.GetConsensus(),
14291429
fReindexChainState,
14301430
nBlockTreeDBCache,
14311431
nCoinDBCache,
@@ -1486,7 +1486,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14861486
rv2 = VerifyLoadedChainstate(chainman,
14871487
fReset,
14881488
fReindexChainState,
1489-
chainparams,
1489+
chainparams.GetConsensus(),
14901490
check_blocks,
14911491
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
14921492
static_cast<int64_t(*)()>(GetTime));

src/node/chainstate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
#include <node/chainstate.h>
66

7-
#include <chainparams.h> // for CChainParams
7+
#include <consensus/params.h> // for Consensus::Params
88
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
99
#include <validation.h> // for a lot of things
1010

1111
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
1212
ChainstateManager& chainman,
1313
CTxMemPool* mempool,
1414
bool fPruneMode,
15-
const CChainParams& chainparams,
15+
const Consensus::Params& consensus_params,
1616
bool fReindexChainState,
1717
int64_t nBlockTreeDBCache,
1818
int64_t nCoinDBCache,
@@ -57,7 +57,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
5757
}
5858

5959
if (!chainman.BlockIndex().empty() &&
60-
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
60+
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) {
6161
return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK;
6262
}
6363

@@ -128,7 +128,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
128128
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
129129
bool fReset,
130130
bool fReindexChainState,
131-
const CChainParams& chainparams,
131+
const Consensus::Params& consensus_params,
132132
unsigned int check_blocks,
133133
unsigned int check_level,
134134
std::function<int64_t()> get_unix_time_seconds)
@@ -148,7 +148,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
148148
}
149149

150150
if (!CVerifyDB().VerifyDB(
151-
*chainstate, chainparams, chainstate->CoinsDB(),
151+
*chainstate, consensus_params, chainstate->CoinsDB(),
152152
check_level,
153153
check_blocks)) {
154154
return ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB;

src/node/chainstate.h

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

12-
class CChainParams;
1312
class ChainstateManager;
13+
namespace Consensus {
14+
struct Params;
15+
}
1416
class CTxMemPool;
1517

1618
enum class ChainstateLoadingError {
@@ -56,7 +58,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
5658
ChainstateManager& chainman,
5759
CTxMemPool* mempool,
5860
bool fPruneMode,
59-
const CChainParams& chainparams,
61+
const Consensus::Params& consensus_params,
6062
bool fReindexChainState,
6163
int64_t nBlockTreeDBCache,
6264
int64_t nCoinDBCache,
@@ -73,7 +75,7 @@ enum class ChainstateLoadVerifyError {
7375
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
7476
bool fReset,
7577
bool fReindexChainState,
76-
const CChainParams& chainparams,
78+
const Consensus::Params& consensus_params,
7779
unsigned int check_blocks,
7880
unsigned int check_level,
7981
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
@@ -1364,7 +1364,7 @@ static RPCHelpMan verifychain()
13641364

13651365
CChainState& active_chainstate = chainman.ActiveChainstate();
13661366
return CVerifyDB().VerifyDB(
1367-
active_chainstate, Params(), active_chainstate.CoinsTip(), check_level, check_depth);
1367+
active_chainstate, Params().GetConsensus(), active_chainstate.CoinsTip(), check_level, check_depth);
13681368
},
13691369
};
13701370
}

src/validation.cpp

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

38613861
bool CVerifyDB::VerifyDB(
38623862
CChainState& chainstate,
3863-
const CChainParams& chainparams,
3863+
const Consensus::Params& consensus_params,
38643864
CCoinsView& coinsview,
38653865
int nCheckLevel, int nCheckDepth)
38663866
{
@@ -3902,10 +3902,10 @@ bool CVerifyDB::VerifyDB(
39023902
}
39033903
CBlock block;
39043904
// check level 0: read from disk
3905-
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
3905+
if (!ReadBlockFromDisk(block, pindex, consensus_params))
39063906
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
39073907
// check level 1: verify block validity
3908-
if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus()))
3908+
if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params))
39093909
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
39103910
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
39113911
// check level 2: verify undo validity
@@ -3953,7 +3953,7 @@ bool CVerifyDB::VerifyDB(
39533953
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
39543954
pindex = chainstate.m_chain.Next(pindex);
39553955
CBlock block;
3956-
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
3956+
if (!ReadBlockFromDisk(block, pindex, consensus_params))
39573957
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
39583958
if (!chainstate.ConnectBlock(block, state, pindex, coins)) {
39593959
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
@@ -344,7 +344,7 @@ class CVerifyDB {
344344
~CVerifyDB();
345345
bool VerifyDB(
346346
CChainState& chainstate,
347-
const CChainParams& chainparams,
347+
const Consensus::Params& consensus_params,
348348
CCoinsView& coinsview,
349349
int nCheckLevel,
350350
int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

0 commit comments

Comments
 (0)