Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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
89
98
99} // namespace node
ArgsManager & args
Definition bitcoind.cpp:280
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:517
bool GetBoolArg(const std::string &strArg, bool fDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return boolean argument or default value.
Definition args.cpp:571
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition feerate.h:32
constexpr int64_t MAX_BLOCK_SIGOPS_COST
The maximum allowed number of signature check operations in a block (network rule).
Definition consensus.h:17
constexpr unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule).
Definition consensus.h:15
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition messages.cpp:158
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:158
Result< BlockCreateOptions > ReadMiningArgs(const ArgsManager &args)
Read the mining options set in args.
BlockCreateOptions FlattenMiningOptions(BlockCreateOptions options)
Replace null optional values with their hardcoded defaults.
BlockCreateOptions MergeMiningOptions(BlockCreateOptions x, const BlockCreateOptions &y)
Merge two BlockCreateOptions structs, replacing null values in x with non-null values from y.
Result< void > CheckMiningOptions(BlockCreateOptions options, bool use_argnames)
Check option values for validity.
constexpr bool DEFAULT_PRINT_MODIFIED_FEE
Definition mining_args.h:15
bilingual_str ErrorString(const Result< T > &result)
Definition result.h:93
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
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
constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT
Default for -blockreservedweight.
Definition policy.h:27
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.
std::optional< bool > print_modified_fee
Whether to log the fee rate of each transaction when it is added to the block template.
std::optional< CFeeRate > block_min_fee_rate
Minimum fee rate for transactions to be included.
std::optional< uint64_t > block_max_weight
Maximum block weight, defaults to -maxblockweight.
size_t coinbase_output_max_additional_sigops
The maximum additional sigops which the pool will add in coinbase transaction outputs.
std::optional< uint64_t > block_reserved_weight
The default reserved weight for the fixed-size block header, transaction count and coinbase transacti...
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition translation.h:82