execution/cache: wire RevertWithDiffset into unwind path#20516
Merged
execution/cache: wire RevertWithDiffset into unwind path#20516
Conversation
RevertWithDiffset was implemented but never called — the state cache was not invalidated during unwinds, surviving only because ValidateAndPrepare cleared it on the next block (hash mismatch). Wire RevertWithDiffset into unwindExec3 so that keys touched by the unwound blocks are surgically evicted from the cache immediately after the domain state is rewound. Untouched keys remain cached. The lastExecHash (already fetched for this purpose) detects if the cache was modified by a different execution path, falling back to a full clear. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AskAlexSharov
approved these changes
Apr 13, 2026
yperbasis
added a commit
that referenced
this pull request
Apr 13, 2026
Each ValidateChain call opens a fresh RwTx that is rolled back after validation completes. The shared state cache may hold values written during a previous validation on a now-rolled-back tx. When the next validation creates a fresh SharedDomains backed by a new tx, stale cache entries are returned by GetLatest before the backing tx is consulted, causing the parallel executor to see incorrect state (e.g. nonce=1 instead of nonce=0 for a sender at genesis). Clear the state cache at the start of each ValidateChain so execution reads authoritative state from the backing tx. Note: this is distinct from the unwind-path cache invalidation in PR #20516 (RevertWithDiffset). That PR handles keys modified during an unwound execution range within the same tx. This fix handles cross-validation staleness where the previous tx was rolled back entirely. Fixes TestEngineApiExecBlockBatchWithLenLtMaxReorgDepthAtTipThenUnwindShouldSucceed which fails when EXEC3_PARALLEL=true. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
RevertWithDiffsetintounwindExec3so the state cache is surgically invalidated during unwinds — keys touched by the unwound blocks are evicted, untouched keys remain cachedRevertWithDiffsetwas implemented but never called; the cache survived unwinds only becauseValidateAndPreparecleared it on the next block (hash mismatch fallback)lastExecHash(already fetched with a comment anticipating this wiring) detects if the cache was modified by a different execution path (e.g. rolled-backValidatePayload), falling back to a full clearContext
Follow-up to #20265 and #20483. Those PRs fixed correctness bugs in the cache layer and domain unwind; this PR completes the picture by actually invalidating the cache during unwinds rather than relying on the next-block safety net.
Test plan
TestRevertWithDiffset_SurgicalEviction— touched keys evicted, untouched preserved, blockHash updatedTestRevertWithDiffset_HashMismatch_ClearsAll— mismatched revertFromHash triggers full clearTestRevertWithDiffset_AccountChange_EvictsCode— account diffs also evict corresponding code entriesTestRevertWithDiffset_ThenValidateAndPrepare_Continuity— end-to-end: surgical revert then re-execution preserves surviving cache datamake lintclean🤖 Generated with Claude Code