Bitcoin ABC 0.32.4
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 <common/args.h>
10#include <consensus/amount.h>
11#include <kernel/chainparams.h>
12#include <policy/policy.h>
13#include <tinyformat.h>
14#include <util/error.h>
15#include <util/moneystr.h>
16#include <util/translation.h>
17
18#include <chrono>
19#include <memory>
20
22
24static constexpr int MAX_32BIT_MEMPOOL_MB{500};
25
26std::optional<bilingual_str>
27ApplyArgsManOptions(const ArgsManager &argsman, const CChainParams &chainparams,
28 MemPoolOptions &mempool_opts) {
29 mempool_opts.check_ratio =
30 argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
31
32 if (auto mb = argsman.GetIntArg("-maxmempool")) {
33 mempool_opts.max_size_bytes = *mb * 1'000'000;
34 }
35 if (auto mb = argsman.GetIntArg("-maxmempool")) {
36 constexpr bool is_32bit{sizeof(void *) == 4};
37 if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) {
38 return Untranslated(strprintf("-maxmempool is set to %i but can't "
39 "be over %i MB on 32-bit systems",
41 }
42 mempool_opts.max_size_bytes = *mb * 1'000'000;
43 }
44
45 if (auto hours = argsman.GetIntArg("-mempoolexpiry")) {
46 mempool_opts.expiry = std::chrono::hours{*hours};
47 }
48
49 if (argsman.IsArgSet("-minrelaytxfee")) {
50 Amount n = Amount::zero();
51 auto parsed = ParseMoney(argsman.GetArg("-minrelaytxfee", ""), n);
52 if (!parsed || n == Amount::zero()) {
53 return AmountErrMsg("minrelaytxfee",
54 argsman.GetArg("-minrelaytxfee", ""));
55 }
56 // High fee check is done afterward in CWallet::Create()
57 mempool_opts.min_relay_feerate = CFeeRate(n);
58 }
59
60 // Feerate used to define dust. Shouldn't be changed lightly as old
61 // implementations may inadvertently create non-standard transactions.
62 if (argsman.IsArgSet("-dustrelayfee")) {
63 Amount n = Amount::zero();
64 auto parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""), n);
65 if (!parsed || Amount::zero() == n) {
66 return AmountErrMsg("dustrelayfee",
67 argsman.GetArg("-dustrelayfee", ""));
68 }
69 mempool_opts.dust_relay_feerate = CFeeRate(n);
70 }
71
72 mempool_opts.permit_bare_multisig =
73 argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
74
75 mempool_opts.max_datacarrier_bytes =
76 argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)
77 ? std::optional<unsigned>{argsman.GetIntArg("-datacarriersize",
79 : std::nullopt;
80
81 mempool_opts.require_standard =
82 !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
83 if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
84 return strprintf(
86 "acceptnonstdtxn is not currently supported for %s chain"),
87 chainparams.GetChainTypeString());
88 }
89
90 return std::nullopt;
91}
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: args.cpp:372
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:495
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: args.cpp:463
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:525
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:86
std::string GetChainTypeString() const
Return the chain type string.
Definition: chainparams.h:134
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:116
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:118
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:53
static constexpr int MAX_32BIT_MEMPOOL_MB
Maximum mempool size on 32-bit systems.
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