mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-14 13:50:34 +02:00
Move ::nMaxTipAge into ChainstateManager
This commit is contained in:
parent
ba441d493c
commit
faf44876db
@ -198,6 +198,7 @@ BITCOIN_CORE_H = \
|
|||||||
node/blockstorage.h \
|
node/blockstorage.h \
|
||||||
node/caches.h \
|
node/caches.h \
|
||||||
node/chainstate.h \
|
node/chainstate.h \
|
||||||
|
node/chainstatemanager_args.h \
|
||||||
node/coin.h \
|
node/coin.h \
|
||||||
node/connection_types.h \
|
node/connection_types.h \
|
||||||
node/context.h \
|
node/context.h \
|
||||||
@ -381,6 +382,7 @@ libbitcoin_node_a_SOURCES = \
|
|||||||
node/blockstorage.cpp \
|
node/blockstorage.cpp \
|
||||||
node/caches.cpp \
|
node/caches.cpp \
|
||||||
node/chainstate.cpp \
|
node/chainstate.cpp \
|
||||||
|
node/chainstatemanager_args.cpp \
|
||||||
node/coin.cpp \
|
node/coin.cpp \
|
||||||
node/connection_types.cpp \
|
node/connection_types.cpp \
|
||||||
node/context.cpp \
|
node/context.cpp \
|
||||||
|
17
src/init.cpp
17
src/init.cpp
@ -40,6 +40,7 @@
|
|||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/caches.h>
|
#include <node/caches.h>
|
||||||
#include <node/chainstate.h>
|
#include <node/chainstate.h>
|
||||||
|
#include <node/chainstatemanager_args.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <node/mempool_args.h>
|
#include <node/mempool_args.h>
|
||||||
@ -554,7 +555,10 @@ void SetupServerArgs(ArgsManager& argsman)
|
|||||||
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_BYTES >> 20), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_BYTES >> 20), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-maxtipage=<n>",
|
||||||
|
strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)",
|
||||||
|
Ticks<std::chrono::seconds>(DEFAULT_MAX_TIP_AGE)),
|
||||||
|
ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
|
|
||||||
@ -995,8 +999,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
|
|||||||
if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) > 1)
|
if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) > 1)
|
||||||
return InitError(Untranslated("Unknown rpcserialversion requested."));
|
return InitError(Untranslated("Unknown rpcserialversion requested."));
|
||||||
|
|
||||||
nMaxTipAge = args.GetIntArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
|
|
||||||
|
|
||||||
if (args.GetBoolArg("-reindex-chainstate", false)) {
|
if (args.GetBoolArg("-reindex-chainstate", false)) {
|
||||||
// indexes that must be deactivated to prevent index corruption, see #24630
|
// indexes that must be deactivated to prevent index corruption, see #24630
|
||||||
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
|
||||||
@ -1435,6 +1437,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
|
|
||||||
fReindex = args.GetBoolArg("-reindex", false);
|
fReindex = args.GetBoolArg("-reindex", false);
|
||||||
bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
|
bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
|
||||||
|
ChainstateManager::Options chainman_opts{
|
||||||
|
.chainparams = chainparams,
|
||||||
|
.adjusted_time_callback = GetAdjustedTime,
|
||||||
|
};
|
||||||
|
ApplyArgsManOptions(args, chainman_opts);
|
||||||
|
|
||||||
// cache size calculations
|
// cache size calculations
|
||||||
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
|
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
|
||||||
@ -1471,10 +1478,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
|
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
|
||||||
node.mempool = std::make_unique<CTxMemPool>(mempool_opts);
|
node.mempool = std::make_unique<CTxMemPool>(mempool_opts);
|
||||||
|
|
||||||
const ChainstateManager::Options chainman_opts{
|
|
||||||
.chainparams = chainparams,
|
|
||||||
.adjusted_time_callback = GetAdjustedTime,
|
|
||||||
};
|
|
||||||
node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
|
node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
|
||||||
ChainstateManager& chainman = *node.chainman;
|
ChainstateManager& chainman = *node.chainman;
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
class CChainParams;
|
class CChainParams;
|
||||||
|
|
||||||
|
static constexpr auto DEFAULT_MAX_TIP_AGE{24h};
|
||||||
|
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,6 +24,8 @@ namespace kernel {
|
|||||||
struct ChainstateManagerOpts {
|
struct ChainstateManagerOpts {
|
||||||
const CChainParams& chainparams;
|
const CChainParams& chainparams;
|
||||||
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
|
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
|
||||||
|
//! If the tip is older than this, the node is considered to be in initial block download.
|
||||||
|
std::chrono::seconds max_tip_age{DEFAULT_MAX_TIP_AGE};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
|
17
src/node/chainstatemanager_args.cpp
Normal file
17
src/node/chainstatemanager_args.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2022 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <node/chainstatemanager_args.h>
|
||||||
|
|
||||||
|
#include <util/system.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
void ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts)
|
||||||
|
{
|
||||||
|
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
|
||||||
|
}
|
||||||
|
} // namespace node
|
16
src/node/chainstatemanager_args.h
Normal file
16
src/node/chainstatemanager_args.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (c) 2022 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_NODE_CHAINSTATEMANAGER_ARGS_H
|
||||||
|
#define BITCOIN_NODE_CHAINSTATEMANAGER_ARGS_H
|
||||||
|
|
||||||
|
#include <validation.h>
|
||||||
|
|
||||||
|
class ArgsManager;
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
void ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts);
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
|
#endif // BITCOIN_NODE_CHAINSTATEMANAGER_ARGS_H
|
@ -123,7 +123,6 @@ uint256 g_best_block;
|
|||||||
bool g_parallel_script_checks{false};
|
bool g_parallel_script_checks{false};
|
||||||
bool fCheckBlockIndex = false;
|
bool fCheckBlockIndex = false;
|
||||||
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
|
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
|
||||||
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
|
|
||||||
|
|
||||||
uint256 hashAssumeValid;
|
uint256 hashAssumeValid;
|
||||||
arith_uint256 nMinimumChainWork;
|
arith_uint256 nMinimumChainWork;
|
||||||
@ -1548,8 +1547,9 @@ bool Chainstate::IsInitialBlockDownload() const
|
|||||||
return true;
|
return true;
|
||||||
if (m_chain.Tip()->nChainWork < nMinimumChainWork)
|
if (m_chain.Tip()->nChainWork < nMinimumChainWork)
|
||||||
return true;
|
return true;
|
||||||
if (m_chain.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
if (m_chain.Tip()->Time() < NodeClock::now() - m_chainman.m_options.max_tip_age) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
|
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
|
||||||
m_cached_finished_ibd.store(true, std::memory_order_relaxed);
|
m_cached_finished_ibd.store(true, std::memory_order_relaxed);
|
||||||
return false;
|
return false;
|
||||||
|
@ -63,7 +63,6 @@ struct Params;
|
|||||||
static const int MAX_SCRIPTCHECK_THREADS = 15;
|
static const int MAX_SCRIPTCHECK_THREADS = 15;
|
||||||
/** -par default (number of script-checking threads, 0 = auto) */
|
/** -par default (number of script-checking threads, 0 = auto) */
|
||||||
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
|
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
|
||||||
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
|
|
||||||
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
|
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
|
||||||
/** Default for -stopatheight */
|
/** Default for -stopatheight */
|
||||||
static const int DEFAULT_STOPATHEIGHT = 0;
|
static const int DEFAULT_STOPATHEIGHT = 0;
|
||||||
@ -99,8 +98,6 @@ extern uint256 g_best_block;
|
|||||||
extern bool g_parallel_script_checks;
|
extern bool g_parallel_script_checks;
|
||||||
extern bool fCheckBlockIndex;
|
extern bool fCheckBlockIndex;
|
||||||
extern bool fCheckpointsEnabled;
|
extern bool fCheckpointsEnabled;
|
||||||
/** If the tip is older than this (in seconds), the node is considered to be in initial block download. */
|
|
||||||
extern int64_t nMaxTipAge;
|
|
||||||
|
|
||||||
/** Block hash whose ancestors we will assume to have valid scripts without checking them. */
|
/** Block hash whose ancestors we will assume to have valid scripts without checking them. */
|
||||||
extern uint256 hashAssumeValid;
|
extern uint256 hashAssumeValid;
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
# Copyright (c) 2022 The Bitcoin Core developers
|
# Copyright (c) 2022 The Bitcoin Core developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test logic for setting nMaxTipAge on command line.
|
"""Test logic for setting -maxtipage on command line.
|
||||||
|
|
||||||
Nodes don't consider themselves out of "initial block download" as long as
|
Nodes don't consider themselves out of "initial block download" as long as
|
||||||
their best known block header time is more than nMaxTipAge in the past.
|
their best known block header time is more than -maxtipage in the past.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
Loading…
x
Reference in New Issue
Block a user