Bitcoin Core 31.99.0
P2P Digital Currency
mining_args.cpp
Go to the documentation of this file.
1// Copyright (c) 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/mining_args.h>
6
7#include <common/args.h>
8#include <common/messages.h>
9#include <consensus/amount.h>
10#include <consensus/consensus.h>
11#include <node/mining_types.h>
12#include <policy/feerate.h>
13#include <policy/policy.h>
14#include <tinyformat.h>
15#include <util/moneystr.h>
16#include <util/result.h>
17#include <util/translation.h>
18
19#include <cstdint>
20#include <optional>
21#include <string>
22#include <utility>
23
25using util::Error;
26using util::Result;
27
28namespace node {
29
31{
32 options = FlattenMiningOptions(std::move(options));
34 return Error{Untranslated(strprintf("%s (%d) is lower than minimum safety value of (%d)",
35 use_argnames ? "-blockreservedweight" : "block_reserved_weight",
37 }
39 return Error{Untranslated(strprintf("%s (%d) exceeds consensus maximum block weight (%d)",
40 use_argnames ? "-blockreservedweight" : "block_reserved_weight",
42 }
43 if (*options.block_max_weight > MAX_BLOCK_WEIGHT) {
44 return Error{Untranslated(strprintf("%s (%d) exceeds consensus maximum block weight (%d)",
45 use_argnames ? "-blockmaxweight" : "block_max_weight",
47 }
48 if (*options.block_reserved_weight > *options.block_max_weight) {
49 return Error{Untranslated(strprintf("%s (%d) exceeds %s (%d)",
50 use_argnames ? "-blockreservedweight" : "block_reserved_weight",
51 *options.block_reserved_weight,
52 use_argnames ? "-blockmaxweight" : "block_max_weight",
53 *options.block_max_weight))};
54 }
56 return Error{Untranslated(strprintf("%s (%zu) exceeds consensus maximum block sigops cost (%d)",
57 "coinbase_output_max_additional_sigops",
59 }
60 return {};
61}
62
64{
65 BlockCreateOptions options;
66 if (const auto arg{args.GetArg("-blockmintxfee")}) {
67 std::optional<CAmount> block_min_tx_fee{ParseMoney(*arg)};
68 if (!block_min_tx_fee) return Error{AmountErrMsg("blockmintxfee", *arg)};
69 options.block_min_fee_rate = CFeeRate{*block_min_tx_fee};
70 }
71
72 if (const auto arg{args.GetBoolArg("-printpriority")}) options.print_modified_fee = *arg;
73
74 options.block_reserved_weight = args.GetArg<uint64_t>("-blockreservedweight");
75 options.block_max_weight = args.GetArg<uint64_t>("-blockmaxweight");
76
77 if (auto result{CheckMiningOptions(options, /*use_argnames=*/true)}; !result) return Error{util::ErrorString(result)};
78 return options;
79}
80
82{
87 return options;
88}
89
91{
96 return x;
97}
98
99} // namespace node
ArgsManager & args
Definition: bitcoind.cpp:279
std::string GetArg(const std::string &strArg, const std::string &strDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return string argument or default value.
Definition: args.cpp:519
bool GetBoolArg(const std::string &strArg, bool fDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return boolean argument or default value.
Definition: args.cpp:573
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:32
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
static const int64_t MAX_BLOCK_SIGOPS_COST
The maximum allowed number of signature check operations in a block (network rule)
Definition: consensus.h:17
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
is used externally by mining IPC clients, so it should only declare simple data definitions.
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:45
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition: messages.cpp:165
Definition: messages.h:21
Result< BlockCreateOptions > ReadMiningArgs(const ArgsManager &args)
Read the mining options set in args.
Definition: mining_args.cpp:63
BlockCreateOptions FlattenMiningOptions(BlockCreateOptions options)
Replace null optional values with their hardcoded defaults.
Definition: mining_args.cpp:81
static const bool DEFAULT_PRINT_MODIFIED_FEE
Definition: mining_args.h:15
BlockCreateOptions MergeMiningOptions(BlockCreateOptions x, const BlockCreateOptions &y)
Merge two BlockCreateOptions structs, replacing null values in x with non-null values from y.
Definition: mining_args.cpp:90
Result< void > CheckMiningOptions(BlockCreateOptions options, bool use_argnames)
Check option values for validity.
Definition: mining_args.cpp:30
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:93
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE
Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by min...
Definition: policy.h:36
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT
Default for -blockmaxweight, which controls the range of block weights the mining code will create.
Definition: policy.h:25
static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT
Default for -blockreservedweight.
Definition: policy.h:27
static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT
This accounts for the block header, var_int encoding of the transaction count and a minimally viable ...
Definition: policy.h:34
Block template creation options.
Definition: mining_types.h:33
std::optional< bool > print_modified_fee
Whether to log the fee rate of each transaction when it is added to the block template.
Definition: mining_types.h:48
std::optional< CFeeRate > block_min_fee_rate
Minimum fee rate for transactions to be included.
Definition: mining_types.h:42
std::optional< uint64_t > block_max_weight
Maximum block weight, defaults to -maxblockweight.
Definition: mining_types.h:65
size_t coinbase_output_max_additional_sigops
The maximum additional sigops which the pool will add in coinbase transaction outputs.
Definition: mining_types.h:70
std::optional< uint64_t > block_reserved_weight
The default reserved weight for the fixed-size block header, transaction count and coinbase transacti...
Definition: mining_types.h:58
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:82