Bitcoin ABC 0.34.2
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 (auto min_work{uint256::FromUserHex(*value)}) {
40 opts.minimum_chain_work = UintToArith256(*min_work);
41 } else {
42 return strprintf(Untranslated("Invalid minimum work specified "
43 "(%s), must be up to %d hex digits"),
44 *value, uint256::size() * 2);
45 }
46 }
47
48 if (auto value{args.GetArg("-assumevalid")}) {
49 if (auto block_hash{BlockHash::FromUserHex(*value)}) {
50 opts.assumed_valid_block = *block_hash;
51 } else {
52 return strprintf(
53 Untranslated("Invalid assumevalid block hash specified (%s), "
54 "must be up to %d hex digits (or 0 to disable)"),
55 *value, BlockHash::size() * 2);
56 }
57 }
58
59 if (auto value{args.GetIntArg("-maxtipage")}) {
60 opts.max_tip_age = std::chrono::seconds{*value};
61 }
62
64 ReadDatabaseArgs(args, opts.coins_db);
65 ReadCoinsViewArgs(args, opts.coins_view);
66
67 int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
68 if (script_threads <= 0) {
69 // -par=0 means autodetect (number of cores - 1 script threads)
70 // -par=-n means "leave n cores free" (number of cores - n - 1 script
71 // threads)
72 script_threads += GetNumCores();
73 }
74 // Subtract 1 because the main thread counts towards the par threads.
75 opts.worker_threads_num = script_threads - 1;
76
77 if (auto value{args.GetBoolArg("-persistrecentheaderstime")}) {
78 opts.store_recent_headers_time = *value;
79 }
80
81 // When supplied with a max_size of 0, both the signature cache and
82 // script execution cache create the minimum possible cache (2
83 // elements). Therefore, we can use 0 as a floor here.
84 if (auto max_size = args.GetIntArg("-maxscriptcachesize")) {
86 std::max<int64_t>(*max_size, 0) * (1 << 20);
87 }
88 if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
90 std::max<int64_t>(*max_size, 0) * (1 << 20);
91 ;
92 }
93
94 if (auto value{args.GetBoolArg("-parkdeepreorg")}) {
95 opts.park_deep_reorg = *value;
96 }
97
99 "-automaticunparking",
100 !args.GetBoolArg("-avalanche", AVALANCHE_DEFAULT_ENABLED));
101
103 gArgs.GetIntArg("-replayprotectionactivationtime");
104
105 return std::nullopt;
106}
107} // 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)
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
static constexpr unsigned int size()
Definition: uint256.h:128
static std::optional< uint256 > FromUserHex(std::string_view str)
Definition: uint256.h:204
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 std::optional< BlockHash > FromUserHex(std::string_view str)
Definition: blockhash.h:20
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