fix(seismic/txpool): rebuild recent block cache on next-height reorgs - #484
Draft
dieutx wants to merge 1 commit into
Draft
fix(seismic/txpool): rebuild recent block cache on next-height reorgs#484dieutx wants to merge 1 commit into
dieutx wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RecentBlockCache::updatetreated every head atcached_height + 1as a direct extension. Height adjacency alone does not prove chain continuity: after a reorg, the replacement chain can reach one block above the cached losing fork while the new tip's parent differs from the cached tip.In that case the fast path appended only the new tip and returned without rebuilding. Old-fork hashes remained cached, while hashes from the replacement segment were absent.
Why it matters
The txpool uses this cache to validate the
recent_block_hashcarried by Seismic transactions and to evict transactions made stale by a reorg. A stale cache can reject otherwise-valid transactions referencing replacement-chain blocks and delay removal of transactions that reference the losing fork until those hashes age out.Reproduction
RecentBlockCachewith old-fork blocks 8, 9, and 10.11 == cached_height + 1takes the append-only path without consulting the canonical hashes. The old hashes at heights 8 through 10 remain and the replacement hashes are missing.The added
test_update_next_height_reorg_triggers_rebuildencodes this scenario. Applied as a test-only change to base commit39d04d158da383324b12c2e3397b0b28f3c3ee36, it fails at the assertion that the old height-8 hash was removed. It passes with this fix and verifies that the cache contains the replacement window for heights 7 through 11.Fix
Pass the notified block's parent hash into the cache update. The O(1), callback-free append path now requires both adjacent height and parent continuity. An adjacent-height parent mismatch rebuilds the canonical window immediately.
Both the validator and freshness-maintenance callers now pass the sealed tip's actual parent hash.
Tests
cargo test -p reth-seismic-txpool recent_block_cache::tests::test_update_next_height_reorg_triggers_rebuild -- --exact— passcargo test -p reth-seismic-txpool— pass (32 tests plus doc tests)cargo clippy -p 'reth-seismic*' -p 'seismic-reth*' --lib --tests --no-deps -- -D warnings -W clippy::unwrap_used -W clippy::expect_used -W clippy::indexing_slicing -W clippy::panic -W clippy::unreachable -W clippy::todo— passcargo +nightly fmt --all --check— passcargo check --workspace— passRUSTFLAGS="-D warnings" cargo check— passMSRV 1.88, pinned workspace clippy 1.91.1, and workspace nextest were not run locally because those toolchains/tools are unavailable in the local environment; GitHub CI will provide those results.
dprintandzepterwere also unavailable locally; this change does not modify TOML, dependencies, or feature propagation.Risk
The change is limited to the recent-block cache update contract and its two production callers. Normal direct extensions retain the callback-free fast path; existing gap and same/lower-height reorg handling is unchanged. There are no consensus, storage-format, dependency, feature, or lookback-capacity changes.