Bitcoin ABC 0.33.12
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.GetIntArg("-checkblockindex")}) {
29 // Interpret bare -checkblockindex argument as 1 instead of 0.
31 args.GetArg("-checkblockindex")->empty() ? 1 : *value;
32 }
33
34 if (auto value{args.GetBoolArg("-checkpoints")}) {
35 opts.checkpoints_enabled = *value;
36 }
37
38 if (auto value{args.GetArg("-minimumchainwork")}) {
39 if (!IsHexNumber(*value)) {
40 return strprintf(
42 "Invalid non-hex (%s) minimum chain work value specified"),
43 *value);
44 }
46 }
47
48 if (auto value{args.GetArg("-assumevalid")}) {
50 }
51
52 if (auto value{args.GetIntArg("-maxtipage")}) {
53 opts.max_tip_age = std::chrono::seconds{*value};
54 }
55
57 ReadDatabaseArgs(args, opts.coins_db);
58 ReadCoinsViewArgs(args, opts.coins_view);
59
60 int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
61 if (script_threads <= 0) {
62 // -par=0 means autodetect (number of cores - 1 script threads)
63 // -par=-n means "leave n cores free" (number of cores - n - 1 script
64 // threads)
65 script_threads += GetNumCores();
66 }
67 // Subtract 1 because the main thread counts towards the par threads.
69 std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
70 LogPrintf("Script verification uses %d additional threads\n",
72
73 if (auto value{args.GetBoolArg("-persistrecentheaderstime")}) {
74 opts.store_recent_headers_time = *value;
75 }
76
77 // When supplied with a max_size of 0, both the signature cache and
78 // script execution cache create the minimum possible cache (2
79 // elements). Therefore, we can use 0 as a floor here.
80 if (auto max_size = args.GetIntArg("-maxscriptcachesize")) {
82 std::max<int64_t>(*max_size, 0) * (1 << 20);
83 }
84 if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
86 std::max<int64_t>(*max_size, 0) * (1 << 20);
87 ;
88 }
89
90 if (auto value{args.GetBoolArg("-parkdeepreorg")}) {
91 opts.park_deep_reorg = *value;
92 }
93
95 "-automaticunparking",
96 !args.GetBoolArg("-avalanche", AVALANCHE_DEFAULT_ENABLED));
97
99 gArgs.GetIntArg("-replayprotectionactivationtime");
100
101 return std::nullopt;
102}
103} // 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< arith_uint256 > minimum_chain_work
If set, it will override the minimum work we will assume exists on some valid chain.
std::optional< int32_t > check_block_index
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:1203
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:141
bool IsHexNumber(std::string_view str)
Return true if the string is a hex number, optionally prefixed with "0x".