Skip to content

Commit ad09b76

Browse files
committed
Merge bitcoin/bitcoin#26471: Reduce default mempool size in -blocksonly mode
8e85164 doc: release note on mempool size in -blocksonly (willcl-ark) ae79746 doc: Update blocksonly behaviour in reduce-memory (willcl-ark) 1134686 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 bitcoin/bitcoin#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 8e85164 stickies-v: re-ACK bitcoin/bitcoin@8e85164 Tree-SHA512: 1c461c24b6f14ba02cfe4e2cde60dc629e47485db5701bca3003b8df79e3aa311c0c967979f6a1dca3ba69f5b1e45fa2db6ff83352fdf2d4349d5f8d120e740d
2 parents bf9361d + 8e85164 commit ad09b76

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

doc/reduce-memory.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ The size of some in-memory caches can be reduced. As caches trade off memory usa
1616
- The minimum value for `-maxmempool` is 5.
1717
- A lower maximum mempool size means that transactions will be evicted sooner. This will affect any uses of `bitcoind` that process unconfirmed transactions.
1818

19-
- 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.
19+
- 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.
2020

21-
- 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.
21+
- 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.
2222

23-
- 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.
23+
- 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.
2424

2525
## Number of peers
2626

doc/release-notes-26471.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Updated settings
2+
----------------
3+
4+
- Setting `-blocksonly` will now reduce the maximum mempool memory
5+
to 5MB (users may still use `-maxmempool` to override). Previously,
6+
the default 300MB would be used, leading to unexpected memory usage
7+
for users running with `-blocksonly` expecting it to eliminate
8+
mempool memory usage.
9+
10+
As unused mempool memory is shared with dbcache, this also reduces
11+
the dbcache size for users running with `-blocksonly`, potentially
12+
impacting performance.
13+

src/init.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,13 @@ void InitParameterInteraction(ArgsManager& args)
736736
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
737737
}
738738

739-
// disable whitelistrelay in blocksonly mode
740739
if (args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
740+
// disable whitelistrelay in blocksonly mode
741741
if (args.SoftSetBoolArg("-whitelistrelay", false))
742742
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
743+
// Reduce default mempool size in blocksonly mode to avoid unexpected resource usage
744+
if (args.SoftSetArg("-maxmempool", ToString(DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB)))
745+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -maxmempool=%d\n", __func__, DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB);
743746
}
744747

745748
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.

src/kernel/mempool_options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class CBlockPolicyEstimator;
1818

1919
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
2020
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
21+
//** Default for -maxmempool when blocksonly is set */
22+
static constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5};
2123
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
2224
static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336};
2325
/** Default for -mempoolfullrbf, if the transaction replaceability signaling is ignored */

0 commit comments

Comments
 (0)