feat(migration): statehistory migration#3658
Open
MaksymMalicki wants to merge 4 commits into
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## maksym/headstate-migration #3658 +/- ##
==============================================================
- Coverage 76.18% 76.10% -0.09%
==============================================================
Files 400 408 +8
Lines 36571 36913 +342
==============================================================
+ Hits 27861 28091 +230
- Misses 6715 6792 +77
- Partials 1995 2030 +35 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5c0928e to
5a09f6c
Compare
0f8a352 to
c2eacce
Compare
fa47934 to
05dd000
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.
Summary
Adds the
statehistorymigration: rewrites the three deprecated contract history layouts (class-hash, nonce, per-slot storage) so each entry stores the post-update value at its block instead of the pre-update value. Gated behind the existing--new-stateflag. Depends on the headstate migration (consolidated Contract record) shipped in the sibling PR — the new layout readscontract.{ClassHash, Nonce}and the head storage trie as the "last value" source.How it works
Runs three sequential phases — class-hash, nonce, storage — each iterating the
Contractbucket. Four worker goroutines (ingestorCount) per phase walk one contract's deprecated entries at a time, shift them into the new layout in shareddb.Batches, andDeleteRangethe deprecated rows in the same batch. One committer drains batches to disk; a semaphore caps in-flight batches atingestorCount + 1.deploy_hentry on top of the shifted history, growing the count by one per replaced contract.0(the deploy default). Shift only; entry count per contract / per slot is unchanged.felt.Zero.What changes
migration/statehistory/package (migrator, three per-phase ingestors, sharedbaseIngestor, committer, counter, parse helpers, tests).node/migration.goas an optional migration gated bycfg.NewState, running after the headstate migration.Resume safety
(shouldRerun, ctx.Err()).Alternatives considered
Two earlier attempts were benchmarked and dropped:
Wipe + rewrite from state updates. Drop the deprecated history entirely and rebuild the new layout by replaying state updates block-by-block. Conceptually clean but the resulting writes touch every history bucket in a near-random order — pebble compaction has to merge many small per-block updates across overlapping key ranges, so compact pressure dominated runtime.
Per-address instead of per-phase. Loop over contracts once and run all three phases (class-hash, nonce, storage) inside the same per-contract worker, finishing each contract before moving on. Saves two passes over the
Contractbucket but interleaves writes to three different history buckets per contract — again scattered, again heavy on compaction.The current per-phase approach writes are tightly clustered: one phase writes only one history bucket, in contract-address order, with deprecated
DeleteRanges landing in the same batch as the new rows that replace them. Sequential, large, mostly-sorted writes — pebble's happy path. The two extra Contract-bucket scans are negligible compared to the compaction savings.