Skip to content

Commit 6d74b31

Browse files
knstMacroFake
andcommitted
Merge bitcoin#25290: [kernel 3a/n] Decouple CTxMemPool from ArgsManager
BACKPORT NOTE: includes changes from Merge bitcoin#25223: [kernel 2e/n] miner: Make `mempool` optional, stop constructing temporary empty mempools includes changes from Merge bitcoin#26286: test: Remove unused txmempool include from tests d1684be fees: Pass in a filepath instead of referencing gArgs (Carl Dong) 9a3d825 init: Remove redundant -*mempool*, -limit* queries (Carl Dong) 6c5c60c mempool: Use m_limit for UpdateTransactionsFromBlock (Carl Dong) 9e93b10 node/ifaces: Use existing MemPoolLimits (Carl Dong) 38af2bc mempoolaccept: Use limits from mempool in constructor (Carl Dong) 9333427 mempool: Introduce (still-unused) MemPoolLimits (Carl Dong) 716bb5f scripted-diff: Rename anc/desc size limit vars to indicate SI unit (Carl Dong) 1ecc773 scripted-diff: Rename DEFAULT_MEMPOOL_EXPIRY to indicate time unit (Carl Dong) aa9141c mempool: Pass in -mempoolexpiry instead of referencing gArgs (Carl Dong) 51c7a41 init: Only determine maxmempool once (Carl Dong) 386c947 mempool: Make GetMinFee() with custom size protected (Carl Dong) 82f00de mempool: Pass in -maxmempool instead of referencing gArgs (Carl Dong) f1941e8 pool: Add and use MemPoolOptions, ApplyArgsManOptions (Carl Dong) 0199bd3 fuzz/rbf: Add missing TestingSetup (Carl Dong) ccbaf54 scripted-diff: Rename DEFAULT_MAX_MEMPOOL_SIZE to indicate SI unit (Carl Dong) fc02f77 ArgsMan: Add Get*Arg functions returning optional (Carl Dong) Pull request description: This is part of the `libbitcoinkernel` project: bitcoin#24303, https://github.com/bitcoin/bitcoin/projects/18 ----- As mentioned in the Stage 1 Step 2 description of [the `libbitcoinkernel` project](bitcoin#24303), `ArgsManager` will not be part of `libbitcoinkernel`. Therefore, it is important that we remove any dependence on `ArgsManager` by code that will be part of `libbitcoinkernel`. This is the first in a series of PRs aiming to achieve this. This PR removes `CTxMemPool+MempoolAccept`'s dependency on `ArgsManager` by introducing a `CTxMemPool::Options` struct, which is used to specify `CTxMemPool`'s various options at construction time. These options are: - `-maxmempool` -> `CTxMemPool::Options::max_size` - `-mempoolexpiry` -> `CTxMemPool::Options::expiry` - `-limitancestorcount` -> `CTxMemPool::Options::limits::ancestor_count` - `-limitancestorsize` -> `CTxMemPool::Options::limits::ancestor_size` - `-limitdescendantcount` -> `CTxMemPool::Options::limits::descendant_count` - `-limitdescendantsize` -> `CTxMemPool::Options::limits::descendant_size` More context can be gleaned from the commit messages. The important commits are: - 56eb479ded8bfb2ef635bb6f3b484f9d5952c70d "pool: Add and use MemPoolOptions, ApplyArgsManOptions" - a1e08b70f3068f4e8def1c630d8f50cd54da7832 "mempool: Pass in -maxmempool instead of referencing gArgs" - 6f4bf3ede5812b374828f08fc728ceded2f10024 "mempool: Pass in -mempoolexpiry instead of referencing gArgs" - 5958a7fe4806599fc620ee8c1a881ca10fa2dd16 "mempool: Introduce (still-unused) MemPoolLimits" Reviewers: Help needed in the following commits (see commit messages): - a1e08b70f3068f4e8def1c630d8f50cd54da7832 "mempool: Pass in -maxmempool instead of referencing gArgs" - 0695081a797e9a5d7787b78b0f8289dafcc6bff7 "node/ifaces: Use existing MemPoolLimits" Note to Reviewers: There are perhaps an infinite number of ways to architect `CTxMemPool::Options`, the current one tries to keep it simple, usable, and flexible. I hope we don't spend too much time arguing over the design here since that's not the point. In the case that you're 100% certain that a different design is strictly better than this one in every regard, please show us a fully-implemented branch. ----- TODO: - [x] Use the more ergonomic `CTxMemPool::Options` where appropriate - [x] Doxygen comments for `ApplyArgsManOptions`, `MemPoolOptions` ----- Questions for Reviewers: 1. Should we use `std::chrono::seconds` for `CTxMemPool::Options::expiry` and `CTxMemPool::m_expiry` instead of an `int64_t`? Something else? (`std::chrono::hours`?) 2. Should I merge `CTxMemPool::Limits` inside `CTxMemPool::Options`? ACKs for top commit: MarcoFalke: ACK d1684be 🍜 ryanofsky: Code review ACK d1684be. Just minor cleanups since last review, mostly switching to brace initialization Tree-SHA512: 2c138e52d69f61c263f1c3648f01c801338a8f576762c815f478ef5148b8b2f51e91ded5c1be915e678c0b14f6cfba894b82afec58d999d39a7bb7c914736e0b Co-authored-by: MacroFake <falke.marco@gmail.com>
1 parent aa365c3 commit 6d74b31

