mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42: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("-spentindex", DEFAULT_SPENTINDEX),
|
||||||
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
|
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
|
||||||
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
|
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
|
||||||
chainparams,
|
chainparams.GetConsensus(),
|
||||||
|
chainparams.NetworkIDString(),
|
||||||
fReindexChainState,
|
fReindexChainState,
|
||||||
nBlockTreeDBCache,
|
nBlockTreeDBCache,
|
||||||
nCoinDBCache,
|
nCoinDBCache,
|
||||||
@ -1970,7 +1971,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
*Assert(node.evodb.get()),
|
*Assert(node.evodb.get()),
|
||||||
fReset,
|
fReset,
|
||||||
fReindexChainState,
|
fReindexChainState,
|
||||||
chainparams,
|
chainparams.GetConsensus(),
|
||||||
check_blocks,
|
check_blocks,
|
||||||
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
|
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
|
||||||
static_cast<int64_t(*)()>(GetTime));
|
static_cast<int64_t(*)()>(GetTime));
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <node/chainstate.h>
|
#include <node/chainstate.h>
|
||||||
|
|
||||||
#include <chainparams.h> // for CChainParams
|
#include <consensus/params.h> // for Consensus::Params
|
||||||
#include <deploymentstatus.h> // for DeploymentActiveAfter
|
#include <deploymentstatus.h> // for DeploymentActiveAfter
|
||||||
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
|
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
|
||||||
#include <validation.h> // for a lot of things
|
#include <validation.h> // for a lot of things
|
||||||
@ -42,7 +42,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
bool is_spentindex_enabled,
|
bool is_spentindex_enabled,
|
||||||
bool is_timeindex_enabled,
|
bool is_timeindex_enabled,
|
||||||
bool is_txindex_enabled,
|
bool is_txindex_enabled,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
|
const std::string& network_id,
|
||||||
bool fReindexChainState,
|
bool fReindexChainState,
|
||||||
int64_t nBlockTreeDBCache,
|
int64_t nBlockTreeDBCache,
|
||||||
int64_t nCoinDBCache,
|
int64_t nCoinDBCache,
|
||||||
@ -97,7 +98,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
|
|
||||||
chain_helper.reset();
|
chain_helper.reset();
|
||||||
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman,
|
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) {
|
if (fReset) {
|
||||||
pblocktree->WriteReindexing(true);
|
pblocktree->WriteReindexing(true);
|
||||||
@ -119,17 +120,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
|
|
||||||
// TODO: Remove this when pruning is fixed.
|
// TODO: Remove this when pruning is fixed.
|
||||||
// See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
|
// 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;
|
return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chainman.BlockIndex().empty() &&
|
if (!chainman.BlockIndex().empty() &&
|
||||||
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) {
|
||||||
return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK;
|
return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
|
if (!consensus_params.hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
|
||||||
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) {
|
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashDevnetGenesisBlock)) {
|
||||||
return ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK;
|
return ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
|
|||||||
CEvoDB& evodb,
|
CEvoDB& evodb,
|
||||||
bool fReset,
|
bool fReset,
|
||||||
bool fReindexChainState,
|
bool fReindexChainState,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
unsigned int check_blocks,
|
unsigned int check_blocks,
|
||||||
unsigned int check_level,
|
unsigned int check_level,
|
||||||
std::function<int64_t()> get_unix_time_seconds)
|
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) {
|
if (tip && tip->nTime > get_unix_time_seconds() + 2 * 60 * 60) {
|
||||||
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
|
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) {
|
if (v19active) {
|
||||||
bls::bls_legacy_scheme.store(false);
|
bls::bls_legacy_scheme.store(false);
|
||||||
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
|
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CVerifyDB().VerifyDB(
|
if (!CVerifyDB().VerifyDB(
|
||||||
*chainstate, chainparams, chainstate->CoinsDB(),
|
*chainstate, consensus_params, chainstate->CoinsDB(),
|
||||||
evodb,
|
evodb,
|
||||||
check_level,
|
check_level,
|
||||||
check_blocks)) {
|
check_blocks)) {
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#include <functional> // for std::function
|
#include <functional> // for std::function
|
||||||
#include <memory> // for std::unique_ptr
|
#include <memory> // for std::unique_ptr
|
||||||
#include <optional> // for std::optional
|
#include <optional> // for std::optional
|
||||||
|
#include <string> // for std::string
|
||||||
|
|
||||||
class CActiveMasternodeManager;
|
class CActiveMasternodeManager;
|
||||||
class CChainParams;
|
|
||||||
class CChainstateHelper;
|
class CChainstateHelper;
|
||||||
class CCreditPoolManager;
|
class CCreditPoolManager;
|
||||||
class CDeterministicMNManager;
|
class CDeterministicMNManager;
|
||||||
@ -31,6 +31,10 @@ class CInstantSendManager;
|
|||||||
class CQuorumSnapshotManager;
|
class CQuorumSnapshotManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Consensus {
|
||||||
|
struct Params;
|
||||||
|
}
|
||||||
|
|
||||||
enum class ChainstateLoadingError {
|
enum class ChainstateLoadingError {
|
||||||
ERROR_LOADING_BLOCK_DB,
|
ERROR_LOADING_BLOCK_DB,
|
||||||
ERROR_BAD_GENESIS_BLOCK,
|
ERROR_BAD_GENESIS_BLOCK,
|
||||||
@ -100,7 +104,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|||||||
bool is_spentindex_enabled,
|
bool is_spentindex_enabled,
|
||||||
bool is_timeindex_enabled,
|
bool is_timeindex_enabled,
|
||||||
bool is_txindex_enabled,
|
bool is_txindex_enabled,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
|
const std::string& network_id,
|
||||||
bool fReindexChainState,
|
bool fReindexChainState,
|
||||||
int64_t nBlockTreeDBCache,
|
int64_t nBlockTreeDBCache,
|
||||||
int64_t nCoinDBCache,
|
int64_t nCoinDBCache,
|
||||||
@ -119,7 +124,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
|
|||||||
CEvoDB& evodb,
|
CEvoDB& evodb,
|
||||||
bool fReset,
|
bool fReset,
|
||||||
bool fReindexChainState,
|
bool fReindexChainState,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
unsigned int check_blocks,
|
unsigned int check_blocks,
|
||||||
unsigned int check_level,
|
unsigned int check_level,
|
||||||
std::function<int64_t()> get_unix_time_seconds);
|
std::function<int64_t()> get_unix_time_seconds);
|
||||||
|
@ -1642,7 +1642,7 @@ static RPCHelpMan verifychain()
|
|||||||
|
|
||||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||||
return CVerifyDB().VerifyDB(
|
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
|
// Verify db consistency
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params(), chainman.ActiveChainstate().CoinsTip(),
|
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params().GetConsensus(),
|
||||||
*(setup.m_node.evodb), 4, 2));
|
chainman.ActiveChainstate().CoinsTip(), *(setup.m_node.evodb), 4, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(evo_dip3_activation_tests)
|
BOOST_AUTO_TEST_SUITE(evo_dip3_activation_tests)
|
||||||
|
@ -4139,7 +4139,7 @@ CVerifyDB::~CVerifyDB()
|
|||||||
|
|
||||||
bool CVerifyDB::VerifyDB(
|
bool CVerifyDB::VerifyDB(
|
||||||
CChainState& chainstate,
|
CChainState& chainstate,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
CCoinsView& coinsview,
|
CCoinsView& coinsview,
|
||||||
CEvoDB& evoDb,
|
CEvoDB& evoDb,
|
||||||
int nCheckLevel, int nCheckDepth)
|
int nCheckLevel, int nCheckDepth)
|
||||||
@ -4185,10 +4185,10 @@ bool CVerifyDB::VerifyDB(
|
|||||||
}
|
}
|
||||||
CBlock block;
|
CBlock block;
|
||||||
// check level 0: read from disk
|
// 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());
|
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||||
// check level 1: verify block validity
|
// 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__,
|
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
|
||||||
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||||
// check level 2: verify undo validity
|
// check level 2: verify undo validity
|
||||||
@ -4236,7 +4236,7 @@ bool CVerifyDB::VerifyDB(
|
|||||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||||
pindex = chainstate.m_chain.Next(pindex);
|
pindex = chainstate.m_chain.Next(pindex);
|
||||||
CBlock block;
|
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());
|
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||||
if (!chainstate.ConnectBlock(block, state, pindex, coins))
|
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());
|
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||||
|
@ -367,7 +367,7 @@ public:
|
|||||||
~CVerifyDB();
|
~CVerifyDB();
|
||||||
bool VerifyDB(
|
bool VerifyDB(
|
||||||
CChainState& chainstate,
|
CChainState& chainstate,
|
||||||
const CChainParams& chainparams,
|
const Consensus::Params& consensus_params,
|
||||||
CCoinsView& coinsview,
|
CCoinsView& coinsview,
|
||||||
CEvoDB& evoDb,
|
CEvoDB& evoDb,
|
||||||
int nCheckLevel,
|
int nCheckLevel,
|
||||||
|
Loading…
Reference in New Issue
Block a user