mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
validation: allow to specify frequency for -checkblockindex
This makes it similar to -checkaddrman and -checkmempool, which also allow to run the check occasionally instead of always / never. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
parent
d5a631b959
commit
5bc2077e8f
6 changed files with 16 additions and 5 deletions
|
@ -604,7 +604,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
|||
|
||||
argsman.AddArg("-checkblocks=<n>", strprintf("How many blocks to check at startup (default: %u, 0 = all)", DEFAULT_CHECKBLOCKS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checklevel=<n>", strprintf("How thorough the block verification of -checkblocks is: %s (0-4, default: %u)", Join(CHECKLEVEL_DOC, ", "), DEFAULT_CHECKLEVEL), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checkblockindex", strprintf("Do a consistency check for the block tree, chainstate, and other validation data structures occasionally. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checkblockindex", strprintf("Do a consistency check for the block tree, chainstate, and other validation data structures every <n> operations. Use 0 to disable. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checkaddrman=<n>", strprintf("Run addrman consistency checks every <n> operations. Use 0 to disable. (default: %u)", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checkmempool=<n>", strprintf("Run mempool consistency checks every <n> transactions. Use 0 to disable. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-checkpoints", strprintf("Enable rejection of any forks from the known historical chain until block %s (default: %u)", defaultChainParams->Checkpoints().GetHeight(), DEFAULT_CHECKPOINTS_ENABLED), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace kernel {
|
|||
struct ChainstateManagerOpts {
|
||||
const CChainParams& chainparams;
|
||||
fs::path datadir;
|
||||
std::optional<bool> check_block_index{};
|
||||
std::optional<int32_t> check_block_index{};
|
||||
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
|
||||
//! If set, it will override the minimum work we will assume exists on some valid chain.
|
||||
std::optional<arith_uint256> minimum_chain_work{};
|
||||
|
|
|
@ -24,7 +24,10 @@
|
|||
namespace node {
|
||||
util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts)
|
||||
{
|
||||
if (auto value{args.GetBoolArg("-checkblockindex")}) opts.check_block_index = *value;
|
||||
if (auto value{args.GetIntArg("-checkblockindex")}) {
|
||||
// Interpret bare -checkblockindex argument as 1 instead of 0.
|
||||
opts.check_block_index = args.GetArg("-checkblockindex")->empty() ? 1 : *value;
|
||||
}
|
||||
|
||||
if (auto value{args.GetBoolArg("-checkpoints")}) opts.checkpoints_enabled = *value;
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
|
|||
const ChainstateManager::Options chainman_opts{
|
||||
.chainparams = chainparams,
|
||||
.datadir = m_args.GetDataDirNet(),
|
||||
.check_block_index = true,
|
||||
.check_block_index = 1,
|
||||
.notifications = *m_node.notifications,
|
||||
.signals = m_node.validation_signals.get(),
|
||||
.worker_threads_num = 2,
|
||||
|
|
|
@ -5034,6 +5034,14 @@ void ChainstateManager::LoadExternalBlockFile(
|
|||
LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
|
||||
}
|
||||
|
||||
bool ChainstateManager::ShouldCheckBlockIndex() const
|
||||
{
|
||||
// Assert to verify Flatten() has been called.
|
||||
if (!*Assert(m_options.check_block_index)) return false;
|
||||
if (GetRand(*m_options.check_block_index) >= 1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChainstateManager::CheckBlockIndex()
|
||||
{
|
||||
if (!ShouldCheckBlockIndex()) {
|
||||
|
|
|
@ -933,7 +933,7 @@ public:
|
|||
|
||||
const CChainParams& GetParams() const { return m_options.chainparams; }
|
||||
const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
|
||||
bool ShouldCheckBlockIndex() const { return *Assert(m_options.check_block_index); }
|
||||
bool ShouldCheckBlockIndex() const;
|
||||
const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
|
||||
const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
|
||||
kernel::Notifications& GetNotifications() const { return m_options.notifications; };
|
||||
|
|
Loading…
Add table
Reference in a new issue