mempool: remove time-based transaction expiry #36540

pull ismaelsadeeq wants to merge 3 commits into bitcoin:master from ismaelsadeeq:10-2026-remove-mempool-expiry changing 20 files +40 −260
  1. ismaelsadeeq commented at 9:14 AM on October 15, 2026: member

    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

  2. DrahtBot added the label Mempool on Oct 15, 2026
  3. DrahtBot commented at 9:14 AM on October 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK stickies-v, maflcko, tumutech

    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:

    • #36861 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36861.svg"></sub> (Configuration argument handling improvements. by jlopp)
    • #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 <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 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36398.svg"></sub> (wallet: only rebroadcast transactions originating from the wallet by mzumsande)
    • #36257 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equals -> assert_true/assert_false by hodlinator)
    • #31260 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31260.svg"></sub> (scripted-diff: Type-safe settings retrieval by ryanofsky)

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

  4. ajtowns commented at 1:41 AM on October 16, 2026: contributor

    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?

  5. stickies-v commented at 1:31 PM on October 16, 2026: contributor

    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?

  6. maflcko commented at 4:22 PM on October 16, 2026: member

    Concept ACK, per #16409 :sweat_smile:

  7. tumutech commented at 5:33 PM on October 16, 2026: none

    Concept ACK

  8. in src/txmempool.cpp:829 in d40e511d9d


    tumutech commented at 6:19 PM on October 16, 2026:

    @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 commented at 1:29 PM on November 3, 2026:

    Fixed, thanks.

  9. fametrano commented at 7:35 AM on October 25, 2026: none

    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.

  10. musaHaruna commented at 12:58 PM on October 27, 2026: contributor

    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.

  11. test: stop relying on mempool expiry in tests
    Rework the tests that exercise time-based mempool expiry so they no
    longer depend on it, before the feature is removed: trigger
    mempool:removed via RBF in the USDT test, check chain rebroadcast via
    peer invs in the wallet resend test, and drop the expiry knobs from the
    mempool fuzz targets.
    323cd0c2b0
  12. ismaelsadeeq force-pushed on Nov 3, 2026
  13. ismaelsadeeq commented at 1:28 PM on November 3, 2026: member

    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.

  14. ismaelsadeeq force-pushed on Nov 4, 2026
  15. 0xB10C commented at 10:22 PM on November 4, 2026: contributor

    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.

  16. mempool: remove time-based transaction expiry
    Evicting transactions purely by age (-mempoolexpiry, default two weeks)
    is incentive-incompatible: it can drop still-mineable transactions, such
    as a low-feerate parent waiting on a fee-bumping child. Remove it;
    -mempoolexpiry is kept as a no-op that warns when set.
    78c039ab16
  17. mempool: remove now-unused entry_time index and includes
    Expire() was the only reader of the entry_time index. Keeping it would
    cost an ordered-tree node per entry and an O(log n) update on every
    mempool insert/erase to maintain an ordering nothing uses, so drop the
    index along with its tag, comparator, and the boost headers only it
    needed. identity.hpp is then unused tree-wide, so also drop it from
    EXPECTED_BOOST_INCLUDES, and lower the DynamicMemoryUsage() per-entry
    estimate from three indexes to two so -maxmempool accounting stays
    accurate.
    
    Also move util/time.h into txmempool.h (it uses GetTime/chrono) instead
    of relying on mempool_options.h, and drop the unused <chrono> and
    <memory> from mempool_args.cpp.
    63d6cf1a53
  18. in doc/release-notes-36540.md:5 in 8a853c49eb
       0 | @@ -0,0 +1,5 @@
       1 | +Updated settings
       2 | +----------------
       3 | +
       4 | +- Time-based mempool expiry has been removed, and the `-mempoolexpiry` startup
       5 | +  option no longer has any effect (a warning is logged if it is set).
    


    fanquake commented at 11:29 AM on November 12, 2026:
      option no longer has any effect (a warning is logged if it is set). (#36540)
    

    ismaelsadeeq commented at 4:48 PM on November 16, 2026:

    Fixed

  19. ismaelsadeeq force-pushed on Nov 16, 2026
  20. ismaelsadeeq commented at 4:57 PM on November 16, 2026: member

    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

  21. ajtowns commented at 6:56 PM on November 16, 2026: contributor

    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.

  22. ismaelsadeeq commented at 9:22 AM on November 17, 2026: member

    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?

  23. Eunovo commented at 4:15 AM on November 19, 2026: contributor

    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 #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 #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
  24. ismaelsadeeq commented at 5:40 AM on November 19, 2026: member

    re: #36540 (comment)

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


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-19 19:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me