3 suggestions
Optional improvements
[suggestion] · Reorg coverage misses eviction after a valid-cache failure
The reorg tests would not catch a fallback that retains a transaction whose maxInputBlock survives but whose recalculated sequence locks still fail.
Location: test/functional/feature_bip68_sequence.py:432 (head).
Details and suggested fix
MaybeUpdateMempoolForReorg now recalculates when TestLockPointValidity succeeds but the cached sequence-lock check fails. All four new cases assert retention; the older negative reorg cases disconnect the input's confirming block and exercise invalid-cache handling instead. Add a separate non-coinbase output alongside mixed_funding in block H-1, where H is the height of block_setup, then submit its version-2, nLockTime=0 spend with sequence=2 at tip H. Its lock height is H, so it passes for next height H+1. Invalidating block_setup preserves maxInputBlock but makes both cached and fresh checks fail against next height H. Assert that the spend leaves the mempool. The implementation currently evicts it correctly; this guards against a future overly permissive fallback.
[suggestion] · The valid-cache fallback lacks its stale-lockpoint rationale
The adjacent comment does not explain why a successful TestLockPointValidity check can still require recalculation before eviction.
Location: src/validation.cpp:353 (head).
Details and suggested fix
TestLockPointValidity only tests whether maxInputBlock remains on the active chain. Mempool inputs contribute heights relative to tip+1 and, for time locks, the tip's MTP, but do not contribute to maxInputBlock. An all-unconfirmed transaction can therefore retain a genesis maxInputBlock, or a mixed-input transaction a surviving confirmed block, while its cached check uses the old tip. Document that interaction above this condition: a failed cached check after a reorg is not enough to evict, so recalculate against the new tip first. The adjacent comment currently explains only next-block finality.
[suggestion] · Direct broadcast leaves MiniWallet with spent inputs
Broadcasting child_mixed through the node leaves two spent outputs in MiniWallet's UTXO list, which later reuse without a rescan could select.
Location: test/functional/feature_bip68_sequence.py:430 (head).
Details and suggested fix
Creating child_mixed with explicit utxos_to_spend does not pop either input from the wallet. node.sendrawtransaction then bypasses MiniWallet.sendrawtransaction and its scan_tx, leaving mixed_funding["new_utxo"] and child_b["new_utxo"] in self.wallet._utxos after they are spent. Subsequent mining uses TestNode, and reconsidering blocks or synchronizing does not rescan MiniWallet. The current remaining test uses a separate wallet, but a future use of self.wallet could select a spent input and have its transaction rejected. Broadcast with self.wallet.sendrawtransaction(from_node=node, tx_hex=child_mixed["hex"]) so scan_tx updates the input and output bookkeeping after acceptance.