mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
mempool: remove time-based transaction expiry #36540
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36540
Loading…
Reference in a new issue
No description provided.
Delete branch "10-2026-remove-mempool-expiry"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a simple mempool PR that fixes #33510.
Evicting mempool transactions by age (
-mempoolexpiry, default two weeks) isincentive-incompatible: it may drop transactions that could still be mined
As discussed IRL and in #33510, this PR hence removes age-based eviction entirely.
Transactions now leave the mempool only via size limiting (
-maxmempool),replacement, conflicts, or inclusion in a block. The
EXPIRYremoval reason isdropped.
-mempoolexpiryis retained as a hidden no-op that warns when set, soexisting configurations keep starting.
Nice side effects:
entry_timeindex has no readers. Removing it saves anordered-tree node per mempool entry and drops a now unused Boost
include.
DynamicMemoryUsage()per-entry estimate drops from three indexes totwo, so within the same
-maxmempoolbudget the mempool fits slightly moretransactions.
I analyzed the reason=expiry evictions from a 15-node monitoring fleet (data courtesy of b10c) and checked what happened to each transaction afterwards.
Across 938,157 unique expired transactions (2024-02-16 to 2026-10-21):
So time-based expiry is evicting transactions that get mined anyway, usually after a rebroadcast, it costs relay bandwidth.
See thread https://bnoc.xyz/t/request-how-many-mempool-transactions-are-evicted-by-time/132
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
-onlynetto-outboundnetby darosior)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
1 additional verified finding in the Review report.
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🟠 Minor · Post-restart mempool assertion can precede wallet resubmission
The new assertion can race wallet startup and observe zero or one entry instead of two; this functional-test failure is source-supported but has not been observed in CI.
Location:
test/functional/wallet_resendwallettransactions.py:86(head).🔵 Suggestion · Expiry removal leaves the policy-divergence tradeoff unexplained
If miners apply stricter policy, locally acceptable transactions lose age-based turnover; no current mining-policy incident is established, and memory remains bounded by
-maxmempool.Location:
src/validation.cpp:278(base).🔵 Suggestion · Aged transaction retention lacks replacement regression coverage
Deleting
mempool_expiry.pyleaves no replacement test that distinguishes retaining aged transactions during runtime maintenance and persisted-entry loading.Location:
test/functional/mempool_expiry.py:79(base).🔵 Suggestion · Rewritten chain test loses periodic readmission coverage
The startup restart no longer tests scheduled readmission of an absent wallet chain, and its single parent/child pair weakens detection of an ordering regression.
Location:
test/functional/wallet_resendwallettransactions.py:79(head).🔵 Suggestion ·
-mempoolexpiryloses behavior without a transition releaseOperators with an explicit
-mempoolexpirysetting lose its behavior in the release that first warns about it, rather than receiving the documented one-major-release deprecation grace period.Location:
src/init.cpp:963(head).🔵 Suggestion · Old
mempool.datentries now incur startup admission workWith persistence enabled, restarting after long downtime now attempts admission of every old
mempool.datentry; the added work is bounded by the dump, but no startup slowdown was measured.Location:
src/node/mempool_persist.cpp:102(head).Review coverage was incomplete.
Reviewed:
63d6cf1a530f· Review report · Previous reportspermalink
I don't think it's a good idea to change the node's behaviour in a way that doesn't allow users/miners to revert to the previous default in case the change turns out to be undesirable or harmful for some or many users.
Is there any reason why this change shouldn't be phased in via setting
DEFAULT_MEMPOOL_EXPIRY_HOURSto a large value, such as 35040 (4 years), instead?Concept ACK
Node operators should assume that at any point in time, and for any duration of time, their mempool can consume up to
-maxmempoolof resources. Of course, we should make the mempool maximally useful within that constraint, and transactions that should (from the node's perspective) get mined, but don't, can affect its ability to hold transactions that actually will/can get mined.The main downside from this removal is that in a non-adversarial case (an adversary can just rebroadcast every 2 weeks), transactions can remain in the mempool forever with a high enough fee rate, e.g. in case of diverging policy or consensus rules, and this reduces a node's effective mempool capacity. While that is not ideal, I also don't think we need to have startup options that make it easier to run a node that is out of sync with the policy and consensus rules that the network actually operates on.
I think the other historically mentioned reasons don't hold up anymore either:
I think it's nice that we can clean up the code right away. If people can come up with good reasons to use this setting, it might make sense to keep it, or deprecate rather than remove. But if we can't, then I think it's sensible to remove it?
Concept ACK, per https://github.com/bitcoin/bitcoin/pull/16409 😅
Concept ACK
@ismaelsadeeq since you removed entry_time index meaning we are left with 2 indexes.
2 x 3 = 6 pointers.
would it be fine to use 6 in MallocUsage() so that the same -maxmempool budget can hold extra txn you talked about in the nice side-effect?
Two things look unfinished: the memory estimate still counts three indexes, and
wallet_resendwallettransactions.pyno longer checks that a parent is resubmitted before its child.tumutech's inline question on the first is still open.
getmempoolinforeportsusage1192 for one transaction on both649bc0a(base) and1556184(head), sinceDynamicMemoryUsage()still counts 9 pointers per entry. The old resend test expired a parent and child and needed both resubmitted, which works only in insertion order. With that order reversed, base's test fails (resubmit 1) and head's passes.Could this PR use 6 pointers, as tumutech suggests, or drop the "fits slightly more transactions" sentence? For the test, restarting with
-persistmempool=0and checking that both transactions are back would make the order matter again, since the wallet resubmits them on load.The rest matches the release note. I measured it with a functional-test script on regtest with mocktime, and the touched functional tests and the unit suite pass on head on macOS (the USDT test skipped). Head keeps transactions past 336 h, loads older
mempool.datentries with their entry time, and warns that-mempoolexpiryhas no effect. One change may deserve a line in the note:abandontransactionon a wallet transaction older than two weeks now fails with "Transaction not eligible for abandonment". On base it worked after expiry, until the wallet's next resubmission, within 36 h, put it back. I can share the script as a gist.I've spent some time going through the discussion in #33510 and the history of mempool expiry. I agree that removing transactions simply because they've been in the mempool for 14 days isn't ideal, especially when an old parent could become attractive through a new high-fee child.
My main concern with removing expiry entirely is the possibility of retaining high-feerate transactions that miners won't include, for example when an outdated node accepts transactions that violate newer policies adopted by miners, such as #32521.
TrimToSize()wouldn't necessarily help here, since those transactions are still highly ranked locally. Under memory pressure, they could displace lower-feerate transactions that miners would actually include, potentially causing moreSIZELIMITremovals and raising the minimum mempool feerate.I agree with stickies-v that this mostly concerns outdated nodes, and expiry isn't particularly effective against an attacker who keeps rebroadcasting. However, it does provide eventual recovery from a one-time attack or persistent policy disagreement when the transactions are no longer being submitted.
The data shared by 0xB10C shows that expiry removes transactions that can later be mined, but I'm not sure it tells us enough about the tradeoff. How often does expiry remove economically attractive transactions or CPFP packages, compared with how often it actually frees capacity occupied by transactions miners won't include? And would removing it lead to more size-based evictions or a higher minimum mempool feerates under pressure?
Looking at the hybrid approach suggested by Ismaelsadeeq, i.e combining transaction age with missed mining opportunities, possibly only under memory pressure. I'm leaning toward exploring this longer term, but it has its own problems. Local template inclusion doesn't establish that miners received or rejected a transaction, and counting missed opportunities could penalize censored transactions. There are also the costs of template construction and the question of what happens to previous observations when a parent receives a new high-fee child.
There's also the interaction with fee estimation following #34075. Persistently unmined, high-feerate transactions could affect the mempool-based estimator despite its health checks. But I think that such transactions for estimation don't require removing them from the mempool. I think this is worth investigating separately, rather than using fee estimation as a reason to retain expiry.
Given this, I'm leaning toward deprecating
-mempoolexpiryrather than removing its functionality immediately, with age expiry disabled by default but still available explicitly during the deprecation period. This would preserve a recovery option for operators while giving us a chance to understand the consequences of the changed default.Finally, Is there already evidence that the protection expiry provides against persistent policy disagreement is negligible enough to justify removing the mechanism entirely, rather than just changing the default?
I'd appreciate corrections in case I missed something.
Thanks for review @ajtowns @stickies-v @maflcko @tumutech @fametrano @musaHaruna
I addressed most feedback and concerns in the latest push or with reply below.
The best thing to do in this case is to update the node, because expiry doesn't help here either. The transactions can just be rebroadcast again, and as you mentioned, this cycle can go on forever, so I don't think this is a valid reason to keep expiry.
I think the fact that it is possible, and that we see such transactions mined, should suffice. We assume miners act rationally and follow incentive compatibility for inclusion, so whatever they mine is economically incentive compatible at that moment in time.
There is a legitimate concern raised by @mzumsande, and offline by a few other people, that this approach also aids censorship, so I won't be comfortable shipping it.
I thought about this, and that's why the default never uses the mempool to raise the fee rate estimate, so it's not going to be a problem at all. It may only affect users who explicitly request the mempool estimator alone, and I assume those are advanced users who know what they're getting into and should have a sentinel max, e.g. an LND budget sweeper.
I feel strongly about this. I think the reasons mentioned above by you and @ajtowns are thin. We should not incentivize free relay, the expiry use case is a bit speculative, and @0xB10C's data already showed that most of the expired txs eventually get mined. In the adversarial scenario expiry won't help either, since the attacker can just keep cycling it. The fee rate estimator is not affected. So it would be more ideal to just clean this code up and remove this feature, it is unnecessary.
Also, if we decide to remove wallet rebroadcast and only rebroadcast what's not in the mempool, we would still have a privacy leak if users expire, because we'd expire our own txs and then rebroadcast them again. The same thing happens on reload: loading mempool.dat drops entries older than the expiry, so after a restart the node treats its own aged txs as missing and rebroadcasts them.
Fixed, thanks.
To be clear: I only spot-checked like 10 transactions in https://bnoc.xyz/t/request-how-many-mempool-transactions-are-evicted-by-time/132/. Someone should check this in full. I won't get to it anytime soon.
Fixed
@0xB10C shared the dataset with me, and 92.0 percent (863,451) were later mined; only 8.0 percent (74,706) never confirmed. At least 34 percent (316,381) show rebroadcast evidence, and 87 percent of those confirmed. Of the ones that confirm, half are mined within about 5 days of first expiry and ninety percent within about 55 days, so there is a long tail that bounces for weeks before getting in.
See https://bnoc.xyz/t/request-how-many-mempool-transactions-are-evicted-by-time/132/9
It's also the one piece of information that actually matters, since it's what tells you the difference this PR would make, namely between "a confirmed tx was only relayed due to its conflicting tx being expired" vs "these txs were replaced by valid RBF alternatives, or by going direct to a miner anyway".
zmq rawtx (+hashtx to make lookups easier perhaps) would provide that information. Dumping the txid/wtxid/serialization mapping to a database and deleting the rows for txs that confirm might make it manageable long term.
Thanks. I'll capture that going forward on my telemetry node (but will take months to have something reasonable). cc @b10c
IMO it doesn't. Take any conflict C of an expired tx E:
Indeed, with this PR we won't have this free relay fee bumping anymore. But that's an okay tradeoff given the effects of expiry discussed in this thread and the original issue?
AFAICT, the reasons why a transaction that was expired could still be mined are:
These do not seem like enough reason to completely discard age-based eviction. What if we only expired when the mempool is full, as mentioned in https://github.com/bitcoin/bitcoin/issues/33510#issue-3470172634?
re: https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6999505916
Why not? It seems like a valid reason to me. The mempool should hold txs that are likely to be mined based on incentive compatibility, and evicting those is harmful.
In the adversarial case, no, the attacker can just rebroadcast and cycle the tx again. In the policy-tightening case, yes, but a tx only fails to get mined while miners are also skipping, and that can change with network conditions (As we have previously reverse policy tightening https://github.com/bitcoin/bitcoin/pull/33106). And the empirical data indicates that the majority of expired txs get mined anyway.
This is what will happen without age-based expiry. When the mempool is full we evict the lowest-feerate chunks first, which is incentive-compatible. "Expire only when full" would add an age-based eviction on top of that. Age is not a proxy for mineability (how do you do that? You expire first; if nothing expires, then evict the lowest chunks?).
I think "expire only when full" still has a privacy leak. Under memory pressure you'd expire your own txs and then rebroadcast them, but your peers may not have expired theirs yet, so you'd inv them a tx they already have. That re-announcement likely reveals it as your own. And if miners are filtering certain txs, expiring exactly those still aids in dropping them.
Concept ACK
Following @ismaelsadeeq https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-7000830934 and some offline discussions, I've become more convinced that mempool age-based expiry isn't worth keeping and incentivises free relay (an expired transaction is rebroadcast and relayed at no cost).
re: my earlier comment https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6999505916
Age doesn't say anything about mineability, and the low fee rate chunks (which are least likely to get mined) will be removed when the mempool is full. I was previously worried about censorship possibly leading to a situation where mempools are filled with censored transactions; removing expiry helps censorship resistance by giving non-censoring miners the chance to mine them.
re: policy divergence discussions:
I now support removing expiry entirely as is done in this PR. Expiry doesn't enforce any policy. It drops a transaction the node itself considers valid and standard, then accepts it again as soon as it is rebroadcast. If an operator wants to match miners' policy, the fix is to upgrade. If they keep a looser policy on purpose, expiring those transactions works against their own configuration. I can't think of a good reason to keep
-mempoolexpiry.