Fix history reads migration - #3348
Open
vicsn wants to merge 7 commits into
Open
Conversation
Document the migration throughput harness and use the fastest tested batch size to reduce RocksDB startup migration time. Co-authored-by: Cursor <cursoragent@cursor.com>
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
ljedrz
approved these changes
Jul 31, 2026
Collaborator
There was a problem hiding this comment.
While the overall approach is fine (with the caveat already noted by Veria AI), I'd suggest an alternative, lower-level solution for greater speed and future applicability:
- don't read the ledger using the snarkVM types, just open RocksDB "raw"
- dump the map of interest (based on the expected prefix) to a file
- delete the existing map in its entirety (solves the issue mentioned by Veria AI)
- translate the map from the external file into the new format (could be on the fly), and batch-write it to the database (still in the raw format)
- the ledger can now be loaded
That being said, I wouldn't want to block this, so approving the current approach (with the aforementioned issue fixed).
ljedrz
approved these changes
Jul 31, 2026
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.
Motivation
The previous migration logic in #3323 was insufficient. This PR introduces a one-time synchronous db migration to overcome the performance issue.
"Any key that already had an entry in MappingUpdateHeightsMap before this patch was deployed stays on the old path forever — every new write does a full read-modify-write of the growing vector. For an archive node with months of accumulated history, almost all actively-updated keys (staking/credits mappings) already fall into this category, so nearly all hot writes stay on the slow path permanently."
Performance
Local benchmarking on macOS M2 Max shows we can do ~200k updates per second. Time scales roughly linearly with the total number of mapping keys and historical entries. In production we have 20M blocks (which each create a few entries) and 26M transactions (many of which create a few entries), which would predict at least ~5 minutes of migration time.
Test Plan