Merge bitcoin/bitcoin#36294: mempool: Remove -persistmempoolv1 option
What changed, and why it matters
This commit removes an old command-line option called -persistmempoolv1 that let users write the mempool file in a legacy format. The option was always documented as temporary, and the only versions it helped downgrade to are no longer supported. Reading the old format is still supported, so users upgrading from old versions are not affected. A new test was added to check that importing a corrupted mempool file is rejected safely. There is no direct security vulnerability here; it is a cleanup of obsolete functionality.
No immediate action required. Operators who previously used -persistmempoolv1 should be aware the option is gone and that mempool.dat will always be written in the current format. If downgrading to Bitcoin Core v26.x or earlier is still needed, users must manage their mempool manually. Review the new malformed-file test for completeness if desired.
Security signals we found
Removal of a legacy, un-XORed mempool serialization option that was documented as temporary
Addition of a negative test ensuring malformed mempool.dat files are rejected during import
No change to consensus, P2P, wallet encryption, or RPC authorization logic
Evidence from the diff
The merge commit removes the -persistmempoolv1 startup option and the persist_v1_dat mempool option. DumpMempool now always writes the current XOR-obfuscated mempool.dat format (MEMPOOL_DUMP_VERSION) instead of conditionally falling back to the un-XORed v1 format. The functional test mempool_compatibility.py is updated to use v31.0 as the ‘old’ node (the oldest release that supports the current format and still has -persistmempoolv1) to verify that current code can still read legacy v1 files. A new test in mempool_persist.py verifies that importmempool fails gracefully on a truncated/malformed mempool.dat. No buffer overflow, memory corruption, or consensus-affecting change is present in the diff.
Changed components
src/init.cppsrc/kernel/mempool_options.hsrc/node/mempool_args.cppsrc/node/mempool_persist.cpptest/functional/mempool_compatibility.pytest/functional/mempool_persist.pyInspect captured patch +25 / −24
### doc/release-notes-remove-persistmempoolv1.md
@@ -0,0 +1,6 @@
+Updated settings
+----------------
+
+- The `-persistmempoolv1` startup option has been removed. It was introduced
+ as a temporary option in v27.0 to allow downgrading to v26.x and earlier,
+ which cannot read the current `mempool.dat` format.
### src/init.cpp
@@ -534,11 +534,6 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-prevoutfetchthreads=<n>", strprintf("Set the number of threads used to prefetch block input prevouts from the chainstate database (0 disables, up to %d, default: %d). Negative values are rejected.", MAX_PREVOUTFETCH_THREADS, DEFAULT_PREVOUTFETCH_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- argsman.AddArg("-persistmempoolv1",
- strprintf("Whether a mempool.dat file created by -persistmempool or the savemempool RPC will be written in the legacy format "
- "(version 1) or the current format (version 2). This temporary option will be removed in the future. (default: %u)",
- DEFAULT_PERSIST_V1_DAT),
- ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex. "
"Warning: Reverting this setting requires re-downloading the entire blockchain. Wallets and indexes should be loaded at startup and kept active while pruning is enabled so they stay synchronized before old block data is deleted; wallets or indexes that fall behind pruned data may require a reindex. "
### src/kernel/mempool_options.h
@@ -21,8 +21,6 @@ inline constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
inline constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5};
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
inline constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336};
-/** Whether to fall back to legacy V1 serialization when writing mempool.dat */
-inline constexpr bool DEFAULT_PERSIST_V1_DAT{false};
/** Default for -acceptnonstdtxn */
inline constexpr bool DEFAULT_ACCEPT_NON_STD_TXN{false};
@@ -53,7 +51,6 @@ struct MemPoolOptions {
std::optional<unsigned> max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt};
bool permit_bare_multisig{DEFAULT_PERMIT_BAREMULTISIG};
bool require_standard{true};
- bool persist_v1_dat{DEFAULT_PERSIST_V1_DAT};
MemPoolLimits limits{};
ValidationSignals* signals{nullptr};
### src/node/mempool_args.cpp
@@ -103,8 +103,6 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
return util::Error{Untranslated(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.GetChainTypeString()))};
}
- mempool_opts.persist_v1_dat = argsman.GetBoolArg("-persistmempoolv1", mempool_opts.persist_v1_dat);
-
ApplyArgsManOptions(argsman, mempool_opts.limits);
if (mempool_opts.limits.cluster_count > MAX_CLUSTER_COUNT_LIMIT) {
### src/node/mempool_persist.cpp
@@ -179,16 +179,11 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, FopenFn mock
}
try {
- const uint64_t version{pool.m_opts.persist_v1_dat ? MEMPOOL_DUMP_VERSION_NO_XOR_KEY : MEMPOOL_DUMP_VERSION};
- file << version;
+ file << MEMPOOL_DUMP_VERSION;
- if (!pool.m_opts.persist_v1_dat) {
- const Obfuscation obfuscation{FastRandomContext{}.randbytes<Obfuscation::KEY_SIZE>()};
- file << obfuscation;
- file.SetObfuscation(obfuscation);
- } else {
- file.SetObfuscation({});
- }
+ const Obfuscation obfuscation{FastRandomContext{}.randbytes<Obfuscation::KEY_SIZE>()};
+ file << obfuscation;
+ file.SetObfuscation(obfuscation);
uint64_t mempool_transactions_to_write(vinfo.size());
file << mempool_transactions_to_write;
### test/functional/mempool_compatibility.py
@@ -22,13 +22,14 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
+ self.extra_args = [["-persistmempoolv1=1"], []]
def skip_test_if_missing_module(self):
self.skip_if_no_previous_releases()
def setup_network(self):
- self.add_nodes(self.num_nodes, versions=[
- 200100, # Last release without unbroadcast serialization and without XOR
+ self.add_nodes(self.num_nodes, extra_args=self.extra_args, versions=[
+ 310000, # Last release with -persistmempoolv1
None,
])
self.start_nodes()
@@ -37,7 +38,6 @@ def run_test(self):
self.log.info("Test that mempool.dat is compatible between versions")
old_node, new_node = self.nodes
- assert "unbroadcastcount" not in old_node.getmempoolinfo()
new_wallet = MiniWallet(new_node, mode=MiniWalletMode.RAW_P2PK)
self.generate(new_wallet, 1, sync_fun=self.no_op)
self.generate(new_node, COINBASE_MATURITY, sync_fun=self.no_op)
@@ -60,7 +60,8 @@ def run_test(self):
old_node_mempool.rename(new_node_mempool)
self.log.info("Start new node and verify mempool contains the tx")
- self.start_node(1, extra_args=["-persistmempoolv1=1"])
+ # The old node wrote the legacy v1 format (-persistmempoolv1), so this covers reading it
+ self.start_node(1)
assert old_tx_hash in new_node.getrawmempool()
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
@@ -73,7 +74,7 @@ def run_test(self):
new_node_mempool.rename(old_node_mempool)
self.log.info("Start old node again and verify mempool contains both txs")
- self.start_node(0, ['-nowallet'])
+ self.start_node(0)
assert old_tx_hash in old_node.getrawmempool()
assert unbroadcasted_tx_hash in old_node.getrawmempool()
### test/functional/mempool_persist.py
@@ -196,6 +196,15 @@ def run_test(self):
self.test_importmempool_union()
self.test_persist_unbroadcast()
+ self.test_importmempool_malformed()
+
+ def test_importmempool_malformed(self):
+ self.log.debug("Check that importmempool fails on a malformed mempool.dat.")
+ node0 = self.nodes[0]
+ mempooldat_malformed = os.path.join(self.options.tmpdir, "mempool_malformed.dat")
+ with open(node0.savemempool()["filename"], "rb") as src, open(mempooldat_malformed, "wb") as dst:
+ dst.write(src.read()[:-1])
+ assert_raises_rpc_error(-1, "Unable to import mempool file", node0.importmempool, mempooldat_malformed)
def test_persist_unbroadcast(self):
node0 = self.nodes[0]Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.