mempool: remove time-based transaction expiry #36540

Open
ismaelsadeeq wants to merge 3 commits from 10-2026-remove-mempool-expiry into master AGit
ismaelsadeeq commented 2026-10-15 09:14:08 +00:00 (Migrated from github.com)

This is a simple mempool PR that fixes #33510.

Evicting mempool transactions by age (-mempoolexpiry, default two weeks) is
incentive-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 EXPIRY removal reason is
dropped. -mempoolexpiry is retained as a hidden no-op that warns when set, so
existing configurations keep starting.

Nice side effects:

  • With expiry gone, the entry_time index has no readers. Removing it saves an
    ordered-tree node per mempool entry and drops a now unused Boost
    include.
  • The DynamicMemoryUsage() per-entry estimate drops from three indexes to
    two, so within the same -maxmempool budget the mempool fits slightly more
    transactions.

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):

  • 92.0% (863,451) were later mined; only 8.0% (74,706) never confirmed.
  • At least 34% (316,381) show rebroadcast evidence, and 87% of those confirmed.
  • Of the ones that confirm, half are mined within about 5 days of first expiry and 90% within about 55 days.

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

This is a simple mempool PR that fixes #33510. Evicting mempool transactions by age (`-mempoolexpiry`, default two weeks) is incentive-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 `EXPIRY` removal reason is dropped. `-mempoolexpiry` is retained as a hidden no-op that warns when set, so existing configurations keep starting. Nice side effects: - With expiry gone, the `entry_time` index has no readers. Removing it saves an ordered-tree node per mempool entry and drops a now unused Boost include. - The `DynamicMemoryUsage()` per-entry estimate drops from three indexes to two, so within the same `-maxmempool` budget the mempool fits slightly more transactions. 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): - 92.0% (863,451) were later mined; only 8.0% (74,706) never confirmed. - At least 34% (316,381) show rebroadcast evidence, and 87% of those confirmed. - Of the ones that confirm, half are mined within about 5 days of first expiry and 90% within about 55 days. 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
DrahtBot commented 2026-10-15 09:14:18 +00:00 (Migrated from github.com)

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.

Type Reviewers
Concept ACK stickies-v, maflcko, tumutech, Eunovo

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:

  • #37048 (Rename -onlynet to -outboundnet by darosior)
  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36904 (log: Remove trailing and embedded newlines from log messages by maflcko)
  • #36861 (Configuration argument handling improvements. by jlopp)
  • #36627 (tracing: run USDT tests without BPF privileges by willcl-ark)
  • #36482 (wallet: Only broadcast resubmitted transactions that were added to the mempool by achow101)
  • #36398 (wallet: only rebroadcast transactions originating from the wallet by mzumsande)
  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36540 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36540.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36540#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [stickies-v](https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6216612525), [maflcko](https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6219869245), [tumutech](https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6221116492), [Eunovo](https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-7162954491) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37048](https://github.com/bitcoin/bitcoin/pull/37048) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37048.svg"></sub> (Rename `-onlynet` to `-outboundnet` by darosior) * [#36990](https://github.com/bitcoin/bitcoin/pull/36990) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36990.svg"></sub> (test: replace hard-coded RPC error codes by l0rinc) * [#36904](https://github.com/bitcoin/bitcoin/pull/36904) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36904.svg"></sub> (log: Remove trailing and embedded newlines from log messages by maflcko) * [#36861](https://github.com/bitcoin/bitcoin/pull/36861) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36861.svg"></sub> (Configuration argument handling improvements. by jlopp) * [#36627](https://github.com/bitcoin/bitcoin/pull/36627) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36627.svg"></sub> (tracing: run USDT tests without BPF privileges by willcl-ark) * [#36482](https://github.com/bitcoin/bitcoin/pull/36482) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36482.svg"></sub> (wallet: Only broadcast resubmitted transactions that were added to the mempool by achow101) * [#36398](https://github.com/bitcoin/bitcoin/pull/36398) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36398.svg"></sub> (wallet: only rebroadcast transactions originating from the wallet by mzumsande) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equal -> assert_true/assert_false by hodlinator) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

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.py leaves 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 · -mempoolexpiry loses behavior without a transition release

Operators with an explicit -mempoolexpiry setting 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.dat entries now incur startup admission work

