From fac812ca835e0d843aba1d4db0e49d183018a29e Mon Sep 17 00:00:00 2001 From: MacroFake Date: Tue, 2 Aug 2022 15:30:00 +0200 Subject: scripted-diff: Move mempool_args to src/node It is part of the node library. Also, it won't be moved to the kernel lib, as it will be pruned of ArgsManager. -BEGIN VERIFY SCRIPT- # Move module git mv src/mempool_args.cpp src/node/ git mv src/mempool_args.h src/node/ # Replacements sed -i 's:mempool_args\.h:node/mempool_args.h:g' $(git grep -l mempool_args) sed -i 's:mempool_args\.cpp:node/mempool_args.cpp:g' $(git grep -l mempool_args) sed -i 's:MEMPOOL_ARGS_H:NODE_MEMPOOL_ARGS_H:g' $(git grep -l MEMPOOL_ARGS_H) -END VERIFY SCRIPT- --- ci/test/06_script_b.sh | 2 +- src/Makefile.am | 4 +- src/init.cpp | 2 +- src/mempool_args.cpp | 99 ------------------------------- src/mempool_args.h | 27 --------- src/node/mempool_args.cpp | 99 +++++++++++++++++++++++++++++++ src/node/mempool_args.h | 27 +++++++++ src/test/fuzz/rbf.cpp | 2 +- src/test/fuzz/tx_pool.cpp | 2 +- src/test/fuzz/validation_load_mempool.cpp | 2 +- src/test/util/setup_common.cpp | 2 +- 11 files changed, 134 insertions(+), 134 deletions(-) delete mode 100644 src/mempool_args.cpp delete mode 100644 src/mempool_args.h create mode 100644 src/node/mempool_args.cpp create mode 100644 src/node/mempool_args.h diff --git a/ci/test/06_script_b.sh b/ci/test/06_script_b.sh index 978830b7e2..0d8d860f1b 100755 --- a/ci/test/06_script_b.sh +++ b/ci/test/06_script_b.sh @@ -44,7 +44,7 @@ if [ "${RUN_TIDY}" = "true" ]; then " src/dbwrapper.cpp"\ " src/init"\ " src/kernel"\ - " src/mempool_args.cpp"\ + " src/node/mempool_args.cpp"\ " src/node/chainstate.cpp"\ " src/policy/feerate.cpp"\ " src/policy/packages.cpp"\ diff --git a/src/Makefile.am b/src/Makefile.am index 23bc180095..1da6199137 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -184,7 +184,7 @@ BITCOIN_CORE_H = \ logging.h \ logging/timer.h \ mapport.h \ - mempool_args.h \ + node/mempool_args.h \ memusage.h \ merkleblock.h \ net.h \ @@ -372,7 +372,7 @@ libbitcoin_node_a_SOURCES = \ kernel/context.cpp \ kernel/mempool_persist.cpp \ mapport.cpp \ - mempool_args.cpp \ + node/mempool_args.cpp \ net.cpp \ netgroup.cpp \ net_processing.cpp \ diff --git a/src/init.cpp b/src/init.cpp index 056aadb675..c19d27453b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mempool_args.cpp b/src/mempool_args.cpp deleted file mode 100644 index f26f3729fd..0000000000 --- a/src/mempool_args.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2022 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using kernel::MemPoolLimits; -using kernel::MemPoolOptions; - -namespace { -void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits) -{ - mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count); - - if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000; - - mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count); - - if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000; -} -} - -std::optional ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts) -{ - mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio); - - if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000; - - if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours}; - - // incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool - // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting. - if (argsman.IsArgSet("-incrementalrelayfee")) { - if (std::optional inc_relay_fee = ParseMoney(argsman.GetArg("-incrementalrelayfee", ""))) { - mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()}; - } else { - return AmountErrMsg("incrementalrelayfee", argsman.GetArg("-incrementalrelayfee", "")); - } - } - - if (argsman.IsArgSet("-minrelaytxfee")) { - if (std::optional min_relay_feerate = ParseMoney(argsman.GetArg("-minrelaytxfee", ""))) { - // High fee check is done afterward in CWallet::Create() - mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()}; - } else { - return AmountErrMsg("minrelaytxfee", argsman.GetArg("-minrelaytxfee", "")); - } - } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) { - // Allow only setting incremental fee to control both - mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate; - LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n", mempool_opts.min_relay_feerate.ToString()); - } - - // Feerate used to define dust. Shouldn't be changed lightly as old - // implementations may inadvertently create non-standard transactions - if (argsman.IsArgSet("-dustrelayfee")) { - if (std::optional parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""))) { - mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()}; - } else { - return AmountErrMsg("dustrelayfee", argsman.GetArg("-dustrelayfee", "")); - } - } - - mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); - - if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) { - mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY); - } else { - mempool_opts.max_datacarrier_bytes = std::nullopt; - } - - mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); - if (!chainparams.IsTestChain() && !mempool_opts.require_standard) { - return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()); - } - - mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf); - - ApplyArgsManOptions(argsman, mempool_opts.limits); - - return std::nullopt; -} diff --git a/src/mempool_args.h b/src/mempool_args.h deleted file mode 100644 index 72d202cca2..0000000000 --- a/src/mempool_args.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2022 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_MEMPOOL_ARGS_H -#define BITCOIN_MEMPOOL_ARGS_H - -#include - -class ArgsManager; -class CChainParams; -struct bilingual_str; -namespace kernel { -struct MemPoolOptions; -}; - -/** - * Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts. - * Returns an error if one was encountered. - * - * @param[in] argsman The ArgsManager in which to check set options. - * @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman. - */ -[[nodiscard]] std::optional ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, kernel::MemPoolOptions& mempool_opts); - - -#endif // BITCOIN_MEMPOOL_ARGS_H diff --git a/src/node/mempool_args.cpp b/src/node/mempool_args.cpp new file mode 100644 index 0000000000..60993f1d8d --- /dev/null +++ b/src/node/mempool_args.cpp @@ -0,0 +1,99 @@ +// Copyright (c) 2022 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using kernel::MemPoolLimits; +using kernel::MemPoolOptions; + +namespace { +void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits) +{ + mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count); + + if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000; + + mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count); + + if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000; +} +} + +std::optional ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts) +{ + mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio); + + if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000; + + if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours}; + + // incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool + // and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting. + if (argsman.IsArgSet("-incrementalrelayfee")) { + if (std::optional inc_relay_fee = ParseMoney(argsman.GetArg("-incrementalrelayfee", ""))) { + mempool_opts.incremental_relay_feerate = CFeeRate{inc_relay_fee.value()}; + } else { + return AmountErrMsg("incrementalrelayfee", argsman.GetArg("-incrementalrelayfee", "")); + } + } + + if (argsman.IsArgSet("-minrelaytxfee")) { + if (std::optional min_relay_feerate = ParseMoney(argsman.GetArg("-minrelaytxfee", ""))) { + // High fee check is done afterward in CWallet::Create() + mempool_opts.min_relay_feerate = CFeeRate{min_relay_feerate.value()}; + } else { + return AmountErrMsg("minrelaytxfee", argsman.GetArg("-minrelaytxfee", "")); + } + } else if (mempool_opts.incremental_relay_feerate > mempool_opts.min_relay_feerate) { + // Allow only setting incremental fee to control both + mempool_opts.min_relay_feerate = mempool_opts.incremental_relay_feerate; + LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n", mempool_opts.min_relay_feerate.ToString()); + } + + // Feerate used to define dust. Shouldn't be changed lightly as old + // implementations may inadvertently create non-standard transactions + if (argsman.IsArgSet("-dustrelayfee")) { + if (std::optional parsed = ParseMoney(argsman.GetArg("-dustrelayfee", ""))) { + mempool_opts.dust_relay_feerate = CFeeRate{parsed.value()}; + } else { + return AmountErrMsg("dustrelayfee", argsman.GetArg("-dustrelayfee", "")); + } + } + + mempool_opts.permit_bare_multisig = argsman.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); + + if (argsman.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER)) { + mempool_opts.max_datacarrier_bytes = argsman.GetIntArg("-datacarriersize", MAX_OP_RETURN_RELAY); + } else { + mempool_opts.max_datacarrier_bytes = std::nullopt; + } + + mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); + if (!chainparams.IsTestChain() && !mempool_opts.require_standard) { + return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()); + } + + mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf); + + ApplyArgsManOptions(argsman, mempool_opts.limits); + + return std::nullopt; +} diff --git a/src/node/mempool_args.h b/src/node/mempool_args.h new file mode 100644 index 0000000000..52d8b4f265 --- /dev/null +++ b/src/node/mempool_args.h @@ -0,0 +1,27 @@ +// Copyright (c) 2022 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_NODE_MEMPOOL_ARGS_H +#define BITCOIN_NODE_MEMPOOL_ARGS_H + +#include + +class ArgsManager; +class CChainParams; +struct bilingual_str; +namespace kernel { +struct MemPoolOptions; +}; + +/** + * Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts. + * Returns an error if one was encountered. + * + * @param[in] argsman The ArgsManager in which to check set options. + * @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman. + */ +[[nodiscard]] std::optional ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, kernel::MemPoolOptions& mempool_opts); + + +#endif // BITCOIN_NODE_MEMPOOL_ARGS_H diff --git a/src/test/fuzz/rbf.cpp b/src/test/fuzz/rbf.cpp index 4801635791..1a06ae886e 100644 --- a/src/test/fuzz/rbf.cpp +++ b/src/test/fuzz/rbf.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include #include diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index b1db1a425f..ed372d5d1f 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -3,7 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include +#include #include #include #include diff --git a/src/test/fuzz/validation_load_mempool.cpp b/src/test/fuzz/validation_load_mempool.cpp index 90c1a71d9f..8241dff189 100644 --- a/src/test/fuzz/validation_load_mempool.cpp +++ b/src/test/fuzz/validation_load_mempool.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index f5076c043b..76ab6bfa04 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3