Bitcoin Core 29.99.0
P2P Digital Currency
mempool_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
5#include <node/mempool_args.h>
6
9
10#include <common/args.h>
11#include <common/messages.h>
12#include <consensus/amount.h>
13#include <kernel/chainparams.h>
14#include <logging.h>
15#include <policy/feerate.h>
16#include <policy/policy.h>
17#include <tinyformat.h>
18#include <util/moneystr.h>
19#include <util/translation.h>
20
21#include <chrono>
22#include <memory>
23
27
29static constexpr int MAX_32BIT_MEMPOOL_MB{500};
30
31namespace {
32void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
33{
34 mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count);
35
36 if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000;
37
38 mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count);
39
40 if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000;
41}
42}
43
44util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts)
45{
46 mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
47
48 if (auto mb = argsman.GetIntArg("-maxmempool")) {
49 constexpr bool is_32bit{sizeof(void*) == 4};
50 if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) {
51 return util::Error{Untranslated(strprintf("-maxmempool is set to %i but can't be over %i MB on 32-bit systems", *mb, MAX_32BIT_MEMPOOL_MB))};
52 }
53 mempool_opts.max_size_bytes = *mb * 1'000'000;
54 }
55
56 if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
57
58 // incremental relay fee sets the minimum feerate increase necessary for replacement in the mempool
59 // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
60 if (const auto arg{argsman.GetArg("-incrementalrelayfee")}) {
61 if (std::optional<CAmount> inc_relay_fee = ParseMoney(*arg)) {
62 mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()};
63 } else {
64 return util::Error{AmountErrMsg("incrementalrelayfee", *arg)};
65 }
66 }
67
69 if (const auto arg{argsman.GetArg("-minrelaytxfee")}) {
70 if (std::optional<CAmount> min_relay_feerate = ParseMoney(*arg)) {
71 // High fee check is done afterward in CWallet::Create()
72 mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()};
73 } else {
74 return util::Error{AmountErrMsg("minrelaytxfee", *arg)};
75 }
76 } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) {
77 // Allow only setting incremental fee to control both
78 mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate;
79 LogInfo("Increasing minrelaytxfee to %s to match incrementalrelayfee", mempool_opts.min_relay_feerate.ToString());
80 }
81
82 // Feerate used to define dust. Shouldn't be changed lightly as old
83 // implementations may inadvertently create non-standard transactions
84 if (const auto arg{argsman.GetArg("-dustrelayfee")}) {
85 if (std::optional<CAmount> parsed = ParseMoney(*arg)) {
86 mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()};
87 } else {
88 return util::Error{AmountErrMsg("dustrelayfee", *arg)};
89 }
90 }
91
92 mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
93
94 if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) {
95 mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY);
96 } else {
97 mempool_opts.max_datacarrier_bytes = std::nullopt;
98 }
99
100 mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", DEFAULT_ACCEPT_NON_STD_TXN);
101 if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
102 return util::Error{Untranslated(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.GetChainTypeString()))};
103 }
104
105 mempool_opts.persist_v1_dat = argsman.GetBoolArg("-persistmempoolv1", mempool_opts.persist_v1_dat);
106
107 ApplyArgsManOptions(argsman, mempool_opts.limits);
108
109 return {};
110}
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:482
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:457
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:507
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
std::string GetChainTypeString() const
Return the chain type string.
Definition: chainparams.h:101
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:90
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:35
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:29
#define LogInfo(...)
Definition: logging.h:356
static constexpr int MAX_32BIT_MEMPOOL_MB
Maximum mempool size on 32-bit systems.
util::Result< void > ApplyArgsManOptions(const ArgsManager &argsman, const CChainParams &chainparams, MemPoolOptions &mempool_opts)
Overlay the options set in argsman on top of corresponding members in mempool_opts.
static constexpr bool DEFAULT_ACCEPT_NON_STD_TXN
Default for -acceptnonstdtxn.
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
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:167
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for -datacarriersize in vbytes.
Definition: policy.h:80
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
Definition: policy.h:44
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
Definition: policy.h:48
static const bool DEFAULT_ACCEPT_DATACARRIER
Default for -datacarrier.
Definition: policy.h:76
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE
Default for -minrelaytxfee, minimum relay fee for transactions.
Definition: policy.h:66
Options struct containing limit options for a CTxMemPool.
int64_t descendant_count
The maximum allowed number of transactions in a package including the entry and its descendants.
int64_t descendant_size_vbytes
The maximum allowed size in virtual bytes of an entry and its descendants within a package.
int64_t ancestor_count
The maximum allowed number of transactions in a package including the entry and its ancestors.
int64_t ancestor_size_vbytes
The maximum allowed size in virtual bytes of an entry and its ancestors within a package.
Options struct containing options for constructing a CTxMemPool.
std::optional< unsigned > max_datacarrier_bytes
A data carrying output is an unspendable output containing data.
CFeeRate incremental_relay_feerate
CFeeRate min_relay_feerate
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
std::chrono::seconds expiry
#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