33 files changed

Lines changed: 381 additions & 128 deletions

src/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ BITCOIN_CORE_H = \
284284
kernel/checks.h \
285285
kernel/coinstats.h \
286286
kernel/context.h \
287+
kernel/mempool_limits.h \
288+
kernel/mempool_options.h \
287289
key.h \
288290
key_io.h \
289291
limitedmap.h \
@@ -315,6 +317,7 @@ BITCOIN_CORE_H = \
315317
masternode/payments.h \
316318
masternode/sync.h \
317319
masternode/utils.h \
320+
mempool_args.h \
318321
memusage.h \
319322
merkleblock.h \
320323
messagesigner.h \
@@ -347,6 +350,7 @@ BITCOIN_CORE_H = \
347350
outputtype.h \
348351
policy/feerate.h \
349352
policy/fees.h \
353+
policy/fees_args.h \
350354
policy/packages.h \
351355
policy/policy.h \
352356
policy/settings.h \
@@ -583,6 +587,7 @@ libbitcoin_node_a_SOURCES = \
583587
masternode/payments.cpp \
584588
masternode/sync.cpp \
585589
masternode/utils.cpp \
590+
mempool_args.cpp \
586591
net.cpp \
587592
net_processing.cpp \
588593
netfulfilledman.cpp \
@@ -604,6 +609,7 @@ libbitcoin_node_a_SOURCES = \
604609
node/txreconciliation.cpp \
605610
noui.cpp \
606611
policy/fees.cpp \
612+
policy/fees_args.cpp \
607613
policy/packages.cpp \
608614
policy/policy.cpp \
609615
policy/settings.cpp \

