Repository navigation
mempool: remove time-based transaction expiry - #36540
ismaelsadeeq wants to merge 3 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
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 |
|
Concept ACK Node operators should assume that at any point in time, and for any duration of time, their mempool can consume up to 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 #16409 😅 |
|
Concept ACK |
|
Two things look unfinished: the memory estimate still counts three indexes, and tumutech's inline question on the first is still open. Could this PR use 6 pointers, as tumutech suggests, or drop the "fits slightly more transactions" sentence? For the test, restarting with 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 |
musaHaruna
left a comment
There was a problem hiding this 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.
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.
1556184 to
2eb3d48
Compare
|
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. |
2eb3d48 to
8a853c4
Compare
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. |
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.
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.
8a853c4 to
63d6cf1
Compare
@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. |
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 #33510 (comment)?
|
|
re: #36540 (comment)
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 #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 #36540 (comment) 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 #36540 (comment)
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: |

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