[dont merge] fix: re-evaluate queued txs when USDC balance slots change#379
Draft
[dont merge] fix: re-evaluate queued txs when USDC balance slots change#379
Conversation
Contributor
|
Adds queued sender reloading when USDC balance storage slots change in transaction pool maintenance. LGTM |
7e93e48 to
4af1931
Compare
## Summary - **Bug:** `SeismicBalanceHook` was calling `self.client.latest()` to read USDC balances, while the maintenance loop loaded native balance/nonce from a historical block snapshot (`history_by_block_hash`). This caused mixed-state reconciliation where nonce and native balance came from block B but USDC balance came from the chain tip, which could be a different block. - **Impact:** False promotions (tx appears fundable using future USDC) and false demotions (tx appears unfunded using stale USDC) during reorgs and dirty-account reloads. - **Fix:** Pass the same `StateProvider` the maintenance loop already opened into the `ChangedAccountsHook::transform` method. The Seismic hook no longer owns a client or opens its own state — it reads USDC storage from the snapshot it receives. ### Changes - `ChangedAccountsHook::transform` now takes `&dyn StateProvider` as its first argument - All 3 call sites in `maintain_transaction_pool_with_hook` open the correct historical state and pass it through - `SeismicBalanceHook` becomes a unit struct — no generic, no client field, no `latest()` call - No-op `()` impl updated to match the new signature ## Test plan - [x] `cargo check -p reth-transaction-pool -p reth-seismic-txpool -p reth-seismic-node` passes - [ ] Existing txpool tests pass - [ ] Manual verification: submit tx from USDC-funded account, trigger reorg, confirm pool state is consistent
a248354 to
f4d287b
Compare
When USDC predeploy storage slots change in a canonical update, queued transactions whose senders have affected balance slots must be re-evaluated. This adds extend_reload_queued_senders to the ChangedAccountsHook trait and implements it in SeismicBalanceHook to detect USDC slot mutations and mark the corresponding queued senders as dirty.
f4d287b to
036567b
Compare
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
When a block changes a sender's USDC predeploy balance, queued transactions from that sender need to be re-evaluated — their effective balance changed, so they may now be promotable (or demotable). Today the pool only re-evaluates senders whose native account state changed, so USDC-only balance updates are silently ignored and queued txs stay stuck.
Solution
Extend the
ChangedAccountsHooktrait with a new method,extend_reload_queued_senders, that lets the Seismic hook inspect theExecutionOutcomeand flag additional senders as dirty. The implementation:_balances[address]slot (keccak of the mapping key) is in that changed set.Changes
Commit 1 —
fix: reload queued senders on USDC storage changescrates/transaction-pool/src/maintain.rsextend_reload_queued_sendersto theChangedAccountsHooktrait (default no-op). Call it after both commit and reorg paths, passing the queued-sender set and execution outcomes. Addedqueued_senders()helper.crates/seismic/txpool/src/maintain.rsextend_reload_queued_sendersonSeismicBalanceHook. Addedqueued_senders_with_changed_usdc_slotsandchanged_usdc_storage_slotshelpers.crates/seismic/txpool/src/usdc.rsusdc_balance_storage_keypub(crate)so the hook can compute expected slot keys.Commit 2 —
test: add tests for queued-sender USDC slot reload logiccrates/seismic/txpool/src/maintain.rs