Branch data Line data Source code
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 : :
7 : : #include <kernel/mempool_limits.h>
8 : : #include <kernel/mempool_options.h>
9 : :
10 : : #include <common/args.h>
11 : : #include <consensus/amount.h>
12 : : #include <kernel/chainparams.h>
13 : : #include <logging.h>
14 : : #include <policy/feerate.h>
15 : : #include <policy/policy.h>
16 : : #include <tinyformat.h>
17 [ + - ]: 2 : #include <util/error.h>
18 [ + - ]: 2 : #include <util/moneystr.h>
19 : : #include <util/translation.h>
20 : :
21 : : #include <chrono>
22 : : #include <memory>
23 : :
24 : : using kernel::MemPoolLimits;
25 : : using kernel::MemPoolOptions;
26 : :
27 : : namespace {
28 : 1 : void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
29 : : {
30 [ + - ][ + - ]: 1 : mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count);
31 : :
32 [ + - ][ + - ]: 1 : if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000;
[ + - ]
33 : :
34 [ + - ][ + - ]: 1 : mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count);
35 : :
36 [ + - ][ + - ]: 1 : if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000;
[ + - ]
37 : 1 : }
38 : : }
39 : :
40 : 1 : util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts)
41 : : {
42 [ + - ][ + - ]: 1 : mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
43 : :
44 [ + - ][ + - ]: 1 : if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
[ + - ]
45 : :
46 [ + - ][ + - ]: 1 : if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
[ + - ]
47 : :
48 : : // incremental relay fee sets the minimum feerate increase necessary for replacement in the mempool
49 : : // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
50 [ + - ][ + - ]: 1 : if (argsman.IsArgSet("-incrementalrelayfee")) {
[ + - ]
51 [ # # ][ # # ]: 0 : if (std::optional<CAmount> inc_relay_fee = ParseMoney(argsman.GetArg("-incrementalrelayfee", ""))) {
[ # # ][ # # ]
[ # # ]
52 : 0 : mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()};
53 : 0 : } else {
54 [ # # ][ # # ]: 0 : return util::Error{AmountErrMsg("incrementalrelayfee", argsman.GetArg("-incrementalrelayfee", ""))};
[ # # ][ # # ]
[ # # ][ # # ]
55 : : }
56 : 0 : }
57 : :
58 [ + - ][ + - ]: 1 : if (argsman.IsArgSet("-minrelaytxfee")) {
[ - + ]
59 [ # # ][ # # ]: 0 : if (std::optional<CAmount> min_relay_feerate = ParseMoney(argsman.GetArg("-minrelaytxfee", ""))) {
[ # # ][ # # ]
[ # # ]
60 : : // High fee check is done afterward in CWallet::Create()
61 : 0 : mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()};
62 : 0 : } else {
63 [ # # ][ # # ]: 0 : return util::Error{AmountErrMsg("minrelaytxfee", argsman.GetArg("-minrelaytxfee", ""))};
[ # # ][ # # ]
[ # # ][ # # ]
64 : : }
65 [ + - ]: 1 : } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) {
66 : : // Allow only setting incremental fee to control both
67 : 0 : mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate;
68 [ # # ][ # # ]: 0 : LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n", mempool_opts.min_relay_feerate.ToString());
[ # # ][ # # ]
69 : 0 : }
70 : :
71 : : // Feerate used to define dust. Shouldn't be changed lightly as old
72 : : // implementations may inadvertently create non-standard transactions
73 [ + - ][ + - ]: 1 : if (argsman.IsArgSet("-dustrelayfee")) {
[ + - ]
74 [ # # ][ # # ]: 0 : if (std::optional<CAmount> parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""))) {
[ # # ][ # # ]
[ # # ]
75 : 0 : mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()};
76 : 0 : } else {
77 [ # # ][ # # ]: 0 : return util::Error{AmountErrMsg("dustrelayfee", argsman.GetArg("-dustrelayfee", ""))};
[ # # ][ # # ]
[ # # ][ # # ]
78 : : }
79 : 0 : }
80 : :
81 [ + - ][ + - ]: 1 : mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
82 : :
83 [ + - ][ + - ]: 1 : if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) {
[ + - ]
84 [ + - ][ + - ]: 1 : mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY);
85 : 1 : } else {
86 : 0 : mempool_opts.max_datacarrier_bytes = std::nullopt;
87 : : }
88 : :
89 [ + - ][ + - ]: 1 : mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", DEFAULT_ACCEPT_NON_STD_TXN);
90 [ - + ][ # # ]: 1 : if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
91 [ # # ][ # # ]: 0 : return util::Error{strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.GetChainTypeString())};
[ # # ][ # # ]
[ # # ]
92 : : }
93 : :
94 [ + - ][ + - ]: 1 : mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);
95 : :
96 : 1 : ApplyArgsManOptions(argsman, mempool_opts.limits);
97 : :
98 : 1 : return {};
99 : 1 : }
|