aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-09-20 14:02:07 -0400
committerCarl Dong <contact@carldong.me>2021-12-07 14:48:49 -0500
commit15f2e33bb3d1ad3bc997f6a84956337f46495091 (patch)
treef645b983981d41f2da59acd1e6c0f11c3e5a9830
parent4da9c076d1cf12728730bb1f7e8906d4e9bfaba5 (diff)
validation: VerifyDB only needs Consensus::Params
Previously we were passing in CChainParams, when VerifyDB only needed the Consensus::Params subset.
-rw-r--r--src/init.cpp4
-rw-r--r--src/node/chainstate.cpp10
-rw-r--r--src/node/chainstate.h8
-rw-r--r--src/rpc/blockchain.cpp2
-rw-r--r--src/validation.cpp8
-rw-r--r--src/validation.h2
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<int64_t(*)()>(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 <node/chainstate.h>
-#include <chainparams.h> // for CChainParams
+#include <consensus/params.h> // for Consensus::Params
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
#include <validation.h> // for a lot of things
@@ -12,7 +12,7 @@ std::optional<ChainstateLoadingError> 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<ChainstateLoadingError> 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<ChainstateLoadingError> LoadChainstate(bool fReset,
std::optional<ChainstateLoadVerifyError> 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<int64_t()> get_unix_time_seconds)
@@ -148,7 +148,7 @@ std::optional<ChainstateLoadVerifyError> 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 <functional> // for std::function
#include <optional> // for std::optional
-class CChainParams;
class ChainstateManager;
+namespace Consensus {
+ struct Params;
+}
class CTxMemPool;
enum class ChainstateLoadingError {
@@ -56,7 +58,7 @@ std::optional<ChainstateLoadingError> 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<ChainstateLoadVerifyError> 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<int64_t()> 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);