Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
node
chainstatemanager_args.cpp
Go to the documentation of this file.
1
// Copyright (c) 2022-present 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
5
#include <
node/chainstatemanager_args.h
>
6
7
#include <
arith_uint256.h
>
8
#include <
common/args.h
>
9
#include <
common/system.h
>
10
#include <logging.h>
11
#include <
node/coins_view_args.h
>
12
#include <
node/database_args.h
>
13
#include <
tinyformat.h
>
14
#include <
uint256.h
>
15
#include <
util/result.h
>
16
#include <
util/strencodings.h
>
17
#include <
util/translation.h
>
18
#include <validation.h>
19
20
#include <algorithm>
21
#include <chrono>
22
#include <string>
23
24
namespace
node
{
25
util::Result<void>
ApplyArgsManOptions
(
const
ArgsManager
&
args
,
ChainstateManager::Options
& opts)
26
{
27
if
(
auto
value{
args
.GetIntArg(
"-checkblockindex"
)}) {
28
// Interpret bare -checkblockindex argument as 1 instead of 0.
29
opts.
check_block_index
=
args
.GetArg(
"-checkblockindex"
)->empty() ? 1 : *value;
30
}
31
32
if
(
auto
value{
args
.GetArg(
"-minimumchainwork"
)}) {
33
if
(
auto
min_work{
uint256::FromUserHex
(*value)}) {
34
opts.
minimum_chain_work
=
UintToArith256
(*min_work);
35
}
else
{
36
return
util::Error
{
Untranslated
(
strprintf
(
"Invalid minimum work specified (%s), must be up to %d hex digits"
, *value,
uint256::size
() * 2))};
37
}
38
}
39
40
if
(
auto
value{
args
.GetArg(
"-assumevalid"
)}) {
41
if
(
auto
block_hash{
uint256::FromUserHex
(*value)}) {
42
opts.
assumed_valid_block
= *block_hash;
43
}
else
{
44
return
util::Error
{
Untranslated
(
strprintf
(
"Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable)"
, *value,
uint256::size
() * 2))};
45
}
46
}
47
48
if
(
auto
value{
args
.GetIntArg(
"-maxtipage"
)}) opts.
max_tip_age
= std::chrono::seconds{*value};
49
50
ReadDatabaseArgs
(
args
, opts.coins_db);
51
ReadCoinsViewArgs
(
args
, opts.coins_view);
52
53
int
script_threads =
args
.GetIntArg(
"-par"
,
DEFAULT_SCRIPTCHECK_THREADS
);
54
if
(script_threads <= 0) {
55
// -par=0 means autodetect (number of cores - 1 script threads)
56
// -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
57
script_threads +=
GetNumCores
();
58
}
59
// Subtract 1 because the main thread counts towards the par threads.
60
opts.worker_threads_num = script_threads - 1;
61
62
if
(
auto
max_size =
args
.
GetIntArg
(
"-maxsigcachesize"
)) {
63
// 1. When supplied with a max_size of 0, both the signature cache and
64
// script execution cache create the minimum possible cache (2
65
// elements). Therefore, we can use 0 as a floor here.
66
// 2. Multiply first, divide after to avoid integer truncation.
67
size_t
clamped_size_each = std::max<int64_t>(*max_size, 0) * (1 << 20) / 2;
68
opts.script_execution_cache_bytes = clamped_size_each;
69
opts.signature_cache_bytes = clamped_size_each;
70
}
71
72
return
{};
73
}
74
}
// namespace node
args.h
UintToArith256
arith_uint256 UintToArith256(const uint256 &a)
Definition
arith_uint256.cpp:225
arith_uint256.h
args
ArgsManager & args
Definition
bitcoind.cpp:277
chainstatemanager_args.h
DEFAULT_SCRIPTCHECK_THREADS
static constexpr int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition
chainstatemanager_args.h:14
ArgsManager
Definition
args.h:103
ArgsManager::GetIntArg
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Definition
args.h:306
ChainstateManager::Options
kernel::ChainstateManagerOpts Options
Definition
validation.h:999
base_blob< 256 >::size
static constexpr unsigned int size()
Definition
uint256.h:106
uint256::FromUserHex
static std::optional< uint256 > FromUserHex(std::string_view str)
Definition
uint256.h:198
util::Result
Definition
result.h:36
coins_view_args.h
GetNumCores
int GetNumCores()
Return the number of cores available on the current system.
Definition
system.cpp:109
database_args.h
node
Definition
messages.h:21
node::ApplyArgsManOptions
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
Definition
blockmanager_args.cpp:18
node::ReadCoinsViewArgs
void ReadCoinsViewArgs(const ArgsManager &args, CoinsViewOptions &options)
Definition
coins_view_args.cpp:11
node::ReadDatabaseArgs
void ReadDatabaseArgs(const ArgsManager &args, DBOptions &options)
Definition
database_args.cpp:11
result.h
strencodings.h
kernel::ChainstateManagerOpts::assumed_valid_block
std::optional< uint256 > assumed_valid_block
If set, it will override the block hash whose ancestors we will assume to have valid scripts without ...
Definition
chainstatemanager_opts.h:40
kernel::ChainstateManagerOpts::minimum_chain_work
std::optional< arith_uint256 > minimum_chain_work
If set, it will override the minimum work we will assume exists on some valid chain.
Definition
chainstatemanager_opts.h:38
kernel::ChainstateManagerOpts::check_block_index
std::optional< int32_t > check_block_index
Definition
chainstatemanager_opts.h:36
kernel::ChainstateManagerOpts::max_tip_age
std::chrono::seconds max_tip_age
If the tip is older than this, the node is considered to be in initial block download.
Definition
chainstatemanager_opts.h:42
util::Error
Definition
result.h:15
system.h
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
translation.h
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition
translation.h:82
uint256.h
Generated on
for Bitcoin Core by
1.17.0