mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
validation: VerifyDB only needs Consensus::Params
This commit is contained in:
parent
c405492874
commit
d7f1e234c5
@ -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<int64_t(*)()>(GetTime));
|
||||
|
@ -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
|
||||
@ -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,
|
||||
@ -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);
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
@ -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)) {
|
||||
|
@ -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;
|
||||
@ -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<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,
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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());
|
||||
|
@ -367,7 +367,7 @@ public:
|
||||
~CVerifyDB();
|
||||
bool VerifyDB(
|
||||
CChainState& chainstate,
|
||||
const CChainParams& chainparams,
|
||||
const Consensus::Params& consensus_params,
|
||||
CCoinsView& coinsview,
|
||||
CEvoDB& evoDb,
|
||||
int nCheckLevel,
|
||||
|
Loading…
Reference in New Issue
Block a user