Skip to content

Commit e4e201d

Browse files
author
MacroFake
committed
Merge bitcoin#25290: [kernel 3a/n] Decouple CTxMemPool from ArgsManager
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: - 56eb479 "pool: Add and use MemPoolOptions, ApplyArgsManOptions" - a1e08b7 "mempool: Pass in -maxmempool instead of referencing gArgs" - 6f4bf3e "mempool: Pass in -mempoolexpiry instead of referencing gArgs" - 5958a7f "mempool: Introduce (still-unused) MemPoolLimits" Reviewers: Help needed in the following commits (see commit messages): - a1e08b7 "mempool: Pass in -maxmempool instead of referencing gArgs" - 0695081 "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
2 parents 72d6469 + d1684be commit e4e201d

31 files changed

+397
-117
lines changed

src/Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,14 @@ BITCOIN_CORE_H = \
173173
kernel/checks.h \
174174
kernel/coinstats.h \
175175
kernel/context.h \
176+
kernel/mempool_limits.h \
177+
kernel/mempool_options.h \
176178
key.h \
177179
key_io.h \
178180
logging.h \
179181
logging/timer.h \
180182
mapport.h \
183+
mempool_args.h \
181184
memusage.h \
182185
merkleblock.h \
183186
net.h \
@@ -203,6 +206,7 @@ BITCOIN_CORE_H = \
203206
outputtype.h \
204207
policy/feerate.h \
205208
policy/fees.h \
209+
policy/fees_args.h \
206210
policy/packages.h \
207211
policy/policy.h \
208212
policy/rbf.h \
@@ -361,6 +365,7 @@ libbitcoin_node_a_SOURCES = \
361365
kernel/coinstats.cpp \
362366
kernel/context.cpp \
363367
mapport.cpp \
368+
mempool_args.cpp \
364369
net.cpp \
365370
netgroup.cpp \
366371
net_processing.cpp \
@@ -377,6 +382,7 @@ libbitcoin_node_a_SOURCES = \
377382
node/interface_ui.cpp \
378383
noui.cpp \
379384
policy/fees.cpp \
385+
policy/fees_args.cpp \
380386
policy/packages.cpp \
381387
policy/rbf.cpp \
382388
policy/settings.cpp \

src/init.cpp

+23-15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <interfaces/init.h>
3131
#include <interfaces/node.h>
3232
#include <mapport.h>
33+
#include <mempool_args.h>
3334
#include <net.h>
3435
#include <net_permissions.h>
3536
#include <net_processing.h>
@@ -39,10 +40,11 @@
3940
#include <node/caches.h>
4041
#include <node/chainstate.h>
4142
#include <node/context.h>
42-
#include <node/miner.h>
4343
#include <node/interface_ui.h>
44+
#include <node/miner.h>
4445
#include <policy/feerate.h>
4546
#include <policy/fees.h>
47+
#include <policy/fees_args.h>
4648
#include <policy/policy.h>
4749
#include <policy/settings.h>
4850
#include <protocol.h>
@@ -62,6 +64,7 @@
6264
#include <txorphanage.h>
6365
#include <util/asmap.h>
6466
#include <util/check.h>
67+
#include <util/designator.h>
6568
#include <util/moneystr.h>
6669
#include <util/strencodings.h>
6770
#include <util/string.h>
@@ -413,9 +416,9 @@ void SetupServerArgs(ArgsManager& argsman)
413416
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);
414417
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);
415418
argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
416-
argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
419+
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);
417420
argsman.AddArg("-maxorphantx=<n>", strprintf("Keep at most <n> unconnectable transactions in memory (default: %u)", DEFAULT_MAX_ORPHAN_TRANSACTIONS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
418-
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);
421+
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);
419422
argsman.AddArg("-minimumchainwork=<hex>", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, signet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), signetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
420423
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)",
421424
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -536,9 +539,9 @@ void SetupServerArgs(ArgsManager& argsman)
536539
argsman.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
537540
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);
538541
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);
539-
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);
542+
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);
540543
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);
541-
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);
544+
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);
542545
argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
543546
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
544547
argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
@@ -928,11 +931,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
928931
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex());
929932
}
930933

