/Users/eugenesiegel/btc/bitcoin/src/node/mempool_args.cpp
| Line | Count | Source (jump to first uncovered line) | 
| 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 <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 |  |  | 
| 24 |  | using common::AmountErrMsg; | 
| 25 |  | using kernel::MemPoolLimits; | 
| 26 |  | using kernel::MemPoolOptions; | 
| 27 |  |  | 
| 28 |  | //! Maximum mempool size on 32-bit systems. | 
| 29 |  | static constexpr int MAX_32BIT_MEMPOOL_MB{500}; | 
| 30 |  |  | 
| 31 |  | namespace { | 
| 32 |  | void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits) | 
| 33 | 102k | { | 
| 34 | 102k |     mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count); | 
| 35 |  |  | 
| 36 | 102k |     if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'0000; | 
| 37 |  |  | 
| 38 | 102k |     mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count); | 
| 39 |  |  | 
| 40 | 102k |     if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'0000; | 
| 41 | 102k | } | 
| 42 |  | } | 
| 43 |  |  | 
| 44 |  | util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts) | 
| 45 | 102k | { | 
| 46 | 102k |     mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio); | 
| 47 |  |  | 
| 48 | 102k |     if (auto mb = argsman.GetIntArg("-maxmempool")) { | 
| 49 | 0 |         constexpr bool is_32bit{sizeof(void*) == 4}; | 
| 50 | 0 |         if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) { | 
| 51 | 0 |             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))};| Line | Count | Source |  | 1172 | 0 | #define strprintf tfm::format | 
 | 
| 52 | 0 |         } | 
| 53 | 0 |         mempool_opts.max_size_bytes = *mb * 1'000'000; | 
| 54 | 0 |     } | 
| 55 |  |  | 
| 56 | 102k |     if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours}0; | 
| 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 | 102k |     if (const auto arg{argsman.GetArg("-incrementalrelayfee")}) { | 
| 61 | 0 |         if (std::optional<CAmount> inc_relay_fee = ParseMoney(*arg)) { | 
| 62 | 0 |             mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()}; | 
| 63 | 0 |         } else { | 
| 64 | 0 |             return util::Error{AmountErrMsg("incrementalrelayfee", *arg)}; | 
| 65 | 0 |         } | 
| 66 | 0 |     } | 
| 67 |  |  | 
| 68 | 102k |     static_assert(DEFAULT_MIN_RELAY_TX_FEE == DEFAULT_INCREMENTAL_RELAY_FEE); | 
| 69 | 102k |     if (const auto arg{argsman.GetArg("-minrelaytxfee")}) { | 
| 70 | 0 |         if (std::optional<CAmount> min_relay_feerate = ParseMoney(*arg)) { | 
| 71 |  |             // High fee check is done afterward in CWallet::Create() | 
| 72 | 0 |             mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()}; | 
| 73 | 0 |         } else { | 
| 74 | 0 |             return util::Error{AmountErrMsg("minrelaytxfee", *arg)}; | 
| 75 | 0 |         } | 
| 76 | 102k |     } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) { | 
| 77 |  |         // Allow only setting incremental fee to control both | 
| 78 | 0 |         mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate; | 
| 79 | 0 |         LogInfo("Increasing minrelaytxfee to %s to match incrementalrelayfee", mempool_opts.min_relay_feerate.ToString());| Line | Count | Source |  | 356 | 0 | #define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/true, __VA_ARGS__) | Line | Count | Source |  | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) | 
 | 
 | 
| 80 | 0 |     } | 
| 81 |  |  | 
| 82 |  |     // Feerate used to define dust.  Shouldn't be changed lightly as old | 
| 83 |  |     // implementations may inadvertently create non-standard transactions | 
| 84 | 102k |     if (const auto arg{argsman.GetArg("-dustrelayfee")}) { | 
| 85 | 0 |         if (std::optional<CAmount> parsed = ParseMoney(*arg)) { | 
| 86 | 0 |             mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()}; | 
| 87 | 0 |         } else { | 
| 88 | 0 |             return util::Error{AmountErrMsg("dustrelayfee", *arg)}; | 
| 89 | 0 |         } | 
| 90 | 0 |     } | 
| 91 |  |  | 
| 92 | 102k |     mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | 
| 93 |  |  | 
| 94 | 102k |     if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) { | 
| 95 | 102k |         mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY); | 
| 96 | 102k |     } else { | 
| 97 | 0 |         mempool_opts.max_datacarrier_bytes = std::nullopt; | 
| 98 | 0 |     } | 
| 99 |  |  | 
| 100 | 102k |     mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", DEFAULT_ACCEPT_NON_STD_TXN); | 
| 101 | 102k |     if (!chainparams.IsTestChain() && !mempool_opts.require_standard0) { | 
| 102 | 0 |         return util::Error{Untranslated(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.GetChainTypeString()))};| Line | Count | Source |  | 1172 | 0 | #define strprintf tfm::format | 
 | 
| 103 | 0 |     } | 
| 104 |  |  | 
| 105 | 102k |     mempool_opts.persist_v1_dat = argsman.GetBoolArg("-persistmempoolv1", mempool_opts.persist_v1_dat); | 
| 106 |  |  | 
| 107 | 102k |     ApplyArgsManOptions(argsman, mempool_opts.limits); | 
| 108 |  |  | 
| 109 | 102k |     return {}; | 
| 110 | 102k | } |