mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge bitcoin/bitcoin#25704: refactor: Remove almost all validation option globals
aaaa7bd0baiwyu: Add missing includes (MacroFake)fa9ebec096Remove g_parallel_script_checks (MacroFake)fa7c834b9fMove ::fCheckBlockIndex into ChainstateManager (MacroFake)fa43188d86Move ::fCheckpointsEnabled into ChainstateManager (MacroFake)cccca83099Move ::nMinimumChainWork into ChainstateManager (MacroFake)fa29d0b57cMove ::hashAssumeValid into ChainstateManager (MacroFake)faf44876dbMove ::nMaxTipAge into ChainstateManager (MacroFake) Pull request description: It seems preferable to assign globals to a class (in this case `ChainstateManager`), than to leave them dangling. This should clarify scope for code-readers, as well as clarifying unit test behaviour. ACKs for top commit: dergoegge: Code review ACKaaaa7bd0baryanofsky: Code review ACKaaaa7bd0ba. No changes since last review, other than rebase aureleoules: reACKaaaa7bd0baTree-SHA512: 83ec3ba0fb4f1dad95810d4bd4e578454e0718dc1bdd3a794cc4e48aa819b6f5dad4ac4edab3719bdfd5f89cbe23c2740a50fd56c1ff81c99e521c5f6d4e898d
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
|
||||
#include <node/chainstate.h>
|
||||
|
||||
#include <arith_uint256.h>
|
||||
#include <chain.h>
|
||||
#include <coins.h>
|
||||
#include <consensus/params.h>
|
||||
#include <logging.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/caches.h>
|
||||
#include <sync.h>
|
||||
@@ -21,6 +23,7 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -32,13 +35,13 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
|
||||
return options.reindex || options.reindex_chainstate || chainstate->CoinsTip().GetBestBlock().IsNull();
|
||||
};
|
||||
|
||||
if (!hashAssumeValid.IsNull()) {
|
||||
LogPrintf("Assuming ancestors of block %s have valid signatures.\n", hashAssumeValid.GetHex());
|
||||
if (!chainman.AssumedValidBlock().IsNull()) {
|
||||
LogPrintf("Assuming ancestors of block %s have valid signatures.\n", chainman.AssumedValidBlock().GetHex());
|
||||
} else {
|
||||
LogPrintf("Validating signatures for all blocks.\n");
|
||||
}
|
||||
LogPrintf("Setting nMinimumChainWork=%s\n", nMinimumChainWork.GetHex());
|
||||
if (nMinimumChainWork < UintToArith256(chainman.GetConsensus().nMinimumChainWork)) {
|
||||
LogPrintf("Setting nMinimumChainWork=%s\n", chainman.MinimumChainWork().GetHex());
|
||||
if (chainman.MinimumChainWork() < UintToArith256(chainman.GetConsensus().nMinimumChainWork)) {
|
||||
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainman.GetConsensus().nMinimumChainWork.GetHex());
|
||||
}
|
||||
if (nPruneTarget == std::numeric_limits<uint64_t>::max()) {
|
||||
|
||||
39
src/node/chainstatemanager_args.cpp
Normal file
39
src/node/chainstatemanager_args.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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 <arith_uint256.h>
|
||||
#include <tinyformat.h>
|
||||
#include <uint256.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace node {
|
||||
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts)
|
||||
{
|
||||
if (auto value{args.GetBoolArg("-checkblockindex")}) opts.check_block_index = *value;
|
||||
|
||||
if (auto value{args.GetBoolArg("-checkpoints")}) opts.checkpoints_enabled = *value;
|
||||
|
||||
if (auto value{args.GetArg("-minimumchainwork")}) {
|
||||
if (!IsHexNumber(*value)) {
|
||||
return strprintf(Untranslated("Invalid non-hex (%s) minimum chain work value specified"), *value);
|
||||
}
|
||||
opts.minimum_chain_work = UintToArith256(uint256S(*value));
|
||||
}
|
||||
|
||||
if (auto value{args.GetArg("-assumevalid")}) opts.assumed_valid_block = uint256S(*value);
|
||||
|
||||
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace node
|
||||
19
src/node/chainstatemanager_args.h
Normal file
19
src/node/chainstatemanager_args.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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>
|
||||
|
||||
#include <optional>
|
||||
|
||||
class ArgsManager;
|
||||
struct bilingual_str;
|
||||
|
||||
namespace node {
|
||||
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts);
|
||||
} // namespace node
|
||||
|
||||
#endif // BITCOIN_NODE_CHAINSTATEMANAGER_ARGS_H
|
||||
Reference in New Issue
Block a user