Bitcoin Core  24.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 <chainparams.h>
11 #include <consensus/amount.h>
12 #include <logging.h>
13 #include <policy/feerate.h>
14 #include <policy/policy.h>
15 #include <script/standard.h>
16 #include <tinyformat.h>
17 #include <util/error.h>
18 #include <util/moneystr.h>
19 #include <util/system.h>
20 #include <util/translation.h>
21 
22 #include <chrono>
23 #include <memory>
24 
27 
28 namespace {
29 void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
30 {
31  mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count);
32 
33  if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000;
34 
35  mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count);
36 
37  if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000;
38 }
39 }
40 
41 std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts)
42 {
43  mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
44 
45  if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
46 
47  if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
48 
49  // incremental relay fee sets the minimum feerate increase necessary for replacement in the mempool
50  // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
51  if (argsman.IsArgSet("-incrementalrelayfee")) {
52  if (std::optional<CAmount> inc_relay_fee = ParseMoney(argsman.GetArg("-incrementalrelayfee", ""))) {
53  mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()};
54  } else {
55  return AmountErrMsg("incrementalrelayfee", argsman.GetArg("-incrementalrelayfee", ""));
56  }
57  }
58 
59  if (argsman.IsArgSet("-minrelaytxfee")) {
60  if (std::optional<CAmount> min_relay_feerate = ParseMoney(argsman.GetArg("-minrelaytxfee", ""))) {
61  // High fee check is done afterward in CWallet::Create()
62  mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()};
63  } else {
64  return AmountErrMsg("minrelaytxfee", argsman.GetArg("-minrelaytxfee", ""));
65  }
66  } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) {
67  // Allow only setting incremental fee to control both
68  mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate;
69  LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n", mempool_opts.min_relay_feerate.ToString());
70  }
71 
72  // Feerate used to define dust. Shouldn't be changed lightly as old
73  // implementations may inadvertently create non-standard transactions
74  if (argsman.IsArgSet("-dustrelayfee")) {
75  if (std::optional<CAmount> parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""))) {
76  mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()};
77  } else {
78  return AmountErrMsg("dustrelayfee", argsman.GetArg("-dustrelayfee", ""));
79  }
80  }
81 
82  mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
83 
84  if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) {
85  mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY);
86  } else {
87  mempool_opts.max_datacarrier_bytes = std::nullopt;
88  }
89 
90  mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
91  if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
92  return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString());
93  }
94 
95  mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);
96 
97  ApplyArgsManOptions(argsman, mempool_opts.limits);
98 
99  return std::nullopt;
100 }
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:500
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: system.cpp:629
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:604
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:654
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:70
std::string NetworkIDString() const
Return the network string.
Definition: chainparams.h:112
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:99
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:101
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:33
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:39
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition: error.cpp:57
#define LogPrintf(...)
Definition: logging.h:234
std::optional< bilingual_str > ApplyArgsManOptions(const ArgsManager &argsman, const CChainParams &chainparams, MemPoolOptions &mempool_opts)
Overlay the options set in argsman on top of corresponding members in mempool_opts.
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:42
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
Definition: policy.h:39
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for -datacarriersize.
Definition: standard.h:39
static const bool DEFAULT_ACCEPT_DATACARRIER
Definition: standard.h:19
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:1164
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:48