With persistence enabled, restarting after long downtime now attempts admission of every old mempool.dat entry; 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 reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4da2754fad9950343ec17fdcafb16eba62864da6bb440cd178ec60ac28a60459:7ce671d487915d65de4fd6eef6a405851510d462206109463572d325d51bc921 --> <!-- ralph-base:8130b3b8836879915e82730eb818ee6b58c28168 --> <!-- ralph-head:63d6cf1a530f410b9b5ed2c3860da55acdaf04b9 --> <!-- ralph-case:1d153f84cebfb01ff2bf0d1c6e2c7fde45af7eafc6f4d2d7a1e4c24a7158dc0f --> [1 additional verified finding in the Review report](<https://review.fish.foo/report/36540-63d6cf1a530f410b9b5ed2c3860da55acdaf04b9-2716-7.html>). 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/63d6cf1a530f410b9b5ed2c3860da55acdaf04b9/test/functional/wallet_resendwallettransactions.py#L86>) (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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/649bc0a645eb127a9b1e6d078f8d129be6380c87/src/validation.cpp#L278>) (base). **🔵 Suggestion · Aged transaction retention lacks replacement regression coverage** Deleting `mempool_expiry.py` leaves no replacement test that distinguishes retaining aged transactions during runtime maintenance and persisted-entry loading. Location: [`test/functional/mempool_expiry.py:79`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/649bc0a645eb127a9b1e6d078f8d129be6380c87/test/functional/mempool_expiry.py#L79>) (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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/63d6cf1a530f410b9b5ed2c3860da55acdaf04b9/test/functional/wallet_resendwallettransactions.py#L79>) (head). **🔵 Suggestion · `-mempoolexpiry` loses behavior without a transition release** Operators with an explicit `-mempoolexpiry` setting 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/63d6cf1a530f410b9b5ed2c3860da55acdaf04b9/src/init.cpp#L963>) (head). **🔵 Suggestion · Old `mempool.dat` entries now incur startup admission work** With persistence enabled, restarting after long downtime now attempts admission of every old `mempool.dat` entry; the added work is bounded by the dump, but no startup slowdown was measured. Location: [`src/node/mempool_persist.cpp:102`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/63d6cf1a530f410b9b5ed2c3860da55acdaf04b9/src/node/mempool_persist.cpp#L102>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`63d6cf1a530f`](<https://git.fish.foo/bitcoin/bitcoin/commit/63d6cf1a530f410b9b5ed2c3860da55acdaf04b9>) · [Review report](<https://review.fish.foo/report/36540-63d6cf1a530f410b9b5ed2c3860da55acdaf04b9-2716-7.html>) · [Previous reports](<https://review.fish.foo/traces/36540/>) [permalink](<https://review.fish.foo/report/36540-63d6cf1a530f410b9b5ed2c3860da55acdaf04b9-2716-7.html>)
ajtowns commented 2026-10-16 01:41:22 +00:00 (Migrated from github.com)

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_HOURS to a large value, such as 35040 (4 years), instead?

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_HOURS` to a large value, such as 35040 (4 years), instead?
stickies-v commented 2026-10-16 13:31:56 +00:00 (Migrated from github.com)

Concept ACK

Node operators should assume that at any point in time, and for any duration of time, their mempool can consume up to -maxmempool of 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:

  • it's nice to be able to replace a large, low fee rate transaction without having to pay the RBF "tax", but RBF mitigates free relay for a reason, I don't think we need a carve-out, even a conservatively rate-limited one
  • pinning attacks also seem largely irrelevant, given the 2 week delay and the fact that we have TRUC now

Is there any reason why this change shouldn't be phased in via setting

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 Node operators should assume that at any point in time, and for any duration of time, their mempool can consume up to `-maxmempool` of 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: - it's nice to be able to replace a large, low fee rate transaction without having to pay the RBF "tax", but RBF mitigates free relay for a reason, I don't think we need a carve-out, even a conservatively rate-limited one - pinning attacks also seem largely irrelevant, given the 2 week delay and the fact that we have TRUC now > Is there any reason why this change shouldn't be phased in via setting 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?
maflcko commented 2026-10-16 16:22:30 +00:00 (Migrated from github.com)
Concept ACK, per https://github.com/bitcoin/bitcoin/pull/16409 :sweat_smile:
tumutech commented 2026-10-16 17:33:05 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
tumutech (Migrated from github.com) reviewed 2026-10-16 18:19:59 +00:00
Lines 829-830
tumutech (Migrated from github.com) commented 2026-10-16 18:19:59 +00:00

@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?

The DynamicMemoryUsage() per-entry estimate drops from three indexes to
two, so within the same -maxmempool budget the mempool fits slightly more
transactions.

@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? > The DynamicMemoryUsage() per-entry estimate drops from three indexes to > two, so within the same -maxmempool budget the mempool fits slightly more > transactions.
fametrano commented 2026-10-25 07:35:33 +00:00 (Migrated from github.com)

Two things look unfinished: the memory estimate still counts three indexes, and wallet_resendwallettransactions.py no longer checks that a parent is resubmitted before its child.

tumutech's inline question on the first is still open. getmempoolinfo reports usage 1192 for one transaction on both 649bc0a (base) and 1556184 (head), since DynamicMemoryUsage() 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=0 and 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.dat entries with their entry time, and warns that -mempoolexpiry has no effect. One change may deserve a line in the note: abandontransaction on 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.

Two things look unfinished: the memory estimate still counts three indexes, and `wallet_resendwallettransactions.py` no longer checks that a parent is resubmitted before its child. tumutech's inline question on the first is still open. `getmempoolinfo` reports `usage` 1192 for one transaction on both 649bc0a (base) and 1556184 (head), since `DynamicMemoryUsage()` 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=0` and 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.dat` entries with their entry time, and warns that `-mempoolexpiry` has no effect. One change may deserve a line in the note: `abandontransaction` on 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.
musaHaruna (Migrated from github.com) reviewed 2026-10-27 12:58:15 +00:00
musaHaruna (Migrated from github.com) left a comment

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 more SIZELIMIT removals 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 -mempoolexpiry rather 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.

I've spent some time going through the discussion in[ #33510](https://github.com/bitcoin/bitcoin/issues/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](https://github.com/bitcoin/bitcoin/pull/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 more `SIZELIMIT` removals 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](https://github.com/bitcoin/bitcoin/pull/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 `-mempoolexpiry` rather 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.
ismaelsadeeq commented 2026-11-03 13:28:44 +00:00 (Migrated from github.com)

Thanks for review @ajtowns @stickies-v @maflcko @tumutech @fametrano @musaHaruna

I addressed most feedback and concerns in the latest push or with reply below.

My main concern with removing expiry entirely is the possibility of retaining high-feerate transactions that miners won't include ... Under memory pressure, they could displace lower-feerate transactions that miners would actually include, potentially causing more SIZELIMIT removals and raising the minimum mempool feerate.

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.

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?

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.

Looking at the hybrid approach suggested by Ismaelsadeeq ... counting missed opportunities could penalize censored transactions ...

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.

There's also the interaction with fee estimation following #34075 ...

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.

Given this, I'm leaning toward deprecating -mempoolexpiry rather than removing its functionality immediately, with age expiry disabled by default but still available explicitly during the deprecation period.

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.

Thanks for review @ajtowns @stickies-v @maflcko @tumutech @fametrano @musaHaruna I addressed most feedback and concerns in the latest push or with reply below. > My main concern with removing expiry entirely is the possibility of retaining high-feerate transactions that miners won't include ... Under memory pressure, they could displace lower-feerate transactions that miners would actually include, potentially causing more SIZELIMIT removals and raising the minimum mempool feerate. 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. > 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? 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. > Looking at the hybrid approach suggested by Ismaelsadeeq ... counting missed opportunities could penalize censored transactions ... 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. > There's also the interaction with fee estimation following #34075 ... 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. > Given this, I'm leaning toward deprecating -mempoolexpiry rather than removing its functionality immediately, with age expiry disabled by default but still available explicitly during the deprecation period. 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.
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-03 13:29:13 +00:00
Lines 829-830
ismaelsadeeq (Migrated from github.com) commented 2026-11-03 13:29:13 +00:00

Fixed, thanks.

Fixed, thanks.
0xB10C commented 2026-11-04 22:22:23 +00:00 (Migrated from github.com)

and @0xB10C's data already showed that most of the expired txs eventually get mined.

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.

> and @0xB10C's data already showed that most of the expired txs eventually get mined. 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.
fanquake (Migrated from github.com) reviewed 2026-11-12 11:29:44 +00:00
fanquake (Migrated from github.com) commented 2026-11-12 11:29:44 +00:00
  option no longer has any effect (a warning is logged if it is set). (#36540)
```suggestion option no longer has any effect (a warning is logged if it is set). (#36540) ```
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-16 16:48:52 +00:00
ismaelsadeeq (Migrated from github.com) commented 2026-11-16 16:48:52 +00:00

Fixed

Fixed
ismaelsadeeq commented 2026-11-16 16:57:47 +00:00 (Migrated from github.com)

and @0xB10C's data already showed that most of the expired txs eventually get mined.

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.

@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

> > and @0xB10C's data already showed that most of the expired txs eventually get mined. > > 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. @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
ajtowns commented 2026-11-16 18:56:42 +00:00 (Migrated from github.com)

See https://bnoc.xyz/t/request-how-many-mempool-transactions-are-evicted-by-time/132/9

On “expired then replaced”: @b10c I don’t think the logs can catch it. Once a transaction expires it is already evicted, so a later conflicting transaction is never logged as replacing it, there is nothing in the mempool to replace. The only way would be to take the expired transaction’s spent outpoints and check whether a later mempool entry or mined transaction spends them, which needs data the txid-only logs don’t carry. Given 92 percent confirm anyway the lost ones are minuscule of a concern, but it is the one piece this dataset can’t answer.

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.

> See https://bnoc.xyz/t/request-how-many-mempool-transactions-are-evicted-by-time/132/9 > > On “expired then replaced”: @b10c I don’t think the logs can catch it. Once a transaction expires it is already evicted, so a later conflicting transaction is never logged as replacing it, there is nothing in the mempool to replace. The only way would be to take the expired transaction’s spent outpoints and check whether a later mempool entry or mined transaction spends them, which needs data the txid-only logs don’t carry. Given 92 percent confirm anyway the lost ones are minuscule of a concern, but it is the one piece this dataset can’t answer. 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.
ismaelsadeeq commented 2026-11-17 09:22:56 +00:00 (Migrated from github.com)

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

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".

IMO it doesn't. Take any conflict C of an expired tx E:

  1. If C satisfies the replacement policy, it would replace E whether or not E is still in the mempool, so the PR doesn't change anything here.
  2. If C doesn't satisfy the replacement rules, then while E is in the mempool C is rejected, without expiry a conflict that couldn't outbid E simply can't displace it. A sender who genuinely wants to replace still can, by paying the incremental relay fee, otherwise E stays (May confirm, or dropped by size eviction).

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?

> 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 > 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". IMO it doesn't. Take any conflict C of an expired tx E: 1. If C satisfies the replacement policy, it would replace E whether or not E is still in the mempool, so the PR doesn't change anything here. 2. If C doesn't satisfy the replacement rules, then while E is in the mempool C is rejected, without expiry a conflict that couldn't outbid E simply can't displace it. A sender who genuinely wants to replace still can, by paying the incremental relay fee, otherwise E stays (May confirm, or dropped by size eviction). 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?
Eunovo commented 2026-11-19 04:15:45 +00:00 (Migrated from github.com)

Evicting mempool transactions by age (-mempoolexpiry, default two weeks) is
incentive-incompatible: it may drop transactions that could still be mined
As discussed IRL and in #33510, this PR hence removes age-based eviction entirely.

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?

  • we can avoid filling the mempool with transactions that won't get mined
  • transactions that can be mined will remain as long as we have memory
> Evicting mempool transactions by age (`-mempoolexpiry`, default two weeks) is > incentive-incompatible: it may drop transactions that could still be mined > As discussed IRL and in #33510, this PR hence removes age-based eviction entirely. AFAICT, the reasons why a transaction that was expired could still be mined are: - "the mempool was cleared and some low feerate transaction that has been in the mempool and has not confirmed in a long time due to having a low feerate is now at the top of the mempool" as mentioned in https://github.com/bitcoin/bitcoin/issues/33510#issue-3470172634 - the transaction has a recent child that makes the package desirable to miners 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? - we can avoid filling the mempool with transactions that won't get mined - transactions that can be mined will remain as long as we have memory
ismaelsadeeq commented 2026-11-19 05:40:13 +00:00 (Migrated from github.com)

re: https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6999505916

These do not seem like enough reason to completely discard age-based eviction

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.

we can avoid filling the mempool with transactions that won't get mined

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.

transactions that can be mined will remain as long as we have memory

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.

re: https://github.com/bitcoin/bitcoin/pull/36540#issuecomment-6999505916 > These do not seem like enough reason to completely discard age-based eviction 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. > we can avoid filling the mempool with transactions that won't get mined 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. > transactions that can be mined will remain as long as we have memory 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.
Eunovo commented 2026-11-25 12:51:32 +00:00 (Migrated from github.com)

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

we can avoid filling the mempool with transactions that won't get mined
transactions that can be mined will remain as long as we have memory

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.

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 > we can avoid filling the mempool with transactions that won't get mined > transactions that can be mined will remain as long as we have memory 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`.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36540
No description provided.