node/chainstate: Decouple from ArgsManager

This commit is contained in:
Kittywhiskers Van Gogh 2024-12-14 15:02:39 +00:00
parent d7419e42d6
commit ee9d3dd5fc
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 29 additions and 15 deletions

View File

@ -1869,13 +1869,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
chainman,
node,
fPruneMode,
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
is_governance_enabled,
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
chainparams,
args,
fReindexChainState,
nBlockTreeDBCache,
nCoinDBCache,
nCoinCacheUsage);
nCoinCacheUsage,
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS),
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL));
if (rv.has_value()) {
switch (rv.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:

View File

@ -28,13 +28,18 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
NodeContext& node,
bool fPruneMode,
bool is_addrindex_enabled,
bool is_governance_enabled,
bool is_spentindex_enabled,
bool is_timeindex_enabled,
bool is_txindex_enabled,
const CChainParams& chainparams,
const ArgsManager& args,
bool fReindexChainState,
int64_t nBlockTreeDBCache,
int64_t nCoinDBCache,
int64_t nCoinCacheUsage)
int64_t nCoinCacheUsage,
unsigned int check_blocks,
unsigned int check_level)
{
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
@ -106,7 +111,7 @@ 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 && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) {
if (is_governance_enabled && !is_txindex_enabled && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) {
return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED;
}
@ -124,17 +129,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
if (!fReset && !fReindexChainState) {
// Check for changed -addressindex state
if (!fAddressIndex && fAddressIndex != args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
if (!fAddressIndex && fAddressIndex != is_addrindex_enabled) {
return ChainstateLoadingError::ERROR_ADDRIDX_NEEDS_REINDEX;
}
// Check for changed -timestampindex state
if (!fTimestampIndex && fTimestampIndex != args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
if (!fTimestampIndex && fTimestampIndex != is_timeindex_enabled) {
return ChainstateLoadingError::ERROR_TIMEIDX_NEEDS_REINDEX;
}
// Check for changed -spentindex state
if (!fSpentIndex && fSpentIndex != args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
if (!fSpentIndex && fSpentIndex != is_spentindex_enabled) {
return ChainstateLoadingError::ERROR_SPENTIDX_NEEDS_REINDEX;
}
}
@ -223,7 +228,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
for (CChainState* chainstate : chainman.GetAll()) {
if (!is_coinsview_empty(chainstate)) {
uiInterface.InitMessage(_("Verifying blocks…").translated);
if (chainman.m_blockman.m_have_pruned && args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
MIN_BLOCKS_TO_KEEP);
}
@ -242,8 +247,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
if (!CVerifyDB().VerifyDB(
*chainstate, chainparams, chainstate->CoinsDB(),
*node.evodb,
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
check_level,
check_blocks)) {
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
}
@ -254,7 +259,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
}
if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
if (check_level >= 3) {
chainstate->ResetBlockFailureFlags(nullptr);
}

View File

@ -8,7 +8,6 @@
#include <cstdint> // for int64_t
#include <optional> // for std::optional
class ArgsManager;
class CChainParams;
class ChainstateManager;
struct NodeContext;
@ -66,12 +65,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
NodeContext& node,
bool fPruneMode,
bool is_addrindex_enabled,
bool is_governance_enabled,
bool is_spentindex_enabled,
bool is_timeindex_enabled,
bool is_txindex_enabled,
const CChainParams& chainparams,
const ArgsManager& args,
bool fReindexChainState,
int64_t nBlockTreeDBCache,
int64_t nCoinDBCache,
int64_t nCoinCacheUsage);
int64_t nCoinCacheUsage,
unsigned int check_blocks,
unsigned int check_level);
#endif // BITCOIN_NODE_CHAINSTATE_H