src/init.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <interfaces/wallet.h>
4141
#include <kernel/coinstats.h>
4242
#include <mapport.h>
43-
#include <node/miner.h>
43+
#include <mempool_args.h>
4444
#include <net.h>
4545
#include <net_permissions.h>
4646
#include <net_processing.h>
@@ -51,10 +51,12 @@
5151
#include <node/chainstate.h>
5252
#include <node/context.h>
5353
#include <node/interface_ui.h>
54+
#include <node/miner.h>
5455
#include <node/sync_manager.h>
5556
#include <node/txreconciliation.h>
5657
#include <policy/feerate.h>
5758
#include <policy/fees.h>
59+
#include <policy/fees_args.h>
5860
#include <policy/policy.h>
5961
#include <policy/settings.h>
6062
#include <rpc/blockchain.h>
@@ -583,10 +585,10 @@ void SetupServerArgs(ArgsManager& argsman)
583585
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
584586
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
585587
argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
586-
argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
588+
argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE_MB), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
587589
argsman.AddArg("-maxorphantxsize=<n>", strprintf("Maximum total size of all orphan transactions in megabytes (default: %u)", DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
588590
argsman.AddArg("-maxrecsigsage=<n>", strprintf("Number of seconds to keep LLMQ recovery sigs (default: %u)", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
589-
argsman.AddArg("-mempoolexpiry=<n>", strprintf("Do not keep transactions in the mempool longer than <n> hours (default: %u)", DEFAULT_MEMPOOL_EXPIRY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
591+
argsman.AddArg("-mempoolexpiry=<n>", strprintf("Do not keep transactions in the mempool longer than <n> hours (default: %u)", DEFAULT_MEMPOOL_EXPIRY_HOURS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
590592
argsman.AddArg("-minimumchainwork=<hex>", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, devnet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), devnetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
591593
argsman.AddArg("-par=<n>", strprintf("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)",
592594
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -774,9 +776,9 @@ void SetupServerArgs(ArgsManager& argsman)
774776
argsman.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
775777
argsman.AddArg("-forceevodbrepair", "Force evodb masternode list diff verification and repair on startup, even if already repaired (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
776778
argsman.AddArg("-limitancestorcount=<n>", strprintf("Do not accept transactions if number of in-mempool ancestors is <n> or more (default: %u)", DEFAULT_ANCESTOR_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
777-
argsman.AddArg("-limitancestorsize=<n>", strprintf("Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u)", DEFAULT_ANCESTOR_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
779+
argsman.AddArg("-limitancestorsize=<n>", strprintf("Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u)", DEFAULT_ANCESTOR_SIZE_LIMIT_KVB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
778780
argsman.AddArg("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
779-
argsman.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
781+
argsman.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT_KVB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
780782
argsman.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
781783
argsman.AddArg("-stopatheight", strprintf("Stop running after reaching the given height in the main chain (default: %u)", DEFAULT_STOPATHEIGHT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
782784
argsman.AddArg("-watchquorums=<n>", strprintf("Watch and validate quorum communication (default: %u)", llmq::DEFAULT_WATCH_QUORUMS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
@@ -886,7 +888,6 @@ static void StartupNotify(const ArgsManager& args)
886888
static void PeriodicStats(NodeContext& node)
887889
{
888890
assert(::g_stats_client->active());
889-
const ArgsManager& args = *Assert(node.args);
890891
ChainstateManager& chainman = *Assert(node.chainman);
891892
const CTxMemPool& mempool = *Assert(node.mempool);
892893
const llmq::CInstantSendManager& isman = *Assert(node.llmq_ctx->isman);
@@ -940,7 +941,7 @@ static void PeriodicStats(NodeContext& node)
940941
::g_stats_client->gauge("transactions.mempool.totalTransactions", mempool.size(), 1.0f);
941942
::g_stats_client->gauge("transactions.mempool.totalTxBytes", (int64_t) mempool.GetTotalTxSize(), 1.0f);
942943
::g_stats_client->gauge("transactions.mempool.memoryUsageBytes", (int64_t) mempool.DynamicMemoryUsage(), 1.0f);
943-
::g_stats_client->gauge("transactions.mempool.minFeePerKb", mempool.GetMinFee(args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(), 1.0f);
944+
::g_stats_client->gauge("transactions.mempool.minFeePerKb", mempool.GetMinFee().GetFeePerK(), 1.0f);
944945
}
945946
::g_stats_client->gauge("transactions.mempool.lockedTransactions", isman.GetInstantSendLockCount(), 1.0f);
946947
}
@@ -1302,11 +1303,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
13021303
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex());
13031304
}
13041305

1305-
// mempool limits
1306-
int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
1307-
int64_t nMempoolSizeMin = args.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
1308-
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
1309-
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
13101306
// incremental relay fee sets the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
13111307
if (args.IsArgSet("-incrementalrelayfee")) {
13121308
if (std::optional<CAmount> inc_relay_fee = ParseMoney(args.GetArg("-incrementalrelayfee", ""))) {
@@ -1710,7 +1706,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17101706
assert(!node.fee_estimator);
17111707
// Don't initialize fee estimation with old data if we don't relay transactions,
17121708
// as they would never get updated.
1713-
if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
1709+
if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(args));
17141710

17151711
assert(!node.mn_metaman);
17161712
node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
@@ -1970,7 +1966,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19701966
// cache size calculations
19711967
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
19721968

1973-
int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
19741969
LogPrintf("Cache configuration:\n");
19751970
LogPrintf("* Using %.1f MiB for block index database\n", cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
19761971
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
@@ -1990,15 +1985,26 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19901985
cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
19911986
}
19921987
LogPrintf("* Using %.1f MiB for chain state database\n", cache_sizes.coins_db * (1.0 / 1024 / 1024));
1993-
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", cache_sizes.coins * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
19941988

19951989
assert(!node.mempool);
19961990
assert(!node.chainman);
19971991
assert(!node.mn_sync);
1998-
const int mempool_check_ratio = std::clamp<int>(args.GetIntArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0, 1000000);
1992+
1993+
CTxMemPool::Options mempool_opts{
1994+
.estimator = node.fee_estimator.get(),
1995+
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0,
1996+
};
1997+
ApplyArgsManOptions(args, mempool_opts);
1998+
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
1999+
2000+
int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;
2001+
if (mempool_opts.max_size_bytes < 0 || mempool_opts.max_size_bytes < descendant_limit_bytes) {
2002+
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0)));
2003+
}
2004+
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", cache_sizes.coins * (1.0 / 1024 / 1024), mempool_opts.max_size_bytes * (1.0 / 1024 / 1024));
19992005

20002006
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
2001-
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
2007+
node.mempool = std::make_unique<CTxMemPool>(mempool_opts);
20022008

20032009
const ChainstateManager::Options chainman_opts{
20042010
chainparams,

src/kernel/mempool_limits.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
#ifndef BITCOIN_KERNEL_MEMPOOL_LIMITS_H
5+
#define BITCOIN_KERNEL_MEMPOOL_LIMITS_H
6+
7+
#include <policy/policy.h>
8+
9+
#include <cstdint>
10+
11+
namespace kernel {
12+
/**
13+
* Options struct containing limit options for a CTxMemPool. Default constructor
14+
* populates the struct with sane default values which can be modified.
15+
*
16+
* Most of the time, this struct should be referenced as CTxMemPool::Limits.
17+
*/
18+
struct MemPoolLimits {
19+
//! The maximum allowed number of transactions in a package including the entry and its ancestors.
20+
int64_t ancestor_count{DEFAULT_ANCESTOR_LIMIT};
21+
//! The maximum allowed size in virtual bytes of an entry and its ancestors within a package.
22+
int64_t ancestor_size_vbytes{DEFAULT_ANCESTOR_SIZE_LIMIT_KVB * 1'000};
23+
//! The maximum allowed number of transactions in a package including the entry and its descendants.
24+
int64_t descendant_count{DEFAULT_DESCENDANT_LIMIT};
25+
//! The maximum allowed size in virtual bytes of an entry and its descendants within a package.
26+
int64_t descendant_size_vbytes{DEFAULT_DESCENDANT_SIZE_LIMIT_KVB * 1'000};
27+
};
28+
} // namespace kernel
29+
30+
#endif // BITCOIN_KERNEL_MEMPOOL_LIMITS_H

src/kernel/mempool_options.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
#ifndef BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
5+
#define BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
6+
7+
#include <kernel/mempool_limits.h>
8+
9+
#include <chrono>
10+
#include <cstdint>
11+
12+
class CBlockPolicyEstimator;
13+
14+
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
15+
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
16+
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
17+
static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336};
18+
19+
namespace kernel {
20+
/**
21+
* Options struct containing options for constructing a CTxMemPool. Default
22+
* constructor populates the struct with sane default values which can be
23+
* modified.
24+
*
25+
* Most of the time, this struct should be referenced as CTxMemPool::Options.
26+
*/
27+
struct MemPoolOptions {
28+
/* Used to estimate appropriate transaction fees. */
29+
CBlockPolicyEstimator* estimator{nullptr};
30+
/* The ratio used to determine how often sanity checks will run. */
31+
int check_ratio{0};
32+
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
33+
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY_HOURS}};
34+
MemPoolLimits limits{};
35+
};
36+
} // namespace kernel
37+
38+
#endif // BITCOIN_KERNEL_MEMPOOL_OPTIONS_H

src/mempool_args.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
7+
#include <kernel/mempool_limits.h>
8+
#include <kernel/mempool_options.h>
9+
10+
#include <util/system.h>
11+
12+
using kernel::MemPoolLimits;
13+
using kernel::MemPoolOptions;
14+
15+
namespace {
16+
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
17+
{
18+
mempool_limits.ancestor_count = argsman.GetIntArg("-limitancestorcount", mempool_limits.ancestor_count);
19+
20+
if (auto vkb = argsman.GetIntArg("-limitancestorsize")) mempool_limits.ancestor_size_vbytes = *vkb * 1'000;
21+
22+
mempool_limits.descendant_count = argsman.GetIntArg("-limitdescendantcount", mempool_limits.descendant_count);
23+
24+
if (auto vkb = argsman.GetIntArg("-limitdescendantsize")) mempool_limits.descendant_size_vbytes = *vkb * 1'000;
25+
}
26+
}
27+
28+
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opts)
29+
{
30+
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
31+
32+
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
33+
34+
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
35+
36+
ApplyArgsManOptions(argsman, mempool_opts.limits);
37+
}

src/mempool_args.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#ifndef BITCOIN_MEMPOOL_ARGS_H
6+
#define BITCOIN_MEMPOOL_ARGS_H
7+
8+
class ArgsManager;
9+
namespace kernel {
10+
struct MemPoolOptions;
11+
};
12+
13+
/**
14+
* Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts.
15+
*
16+
* @param[in] argsman The ArgsManager in which to check set options.
17+
* @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman.
18+
*/
19+
void ApplyArgsManOptions(const ArgsManager& argsman, kernel::MemPoolOptions& mempool_opts);
20+
21+
22+
#endif // BITCOIN_MEMPOOL_ARGS_H

src/node/interfaces.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ class NodeImpl : public Node
858858
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
859859
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
860860
size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
861-
size_t getMempoolMaxUsage() override { return gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; }
861+
size_t getMempoolMaxUsage() override { return gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE_MB) * 1000000; }
862862
bool getHeaderTip(int& height, int64_t& block_time) override
863863
{
864864
LOCK(::cs_main);
@@ -1376,24 +1376,25 @@ class ChainImpl : public Chain
13761376
}
13771377
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
13781378
{
1379-
limit_ancestor_count = gArgs.GetIntArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
1380-
limit_descendant_count = gArgs.GetIntArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
1379+
const CTxMemPool::Limits default_limits{};
1380+
1381+
const CTxMemPool::Limits& limits{m_node.mempool ? m_node.mempool->m_limits : default_limits};
1382+
1383+
limit_ancestor_count = limits.ancestor_count;
1384+
limit_descendant_count = limits.descendant_count;
13811385
}
13821386
bool checkChainLimits(const CTransactionRef& tx) override
13831387
{
13841388
if (!m_node.mempool) return true;
13851389
LockPoints lp;
13861390
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
13871391
CTxMemPool::setEntries ancestors;
1388-
auto limit_ancestor_count = gArgs.GetIntArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
1389-
auto limit_ancestor_size = gArgs.GetIntArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * 1000;
1390-
auto limit_descendant_count = gArgs.GetIntArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
1391-
auto limit_descendant_size = gArgs.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
1392+
const CTxMemPool::Limits& limits{m_node.mempool->m_limits};
13921393
std::string unused_error_string;
13931394
LOCK(m_node.mempool->cs);
13941395
return m_node.mempool->CalculateMemPoolAncestors(
1395-
entry, ancestors, limit_ancestor_count, limit_ancestor_size,
1396-
limit_descendant_count, limit_descendant_size, unused_error_string);
1396+
entry, ancestors, limits.ancestor_count, limits.ancestor_size_vbytes,
1397+
limits.descendant_count, limits.descendant_size_vbytes, unused_error_string);
13971398
}
13981399
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
13991400
{
@@ -1408,7 +1409,7 @@ class ChainImpl : public Chain
14081409
CFeeRate mempoolMinFee() override
14091410
{
14101411
if (!m_node.mempool) return {};
1411-
return m_node.mempool->GetMinFee(gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
1412+
return m_node.mempool->GetMinFee();
14121413
}
14131414
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
14141415
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }

0 commit comments

Comments
 (0)