Have you considered adding this logic to mempool_args.cpp::ApplyArgsManOptions()
instead, so we don’t set our mempool_opts.max_size_bytes
in two different locations? I think this has the benefit of 1) being easier to understand why options are set to the values they are and 2) avoid unexpected issues/behaviour where mempool_opts.max_size_bytes
is temporarily set to 300MB before being changed to 5MB.
The downside, as previously discussed, is including net.h
, which probably needs fixing anyway (perhaps in separate PR?).
I think I’d much prefer this approach.
0diff --git a/src/init.cpp b/src/init.cpp
1index c4b15392c..641fef81c 100644
2--- a/src/init.cpp
3+++ b/src/init.cpp
4@@ -1467,12 +1467,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
5 if (mempool_opts.max_size_bytes < 0 || mempool_opts.max_size_bytes < descendant_limit_bytes) {
6 return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0)));
7 }
8- // If we are running in blocksonly mode don't allocate the default 300MB of space for mempool
9- // unless the user specifies -maxmempool, as otherwise it will leak into dbcache allowance.
10- // Keeping the mempool enabled will still permit transaction relay for whitelisted peers
11- if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && !args.IsArgSet("-maxmempool")) {
12- mempool_opts.max_size_bytes = 5 * 1'000'000;
13- }
14 LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n",
15 cache_sizes.coins * (1.0 / 1024 / 1024),
16 mempool_opts.max_size_bytes * (1.0 / 1024 / 1024));
17diff --git a/src/node/mempool_args.cpp b/src/node/mempool_args.cpp
18index 8c929e5e0..b530ac981 100644
19--- a/src/node/mempool_args.cpp
20+++ b/src/node/mempool_args.cpp
21@@ -10,6 +10,7 @@
22 #include <chainparams.h>
23 #include <consensus/amount.h>
24 #include <logging.h>
25+#include <net.h>
26 #include <policy/feerate.h>
27 #include <policy/policy.h>
28 #include <script/standard.h>
29@@ -42,7 +43,14 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, con
30 {
31 mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
32
33- if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
34+ if (auto mb = argsman.GetIntArg("-maxmempool")) {
35+ mempool_opts.max_size_bytes = *mb * 1'000'000;
36+ } else if (argsman.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
37+ // If we are running in blocksonly mode don't allocate the default 300MB of space for mempool
38+ // unless the user specifies -maxmempool, as otherwise it will leak into dbcache allowance.
39+ // Keeping the mempool enabled will still permit transaction relay for whitelisted peers
40+ mempool_opts.max_size_bytes = 5 * 1'000'000;
41+ }
42
43 if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};