Bitcoin ABC 0.33.10
P2P Digital Currency
chainstatemanager_args.cpp
Go to the documentation of this file.
1// Copyright (c) 2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <arith_uint256.h>
9#include <common/args.h>
10#include <common/system.h>
11#include <logging.h>
13#include <node/database_args.h>
14#include <tinyformat.h>
15#include <uint256.h>
16#include <util/strencodings.h>
17#include <util/translation.h>
18#include <validation.h>
19
20#include <algorithm>
21#include <chrono>
22#include <optional>
23#include <string>
24
25namespace node {
26std::optional<bilingual_str>
28 if (auto value{args.GetBoolArg("-checkblockindex")}) {
29 opts.check_block_index = *value;
30 }
31
32 if (auto value{args.GetBoolArg("-checkpoints")}) {
33 opts.checkpoints_enabled = *value;
34 }
35
36 if (auto value{args.GetArg("-minimumchainwork")}) {
37 if (!IsHexNumber(*value)) {
38 return strprintf(
40 "Invalid non-hex (%s) minimum chain work value specified"),
41 *value);
42 }
44 }
45
46 if (auto value{args.GetArg("-assumevalid")}) {
48 }
49
50 if (auto value{args.GetIntArg("-maxtipage")}) {
51 opts.max_tip_age = std::chrono::seconds{*value};
52 }
53
55 ReadDatabaseArgs(args, opts.coins_db);
56 ReadCoinsViewArgs(args, opts.coins_view);
57
58 int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
59 if (script_threads <= 0) {
60 // -par=0 means autodetect (number of cores - 1 script threads)
61 // -par=-n means "leave n cores free" (number of cores - n - 1 script
62 // threads)
63 script_threads += GetNumCores();
64 }
65 // Subtract 1 because the main thread counts towards the par threads.
67 std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
68 LogPrintf("Script verification uses %d additional threads\n",
70
71 if (auto value{args.GetBoolArg("-persistrecentheaderstime")}) {
72 opts.store_recent_headers_time = *value;
73 }
74
75 // When supplied with a max_size of 0, both the signature cache and
76 // script execution cache create the minimum possible cache (2
77 // elements). Therefore, we can use 0 as a floor here.
78 if (auto max_size = args.GetIntArg("-maxscriptcachesize")) {
80 std::max<int64_t>(*max_size, 0) * (1 << 20);
81 }
82 if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
84 std::max<int64_t>(*max_size, 0) * (1 << 20);
85 ;
86 }
87
88 if (auto value{args.GetBoolArg("-parkdeepreorg")}) {
89 opts.park_deep_reorg = *value;
90 }
91
93 "-automaticunparking",
94 !args.GetBoolArg("-avalanche", AVALANCHE_DEFAULT_ENABLED));
95
97 gArgs.GetIntArg("-replayprotectionactivationtime");
98
99 return std::nullopt;
100}
101} // namespace node
ArgsManager gArgs
Definition: args.cpp:39
arith_uint256 UintToArith256(const uint256 &a)
static constexpr bool AVALANCHE_DEFAULT_ENABLED
Is avalanche enabled by default.
Definition: avalanche.h:15
static constexpr int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:494
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:462
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:524
#define LogPrintf(...)
Definition: logging.h:424
Definition: messages.h:12
void ReadCoinsViewArgs(const ArgsManager &args, CoinsViewOptions &options)
void ReadDatabaseArgs(const ArgsManager &args, DBOptions &options)
void ApplyArgsManOptions(const ArgsManager &args, const Config &config, BlockFitter::Options &options)
Apply options from ArgsManager to BlockFitter options.
Definition: blockfitter.cpp:40
static BlockHash fromHex(const std::string &str)
Definition: blockhash.h:17
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
std::optional< bool > check_block_index
std::optional< arith_uint256 > minimum_chain_work
If set, it will override the minimum work we will assume exists on some valid chain.
std::chrono::seconds max_tip_age
If the tip is older than this, the node is considered to be in initial block download.
std::optional< BlockHash > assumed_valid_block
If set, it will override the block hash whose ancestors we will assume to have valid scripts without ...
int worker_threads_num
Number of script check worker threads.
bool store_recent_headers_time
If set, store and load the last few block headers reception time to speed up RTT bootstraping.
std::optional< int64_t > replay_protection_activation_time
If set, this overwrites the timestamp at which replay protection activates.
int GetNumCores()
Return the number of cores available on the current system.
Definition: system.cpp:114
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
uint256 uint256S(const char *str)
uint256 from const char *.
Definition: uint256.h:143
bool IsHexNumber(std::string_view str)
Return true if the string is a hex number, optionally prefixed with "0x".