/tmp/bitcoin/src/node/chainstatemanager_args.cpp
Line | Count | Source |
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/byte_units.h> |
16 | | #include <util/result.h> |
17 | | #include <util/strencodings.h> |
18 | | #include <util/translation.h> |
19 | | #include <validation.h> |
20 | | |
21 | | #include <algorithm> |
22 | | #include <chrono> |
23 | | #include <string> |
24 | | |
25 | | namespace node { |
26 | | util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts) |
27 | 2.83k | { |
28 | 2.83k | if (auto value{args.GetIntArg("-checkblockindex")}) { |
29 | | // Interpret bare -checkblockindex argument as 1 instead of 0. |
30 | 8 | opts.check_block_index = args.GetArg("-checkblockindex")->empty() ? 1 : *value; |
31 | 8 | } |
32 | | |
33 | 2.83k | if (auto value{args.GetArg("-minimumchainwork")}) { |
34 | 23 | if (auto min_work{uint256::FromUserHex(*value)}) { |
35 | 20 | opts.minimum_chain_work = UintToArith256(*min_work); |
36 | 20 | } else { |
37 | 3 | return util::Error{Untranslated(strprintf("Invalid minimum work specified (%s), must be up to %d hex digits", *value, uint256::size() * 2))}; |
38 | 3 | } |
39 | 23 | } |
40 | | |
41 | 2.82k | if (auto value{args.GetArg("-assumevalid")}) { |
42 | 19 | if (auto block_hash{uint256::FromUserHex(*value)}) { |
43 | 17 | opts.assumed_valid_block = *block_hash; |
44 | 17 | } else { |
45 | 2 | 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))}; |
46 | 2 | } |
47 | 19 | } |
48 | | |
49 | 2.82k | if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value}; |
50 | | |
51 | 2.82k | ReadDatabaseArgs(args, opts.coins_db); |
52 | 2.82k | ReadCoinsViewArgs(args, opts.coins_view); |
53 | | |
54 | 2.82k | int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS); |
55 | 2.82k | if (script_threads <= 0) { |
56 | | // -par=0 means autodetect (number of cores - 1 script threads) |
57 | | // -par=-n means "leave n cores free" (number of cores - n - 1 script threads) |
58 | 680 | script_threads += GetNumCores(); |
59 | 680 | } |
60 | | // Subtract 1 because the main thread counts towards the par threads. |
61 | 2.82k | opts.worker_threads_num = script_threads - 1; |
62 | | |
63 | 2.82k | if (auto max_size = args.GetIntArg("-maxsigcachesize")) { |
64 | | // 1. When supplied with a max_size of 0, both the signature cache and |
65 | | // script execution cache create the minimum possible cache (2 |
66 | | // elements). Therefore, we can use 0 as a floor here. |
67 | | // 2. Multiply first, divide after to avoid integer truncation. |
68 | 0 | size_t clamped_size_each{size_t(std::max<int64_t>(*max_size, 0) * 1_MiB / 2)}; |
69 | 0 | opts.script_execution_cache_bytes = clamped_size_each; |
70 | 0 | opts.signature_cache_bytes = clamped_size_each; |
71 | 0 | } |
72 | | |
73 | 2.82k | return {}; |
74 | 2.82k | } |
75 | | } // namespace node |