Use journal instead of CacheKV for giga snapshot/rollback#3295
Open
Use journal instead of CacheKV for giga snapshot/rollback#3295
Conversation
|
Hey @codchen, Code Input detected this PR has a merge conflict. Some of the conflicts of this PR can be resolved with a semantic merge driver. Code Input can do that automatically: https://codeinput.com/r/EESR7EMMZd3 Let me know if you need more help with this conflict or how Code Input works. |
1608a35 to
48a18ad
Compare
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
48a18ad to
00974b3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3295 +/- ##
==========================================
+ Coverage 58.56% 58.58% +0.01%
==========================================
Files 2072 2072
Lines 208020 208095 +75
==========================================
+ Hits 121833 121909 +76
Misses 77413 77413
+ Partials 8774 8773 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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
giga/deps/xevm/state implemented Snapshot()/RevertToSnapshot() by stacking CacheMultiStore layers: each Snapshot() call wrapped the current context in a new cache, and RevertToSnapshot() restored an older context (dropping the outer cache) to undo KV-store writes. This meant N nested EVM snapshots within a single transaction produced N nested CacheMultiStore layers, with all the associated allocation and copy-on-write overhead. The transient/in-memory state (access lists, logs, refunds, transient storage, account status) was already journal-driven; only the persisted KV state relied on the CacheMultiStore trick.
Solution
Adopt the go-ethereum journal pattern for all state—both KV-stored and in-memory:
Event-manager isolation
Snapshot() pushes the current EventManager onto a stack and attaches a fresh one to the context. RevertToSnapshot() pops back to the snapshot's EM, discarding any events emitted inside the reverted range. Finalize() drains all surviving EMs (in order) into committedCtx.EventManager().
GetCommittedState
Previously read from snapshottedCtxs[0] (the context before the first stateDB-level CMS layer). Now reads from committedCtx, the original context saved at NewDBImpl time, which sits below the single stateDB CMS and therefore always reflects the pre-transaction committed state.
Other changes
Tests (snapshot_test.go, 20 new cases)