trie/archiver: streaming archival + pathdb journal consistency#567
Merged
gballet merged 4 commits intogballet:archival-commandfrom Mar 11, 2026
Merged
trie/archiver: streaming archival + pathdb journal consistency#567gballet merged 4 commits intogballet:archival-commandfrom
gballet merged 4 commits intogballet:archival-commandfrom
Conversation
Replace the recursive approach that loaded the entire trie into memory with a streaming NodeIterator-based approach: - processTrie now uses NodeIterator to walk the trie node-by-node - probeHeight reads nodes from raw DB, computes height bounded at 3, and discards decoded nodes immediately (no in-memory trie buildup) - collectSubtree only materializes the bounded height-3 subtree being archived (at most ~4096 nodes) - Memory usage: O(iterator_stack) + O(current_subtree) instead of O(entire_trie) This fixes OOM kills on large storage tries (e.g. contracts with millions of storage slots) where the previous approach would load all nodes and subtreeInfo into memory before archiving any of them.
Instead of deleting the pathdb journal after archive generation (which breaks the chain head and prevents block imports), properly integrate with pathdb: 1. Open triedb with pathdb support (not just raw KV) 2. Disable state history freezer (avoid append gaps) 3. Flush all diff layers to disk via Commit() before archiving 4. After archiving, re-journal the pathdb state (disk layer only) This ensures geth can restart cleanly after archiving and continue importing blocks without 'unknown ancestor' errors.
2e4cbf9 to
2dce6ab
Compare
2dce6ab to
8447505
Compare
gballet
reviewed
Mar 11, 2026
| // height == 3: collect and archive this subtree immediately. | ||
| info := a.collectSubtree(owner, path, hash) | ||
| if info == nil { | ||
| continue |
Owner
There was a problem hiding this comment.
kinda weird that info is nil and we just silently skip it
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
Two fixes for
archive generate:1. Streaming subtree archival (fix OOM)
The previous recursive approach loaded the entire trie into memory before archiving any subtree. For large storage tries (contracts with millions of slots), this caused OOM kills.
Fix: NodeIterator-based streaming approach:
probeHeight(): bounded raw DB reads, discards decoded nodescollectSubtree(): materializes only the bounded height-3 subtreeO(iterator_stack + current_subtree)vsO(entire_trie)Result: RSS stable at 2 MB (vs OOM at 22 GB). ~3h on Hoodi.
2. Flush diff layers + re-journal (fix block import)
After archiving,
geth importfailed with:unknown ancestor: journal deleted, chain head lostout-order append: state history freezer gapstriedb layer missing: re-journal used stale rootFix:
Commit()before archivingDisableStateHistory()Result: 1020 blocks imported successfully after archiving (~265 mgasps).
Test results (Hoodi, 22 GB RAM)