mempool: remove time-based transaction expiry

bitcoin/bitcoin: PR #36540

1 minor finding · 6 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[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).

Details and suggested fix

restart_node() waits for responsive RPC and getmempoolinfo()["loaded"], neither of which waits for wallet resubmission. With -persistmempool=0, the loader immediately skips the file and can mark loading attempted before the wallet starts. AppInitMain() ends RPC warmup before calling StartWallets(), whose postInitProcess() submits the parent and child individually. Keep the child txid returned by sendall() and replace the immediate assertion with self.wait_until(lambda: set(node.getrawmempool()) == {txid, child_txid}). A short wait still detects child-first startup submission: the restarted wallet's next periodic resend is 12–36 hours away.


Optional improvements

Link

[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).

Details and suggested fix

A transaction can pass this node's standardness checks, including its -datacarriersize limit, while miners exclude it. Reloading under unchanged local policy need not reject it, and TrimToSize() removes nothing below the memory cap. Under pressure, high-feerate entries of this kind can displace lower-feerate transactions that miners would accept. The base removed aged entries at the next maintenance call, a documented purpose of expiry. Peers or wallets could reintroduce them, and size eviction can still remove them, so expiry was only an opportunity for unattended local recovery. Explain whether operator upgrades now replace that turnover and why losing it is acceptable; otherwise consider a narrower turnover mechanism.


Link

[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).

Details and suggested fix

The existing persistence test compares metadata for fresh wall-clock entries. The rewritten USDT test replaces immediately, while the wallet restart disables persistence and supplies transactions from the wallet. Reuse the old parent/newer-child fixture, advance mocktime past 336 hours, and admit an independent transaction well below -maxmempool. Assert that both transactions remain with their original entry times. Then restart with persistence enabled, the wallet disabled, no peer resubmission, and the advanced startup mocktime preserved. Check the same txids and timestamps again. These assertions would separately detect restoration of runtime expiry or the load-time age filter.


Link

[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).

Details and suggested fix

Startup calls ResubmitWalletTransactions() with force=true and no relay. Periodic resubmission uses force=false, including the five-minute last-block-time filter, and requests relay. The remaining scheduled checks keep their transactions in the pool, so BroadcastTransaction() can reannounce them without attempting admission. Add coverage with an absent, time-eligible parent/child chain and force=false, for example in a wallet unit fixture with the required chain and broadcast context. Wallet transactions can still need this recovery after size eviction. Also create several independent pairs before the single startup restart and assert their expected txid set: mapWallet is a salted unordered_map, so one pair can happen to be visited parent-first even if the WalletTxOrderComparator sort is lost.


Link

[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).

Details and suggested fix

The base documents -mempoolexpiry=<n> as a public startup option and applies its value. This change hides it, removes the underlying setting, and immediately makes it a no-op. Keeping configurations parseable does not preserve an operator's chosen retention policy. doc/developer-notes.md specifies a one-major-release grace period for feature removal. Either document immediate removal as a deliberate exception with operator migration guidance, or make expiry disabled by default while honoring explicit opt-in settings for one transition release. The latter retains the index or requires another traversal mechanism, plus tests, and postpones the memory savings.


Link

[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).

Details and suggested fix

Previously, LoadMempool() skipped entries older than -mempoolexpiry before taking cs_main. It now calls AcceptToMemoryPool() for each saved entry, potentially reaching script checks. Startup loading follows local block import and can run while network catch-up is still pending. Transactions accepted against that older tip may subsequently be removed as missed blocks connect, adding admission work and lock contention that the old filter avoided. Mention this startup-cost tradeoff in the release note. Restoring a fixed age cutoff would undermine the intended retention behavior, so documentation is the behavior-preserving correction.


Link

[suggestion] · Test-preparation message describes a chain relay check that is absent

Commit 323cd0c2 says it checks chain rebroadcast through peer invs, but its replacement scenario checks startup mempool restoration without relay.

Location: test/functional/wallet_resendwallettransactions.py:79 at 323cd0c2b022 (commit) (commit).

Details and suggested fix

The message for 323cd0c2b022661817a3d9c27e780c6dd62622c3 (test: stop relying on mempool expiry in tests) says “check chain rebroadcast via peer invs.” Its changed chain section instead restarts with -persistmempool=0 and checks getmempoolinfo()["size"]; the existing wait_for_broadcast() calls cover single transactions. Startup resubmission uses MEMPOOL_NO_BROADCAST. Update the message to say that scheduled readmission of an evicted chain is replaced by a startup parent-before-child resubmission check, rather than implying chain relay remains covered. The test-preparation commit boundary can stay unchanged.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Expiry originated partly as protection against high-feerate transactions that occupy the mempool without confirming, rather than simply against excessive transaction count or memory use.

In the 2015 design discussion, Pieter Wuille identified the danger of high-fee but unconfirming transactions driving relay fees upward and considered time-based expiration as a response. In 2016, Alex Morcos explained that expiry also eventually clears transactions when mining policy differs from local mempool policy. This is a distinct purpose from the retained TrimToSize mechanism, which acts only when the configured memory limit is exceeded.

Source 1 · Source 2

The decision to extend expiry from three days to two weeks explicitly favored retaining economically useful low-fee transactions, reducing repeated relay, and observing longer confirmation horizons.

