Bitcoin ABC  0.26.3
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 <mempool_args.h>
6 
8 
9 #include <chainparams.h>
10 #include <consensus/amount.h>
11 #include <policy/policy.h>
12 #include <tinyformat.h>
13 #include <util/error.h>
14 #include <util/moneystr.h>
15 #include <util/system.h>
16 #include <util/translation.h>
17 
18 #include <chrono>
19 #include <memory>
20 
22 
23 std::optional<bilingual_str>
24 ApplyArgsManOptions(const ArgsManager &argsman, const CChainParams &chainparams,
25  MemPoolOptions &mempool_opts) {
26  mempool_opts.check_ratio =
27  argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
28 
29  if (auto mb = argsman.GetIntArg("-maxmempool")) {
30  mempool_opts.max_size_bytes = *mb * 1'000'000;
31  }
32 
33  if (auto hours = argsman.GetIntArg("-mempoolexpiry")) {
34  mempool_opts.expiry = std::chrono::hours{*hours};
35  }
36 
37  if (argsman.IsArgSet("-minrelaytxfee")) {
38  Amount n = Amount::zero();
39  auto parsed = ParseMoney(argsman.GetArg("-minrelaytxfee", ""), n);
40  if (!parsed || n == Amount::zero()) {
41  return AmountErrMsg("minrelaytxfee",
42  argsman.GetArg("-minrelaytxfee", ""));
43  }
44  // High fee check is done afterward in CWallet::Create()
45  mempool_opts.min_relay_feerate = CFeeRate(n);
46  }
47 
48  // Feerate used to define dust. Shouldn't be changed lightly as old
49  // implementations may inadvertently create non-standard transactions.
50  if (argsman.IsArgSet("-dustrelayfee")) {
51  Amount n = Amount::zero();
52  auto parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""), n);
53  if (!parsed || Amount::zero() == n) {
54  return AmountErrMsg("dustrelayfee",
55  argsman.GetArg("-dustrelayfee", ""));
56  }
57  mempool_opts.dust_relay_feerate = CFeeRate(n);
58  }
59 
60  mempool_opts.permit_bare_multisig =
61  argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
62 
63  mempool_opts.max_datacarrier_bytes =
64  argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)
65  ? std::optional<unsigned>{argsman.GetIntArg("-datacarriersize",
67  : std::nullopt;
68 
69  mempool_opts.require_standard =
70  !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
71  if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
72  return strprintf(
74  "acceptnonstdtxn is not currently supported for %s chain"),
75  chainparams.NetworkIDString());
76  }
77 
78  return std::nullopt;
79 }
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:490
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: system.cpp:635
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:603
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:665
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
std::string NetworkIDString() const
Return the BIP70 network string (main, test or regtest)
Definition: chainparams.h:121
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:103
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:105
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition: error.cpp:51
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.
bool ParseMoney(const std::string &money_string, Amount &nRet)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:37
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
Definition: policy.h:56
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for nMaxDatacarrierBytes.
Definition: standard.h:36
static const bool DEFAULT_ACCEPT_DATACARRIER
Definition: standard.h:17
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
Options struct containing options for constructing a CTxMemPool.
int check_ratio
The ratio used to determine how often sanity checks will run.
std::optional< unsigned > max_datacarrier_bytes
A data carrying output is an unspendable output containing data.
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:1202
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36