[LLM Draft] Fetch: single-flight in-flight RPC slot fetches (tighter reimpl of #1070)#1072
Draft
msooseth wants to merge 1 commit into
Draft
[LLM Draft] Fetch: single-flight in-flight RPC slot fetches (tighter reimpl of #1070)#1072msooseth wants to merge 1 commit into
msooseth wants to merge 1 commit into
Conversation
Concurrent workers racing on the same uncached (block, addr, slot) used to each issue an identical eth_getStorageAt before the first result populated the cache. Route oracle slot reads through fetchSlotWithCache and add single-flight tracking keyed by resolved block, address, and slot, so concurrent callers wait for one shared fetch. This is a tighter reimplementation of the approach in #1070: the single-flight logic is a generic, mask-safe `singleFlight` combinator plus a reused `lookupSlotCache`, instead of a dedicated owner/waiter ADT and several helpers. The owner clears the key and wakes waiters even on (async) exception, so a failed fetch is retried by the next caller rather than deadlocking. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4 tasks
Collaborator
Author
|
Fully LLM-written, total YOLO, no manual review AT ALL yet. Will need 2 people to reivew. |
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.
Summary
Reduces redundant RPC load when multiple workers race on the same uncached storage slot, by giving slot fetches single-flight semantics: concurrent callers on the same
(block, address, slot)share oneeth_getStorageAtrequest instead of each issuing their own.This is a tighter reimplementation of #1070. Same behavior and same RPC-count reduction, but the single-flight logic is a generic,
mask-safesingleFlightcombinator plus a reusedlookupSlotCache, instead of a dedicated owner/waiter ADT and several one-shot helpers.What changed
fetchSlotWithCache— thePleaseFetchSlotbranch inoracleno longer hand-rolls its own cache-check/fetch/populate; it calls the shared cache path (which now also respects the failed-slot cache).singleFlight— a generic "run an action at most once per key, share the result" combinator. The owner runs the action, fills anMVar, and removes the key; waiters block on thatMVar. Wrapped inmaskwithtry, so the owner clears the key and wakes waiters even on (async) exception — a failed fetch is retried by the next caller rather than deadlocking.lookupSlotCache— the success/failure cache lookup, factored out and reused on both the fast path (cache hit, no lock) and the post-claim recheck (an owner may have just populated the cache).fetchSlotWithCacheUsing—fetchSlotWithCachewith the underlying RPC injected, so the concurrency tests drive it deterministically with no network.The in-flight key includes the resolved block, so reads at different fork blocks stay isolated (
BlockNumbergains anOrdinstance for the map key).Note on
FetchStatusfor waitersWaiters return the owner's
FetchSuccess val Freshas-is (this version drops theFresh -> Cachedrelabel that #1070 applied to waiters). Inside hevm this is invisible — the oracle ignores the status. The actual RPC still fires exactly once; only the per-callerFresh/Cachedlabel differs for the threads that waited.Motivation
During Echidna fork fuzzing, workers can race on the same uncached storage slot. Before this change each worker could issue its own identical
eth_getStorageAtbefore the first result populated the cache, causing avoidable duplicate RPC traffic and quickly hitting provider call limits.Testing
StorageTestsgroup (5 tests) green.Checklist
🤖 Generated with Claude Code