aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-01-22 14:50:12 +0000
committerfanquake <fanquake@gmail.com>2023-01-22 14:57:16 +0000
commitad09b762757a293ff970113c15bd9dee3057e556 (patch)
tree18f7d661d19d12b6f678a02a249adca1a4840012
parentbf9361d3757656c75775e5b243b4d11980117d04 (diff)
parent8e85164e7d12be324ea1af2e288ebcf689c930b7 (diff)
downloadbitcoin-ad09b762757a293ff970113c15bd9dee3057e556.tar.xz
Merge bitcoin/bitcoin#26471: Reduce default mempool size in -blocksonly mode
8e85164e7d12be324ea1af2e288ebcf689c930b7 doc: release note on mempool size in -blocksonly (willcl-ark) ae797463dc7c72d990afa3ca53eeced7563ccd29 doc: Update blocksonly behaviour in reduce-memory (willcl-ark) 1134686ef92fb622ac32dc7463d3763cf18c85ad mempool: Don't share mempool with dbcache in blocksonly (willcl-ark) Pull request description: Fixes #9526 When `-blocksonly` has been set reduce default mempool size to avoid surprising resource usage via sharing un-used mempool cache space with dbcache. In comparison to https://github.com/bitcoin/bitcoin/pull/9569 which either set `maxmempool` size to 0 when `-blocksonly` was set or else errored on startup, this change will permit `maxmempool` options being set. This preserves the current (surprising?) behaviour of having a functional mempool in `-blocksonly` mode, to permit whitelisted peer transaction relay, whilst reducing average runtime memory usage for blocksonly nodes which either use the default settings or have otherwise configured a `maxmempool` size. To use the previous old defaults node operators can configure their node with: `-blocksonly -maxmempool=300`. ACKs for top commit: ajtowns: ACK 8e85164e7d12be324ea1af2e288ebcf689c930b7 stickies-v: re-ACK https://github.com/bitcoin/bitcoin/commit/8e85164e7d12be324ea1af2e288ebcf689c930b7 Tree-SHA512: 1c461c24b6f14ba02cfe4e2cde60dc629e47485db5701bca3003b8df79e3aa311c0c967979f6a1dca3ba69f5b1e45fa2db6ff83352fdf2d4349d5f8d120e740d
-rw-r--r--doc/reduce-memory.md6
-rw-r--r--doc/release-notes-26471.md13
-rw-r--r--src/init.cpp5
-rw-r--r--src/kernel/mempool_options.h2
4 files changed, 22 insertions, 4 deletions
diff --git a/doc/reduce-memory.md b/doc/reduce-memory.md
index 296b172bde..097cc9f001 100644
--- a/doc/reduce-memory.md
+++ b/doc/reduce-memory.md
@@ -16,11 +16,11 @@ The size of some in-memory caches can be reduced. As caches trade off memory usa
- The minimum value for `-maxmempool` is 5.
- A lower maximum mempool size means that transactions will be evicted sooner. This will affect any uses of `bitcoind` that process unconfirmed transactions.
-- To completely disable mempool functionality there is the option `-blocksonly`. This will make the client opt out of receiving (and thus relaying) transactions completely, except as part of blocks.
+- Since `0.14.0`, unused memory allocated to the mempool (default: 300MB) is shared with the UTXO cache, so when trying to reduce memory usage you should limit the mempool, with the `-maxmempool` command line argument.
- - Do not use this when using the client to broadcast transactions as any transaction sent will stick out like a sore thumb, affecting privacy. When used with the wallet it should be combined with `-walletbroadcast=0` and `-spendzeroconfchange=0`. Another mechanism for broadcasting outgoing transactions (if any) should be used.
+- To disable most of the mempool functionality there is the `-blocksonly` option. This will reduce the default memory usage to 5MB and make the client opt out of receiving (and thus relaying) transactions, except from whitelisted peers and as part of blocks.
-- Since `0.14.0`, unused memory allocated to the mempool (default: 300MB) is shared with the UTXO cache, so when trying to reduce memory usage you should limit the mempool, with the `-maxmempool` command line argument.
+ - Do not use this when using the client to broadcast transactions as any transaction sent will stick out like a sore thumb, affecting privacy. When used with the wallet it should be combined with `-walletbroadcast=0` and `-spendzeroconfchange=0`. Another mechanism for broadcasting outgoing transactions (if any) should be used.
## Number of peers
diff --git a/doc/release-notes-26471.md b/doc/release-notes-26471.md
new file mode 100644
index 0000000000..2cb74804ca
--- /dev/null
+++ b/doc/release-notes-26471.md
@@ -0,0 +1,13 @@
+Updated settings
+----------------
+
+- Setting `-blocksonly` will now reduce the maximum mempool memory
+ to 5MB (users may still use `-maxmempool` to override). Previously,
+ the default 300MB would be used, leading to unexpected memory usage
+ for users running with `-blocksonly` expecting it to eliminate
+ mempool memory usage.
+
+ As unused mempool memory is shared with dbcache, this also reduces
+ the dbcache size for users running with `-blocksonly`, potentially
+ impacting performance.
+
diff --git a/src/init.cpp b/src/init.cpp
index 685583bcbd..d8d8a66d34 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -736,10 +736,13 @@ void InitParameterInteraction(ArgsManager& args)
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}
- // disable whitelistrelay in blocksonly mode
if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
+ // disable whitelistrelay in blocksonly mode
if (args.SoftSetBoolArg("-whitelistrelay", false))
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
+ // Reduce default mempool size in blocksonly mode to avoid unexpected resource usage
+ if (args.SoftSetArg("-maxmempool", ToString(DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB)))
+ LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -maxmempool=%d\n", __func__, DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB);
}
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
diff --git a/src/kernel/mempool_options.h b/src/kernel/mempool_options.h
index dad6f14c39..a5a0bae86d 100644
--- a/src/kernel/mempool_options.h
+++ b/src/kernel/mempool_options.h
@@ -18,6 +18,8 @@ class CBlockPolicyEstimator;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
+//** Default for -maxmempool when blocksonly is set */
+static constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5};
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336};
/** Default for -mempoolfullrbf, if the transaction replaceability signaling is ignored */