fix(anvil): update fee history cache synchronously during mining#13784
Open
decofe wants to merge 1 commit intofoundry-rs:masterfrom
Open
fix(anvil): update fee history cache synchronously during mining#13784decofe wants to merge 1 commit intofoundry-rs:masterfrom
decofe wants to merge 1 commit intofoundry-rs:masterfrom
Conversation
a90b3a5 to
c73de21
Compare
Fixes a race condition where eth_feeHistory returns incomplete results when called shortly after blocks are mined. The fee history cache was populated asynchronously by FeeHistoryService, creating a window where RPC calls observe a stale cache. Now the cache is updated synchronously inside do_mine_block() before notify_on_new_block(), guaranteeing consistency with the chain head. Closes foundry-rs#13680 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019cfba7-4986-77c6-9630-574261e9d580
c73de21 to
73ce3e7
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
eth_feeHistorycan return fewer entries than requested when called right after a block is mined.The fee history cache is populated by
FeeHistoryService, which runs as a separateFutureinsideNodeService::poll. The timeline looks like:do_mine_block()stores the block inBlockchainStoragedo_mine_block()callsnotify_on_new_block()— sends a notification on a channeleth_feeHistoryreads the cache here, before step 4 runs →FeeHistoryService::pollreceives the notification and updates the cacheDuring step 3, the new block exists in storage (so
best_numberis incremented), but the cache hasn't been updated yet.eth_feeHistorysees the new block number, tries to look it up in the cache, finds nothing, silently skips it, and returns a short response.Fix
Share the
FeeHistoryCachebetweenBackendandFeeHistoryService. Update it synchronously indo_mine_block()beforenotify_on_new_block(), closing the race window. The asyncFeeHistoryServicestill runs but becomes a no-op for already-cached blocks.Closes #13680