The proposal said three days was already too slow to resist an attack involving high-feerate but unmineable transactions. Longer retention would instead let transactions benefit from weekly demand cycles, reduce rerelay traffic, and support future low-priority fee estimates. This is direct historical support for distinguishing long waiting time from lack of mining value, while not treating expiry as a strong adversarial defense.

Source 1 · Source 2

Size-based eviction and its rolling fee floor were designed together to bound memory while limiting bandwidth churn; the fee floor's decay balances two opposing attacks.

The original size-limiting discussion describes evicting low-feerate transaction/dependent sets and raising the admission floor above the removed set. Morcos explained that future transactions should help pay for relay of evicted transactions, otherwise a small transaction could repeatedly displace large packages. Conversely, the floor must decay so a single expensive mempool fill cannot hold admission fees high indefinitely. The pinned head retains this structure in src/txmempool.cpp:859–941, now using the worst transaction-graph chunk. These decisions explain memory and churn defenses, not an unlimited-retention guarantee.

Source 1 · Source 2

Persisted-entry age filtering was introduced as an optimization that preserved the existing expiry policy, avoiding work on entries that would already have expired.

During mempool persistence development, the discussion considered ignoring an old dump to avoid loading already-confirmed transactions or low-fee spam. Wuille proposed skipping individually expired entries instead, calling it equivalent in effect and a pure optimization. The subsequent update reported that skipping expired entries made loading a week-old dump instantaneous. In the pinned base, src/node/mempool_persist.cpp:103–120 filters by age before AcceptToMemoryPool; the head removes that shortcut but still submits each entry with bypass_limits=false. Thus the historical age filter had a startup-work rationale as well as continuity with runtime expiry.

Source 1 · Source 2 · Source 3 · Source 4

Preserving mempool contents across restarts was justified by retained mining opportunities and reduced network resource consumption, not merely faster application startup.

The persistence discussion connected retained transactions to miner fee revenue, compact-block reconstruction, and avoiding a large remote mempool transfer after every restart. It also emphasized that remote synchronization has unpredictable resource costs. These goals favor preserving useful long-lived transactions, but coexist with the separate optimization of skipping expired entries. The head continues saving transactions, timestamps, fee deltas, and unbroadcast state; it changes which saved entries are attempted on load.

Source 1 · Source 2 · Source 3 · Source 4

Expiry was never a reliable network-wide cancellation mechanism, and wallet rebroadcast was already understood to undo local expiration.

Gregory Maxwell observed that listening nodes receive old transactions again from third parties. Morcos described wallet transactions being reaccepted on restart or periodically, warned that simply abandoning expired transactions was unsafe advice, and presented special handling or fee bumping after expiry only as possible future behavior. The pinned wallet still independently resubmits unconfirmed transactions on startup and periodically, in insertion order, in src/wallet/wallet.cpp:1903–1955. Removing mempool expiry therefore changes retention policy, not the protocol validity or cancellation status of a signed transaction.

Source 1 · Source 2 · Source 3 · Source 4

Ralph's inferences

The inspected history establishes complementary defenses, not a prior decision that memory bounds, fee policy, and revalidation are complete substitutes for age limits.

Size trimming bounds memory and discourages churn; reload validation checks acceptability under the restarting node's rules; expiry supplied eventual turnover even without memory pressure or agreement with miners' policy. A transaction can pass local revalidation while remaining unattractive to miners using different policy. This distinction follows from the stated historical goals and the pinned code, rather than constituting a finding about this PR.

Source 1 · Source 2 · Source 3 · Source 4

Restart recovery and continued network propagation are separate responsibilities; removing persisted-entry age filtering does not itself establish either guaranteed restoration or successful rebroadcast.

The head still routes saved entries through ordinary admission with limits enabled, and restores unbroadcast status only for transactions accepted into the pool. Wallet startup submission is a separate path and deliberately does not request immediate relay. Together with the historical warnings about rebroadcast and cancellation, this means retention, readmission, and propagation should not be treated as equivalent historical guarantees.

Source 1 · Source 2 · Source 3

Unresolved disagreements

An earlier proposal to remove expiry was withdrawn after objections that replacement fees and policy divergence gave expiry purposes beyond memory limiting; the inspected record does not show those objections subsequently resolved.

PR #16409 argued for retaining long-term miner revenue and avoiding rebroadcast that merely resets an expiry timer. Wuille countered that expiry permits a later submission without replacement's marginal relay charge. Suhas Daftuar highlighted both large-descendant RBF pinning and old nodes retaining transactions rejected by newer mining policy. The author acknowledged the descendant-fee consequence and closed the proposal following that feedback. The counterargument was that periodic retransmission can defeat expiry anyway. This precedent identifies the tradeoffs without proving their present applicability or resolution.

Source 1 · Source 2 · Source 3 · Source 4 · Source 5 · Source 6 · Source 7

The historical discussion recognized a tension between expiring an old ancestor and preserving a recent child that makes its package worth mining, but did not establish a settled age-based resolution.

In issue #33510, Wuille explicitly asked whether a recent CPFP child should keep an old parent alive, since expiring the parent also requires removing descendants. Another participant argued that allowing children to extend retention could sustain growing packages. The pinned base implements unconditional descendant removal in CTxMemPool::Expire, regardless of their newer arrival times; the head removes this age-based decision entirely. The retrieved discussion frames the incentive/resource tension but does not demonstrate that later package or cluster-policy decisions settled all of it.

Source 1 · Source 2