931-
// mempool limits
932-
int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
933-
int64_t nMempoolSizeMin = args.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
934-
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
935-
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
936934
// incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
937935
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
938936
if (args.IsArgSet("-incrementalrelayfee")) {
@@ -1294,7 +1292,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12941292
assert(!node.fee_estimator);
12951293
// Don't initialize fee estimation with old data if we don't relay transactions,
12961294
// as they would never get updated.
1297-
if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
1295+
if (!ignores_incoming_txs) node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(args));
12981296

12991297
// sanitize comments per BIP-0014, format user agent and check total size
13001298
std::vector<std::string> uacomments;
@@ -1411,7 +1409,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14111409
// cache size calculations
14121410
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
14131411

1414-
int64_t nMempoolSizeMax = args.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
14151412
LogPrintf("Cache configuration:\n");
14161413
LogPrintf("* Using %.1f MiB for block index database\n", cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
14171414
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
@@ -1422,14 +1419,25 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14221419
cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
14231420
}
14241421
LogPrintf("* Using %.1f MiB for chain state database\n", cache_sizes.coins_db * (1.0 / 1024 / 1024));
1425-
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));
14261422

14271423
assert(!node.mempool);
14281424
assert(!node.chainman);
1429-
const int mempool_check_ratio = std::clamp<int>(args.GetIntArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0, 1000000);
1425+
1426+
CTxMemPool::Options mempool_opts{
1427+
Desig(estimator) node.fee_estimator.get(),
1428+
Desig(check_ratio) chainparams.DefaultConsistencyChecks() ? 1 : 0,
1429+
};
1430+
ApplyArgsManOptions(args, mempool_opts);
1431+
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
1432+
1433+
int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;
1434+
if (mempool_opts.max_size_bytes < 0 || mempool_opts.max_size_bytes < descendant_limit_bytes) {
1435+
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0)));
1436+
}
1437+
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));
14301438

14311439
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
1432-
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
1440+
node.mempool = std::make_unique<CTxMemPool>(mempool_opts);
14331441

14341442
const ChainstateManager::Options chainman_opts{
14351443
chainparams,

src/kernel/mempool_limits.h

+30
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

+38
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

+37
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

+22
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/net_processing.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4604,7 +4604,7 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
46044604
// transactions to us, regardless of feefilter state.
46054605
if (pto.IsBlockOnlyConn()) return;
46064606

4607-
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
4607+
CAmount currentFilter = m_mempool.GetMinFee().GetFeePerK();
46084608
static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
46094609

46104610
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) {

src/node/interfaces.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -653,24 +653,25 @@ class ChainImpl : public Chain
653653
}
654654
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
655655
{
656-
limit_ancestor_count = gArgs.GetIntArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
657-
limit_descendant_count = gArgs.GetIntArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
656+
const CTxMemPool::Limits default_limits{};
657+
658+
const CTxMemPool::Limits& limits{m_node.mempool ? m_node.mempool->m_limits : default_limits};
659+
660+
limit_ancestor_count = limits.ancestor_count;
661+
limit_descendant_count = limits.descendant_count;
658662
}
659663
bool checkChainLimits(const CTransactionRef& tx) override
660664
{
661665
if (!m_node.mempool) return true;
662666
LockPoints lp;
663667
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
664668
CTxMemPool::setEntries ancestors;
665-
auto limit_ancestor_count = gArgs.GetIntArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
666-
auto limit_ancestor_size = gArgs.GetIntArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * 1000;
667-
auto limit_descendant_count = gArgs.GetIntArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
668-
auto limit_descendant_size = gArgs.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
669+
const CTxMemPool::Limits& limits{m_node.mempool->m_limits};
669670
std::string unused_error_string;
670671
LOCK(m_node.mempool->cs);
671672
return m_node.mempool->CalculateMemPoolAncestors(
672-
entry, ancestors, limit_ancestor_count, limit_ancestor_size,
673-
limit_descendant_count, limit_descendant_size, unused_error_string);
673+
entry, ancestors, limits.ancestor_count, limits.ancestor_size_vbytes,
674+
limits.descendant_count, limits.descendant_size_vbytes, unused_error_string);
674675
}
675676
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
676677
{
@@ -685,7 +686,7 @@ class ChainImpl : public Chain
685686
CFeeRate mempoolMinFee() override
686687
{
687688
if (!m_node.mempool) return {};
688-
return m_node.mempool->GetMinFee(gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
689+
return m_node.mempool->GetMinFee();
689690
}
690691
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
691692
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }

0 commit comments

Comments
 (0)