mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-12 18:01:57 +02:00
refactor: Add stop_at_height option in ChainstateManager
Remove access to the global gArgs for the stopatheight argument and replace it by adding a field to the existing ChainstateManager Options struct. This should eventually allow users of the ChainstateManager to not rely on the global gArgs and instead pass in their own options.
This commit is contained in:
parent
214f8f18b3
commit
ef95be334f
@ -21,6 +21,7 @@ class CChainParams;
|
||||
|
||||
static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true};
|
||||
static constexpr auto DEFAULT_MAX_TIP_AGE{24h};
|
||||
static constexpr int DEFAULT_STOPATHEIGHT{0};
|
||||
|
||||
namespace kernel {
|
||||
|
||||
@ -45,6 +46,7 @@ struct ChainstateManagerOpts {
|
||||
DBOptions coins_db{};
|
||||
CoinsViewOptions coins_view{};
|
||||
Notifications& notifications;
|
||||
int stop_at_height{DEFAULT_STOPATHEIGHT};
|
||||
};
|
||||
|
||||
} // namespace kernel
|
||||
|
@ -37,6 +37,8 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
|
||||
|
||||
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
|
||||
|
||||
if (auto value{args.GetIntArg("-stopatheight")}) opts.stop_at_height = *value;
|
||||
|
||||
ReadDatabaseArgs(args, opts.block_tree_db);
|
||||
ReadDatabaseArgs(args, opts.coins_db);
|
||||
ReadCoinsViewArgs(args, opts.coins_view);
|
||||
|
@ -3104,7 +3104,6 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
||||
|
||||
CBlockIndex *pindexMostWork = nullptr;
|
||||
CBlockIndex *pindexNewTip = nullptr;
|
||||
int nStopAtHeight = gArgs.GetIntArg("-stopatheight", DEFAULT_STOPATHEIGHT);
|
||||
do {
|
||||
// Block until the validation queue drains. This should largely
|
||||
// never happen in normal operation, however may happen during
|
||||
@ -3179,7 +3178,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
||||
}
|
||||
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
||||
|
||||
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
|
||||
if (m_chainman.StopAtHeight() && pindexNewTip && pindexNewTip->nHeight >= m_chainman.StopAtHeight()) StartShutdown();
|
||||
|
||||
if (WITH_LOCK(::cs_main, return m_disabled)) {
|
||||
// Background chainstate has reached the snapshot base block, so exit.
|
||||
|
@ -65,8 +65,6 @@ struct Params;
|
||||
static const int MAX_SCRIPTCHECK_THREADS = 15;
|
||||
/** -par default (number of script-checking threads, 0 = auto) */
|
||||
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
|
||||
/** Default for -stopatheight */
|
||||
static const int DEFAULT_STOPATHEIGHT = 0;
|
||||
/** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pruned. */
|
||||
static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
|
||||
static const signed int DEFAULT_CHECKBLOCKS = 6;
|
||||
@ -960,6 +958,7 @@ public:
|
||||
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; };
|
||||
int StopAtHeight() const { return m_options.stop_at_height; };
|
||||
|
||||
/**
|
||||
* Alias for ::cs_main.
|
||||
|
Loading…
x
Reference in New Issue
Block a user