feat(sync): add unwinding support for chain reorganizations#323
Closed
kariy wants to merge 14 commits intofeat/full-node-wipfrom
Closed
feat(sync): add unwinding support for chain reorganizations#323kariy wants to merge 14 commits intofeat/full-node-wipfrom
kariy wants to merge 14 commits intofeat/full-node-wipfrom
Conversation
9f1a0c7 to
fb97356
Compare
09926a2 to
951a1fa
Compare
Implement functionality to handle chain reorganizations by unwinding blocks in the sync pipeline. When the pipeline receives a new tip that is smaller than its current tip, it can now revert the chain state back to a specific block number. The Stage trait has been extended with a new unwind method that accepts a target block number and removes all blocks after it, ensuring the database state reflects only the data up to the unwind point. Each stage implements unwinding differently based on its responsibilities. The Blocks stage removes block headers, hashes, transactions, and receipts from their respective tables. The Classes stage removes class declarations and artifacts for blocks after the unwind target. The StateTrie stage unwinding is left unimplemented as it requires more complex trie unwinding logic that maintains merkle tree invariants. All stages update their checkpoints after unwinding to maintain consistency. The implementation uses the existing database transaction abstraction to ensure atomicity of the unwind operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
8102308 to
81cb748
Compare
Member
Author
|
superseded by #337 |
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.
Implements unwinding support for the sync pipeline to handle chain reorganizations. When the pipeline detects that a new chain tip is smaller than the current tip, it needs to revert the blockchain state back to a specific block number. This is a critical feature for maintaining consensus in distributed systems where temporary forks can occur.
The implementation extends the Stage trait with an unwind method that each stage must implement according to its specific data storage patterns. The Blocks stage handles removal of block metadata, headers, and all associated transactions from the database. The Classes stage manages the cleanup of contract class declarations and their compiled artifacts. The StateTrie stage unwinding is intentionally left unimplemented with clear documentation noting that it requires complex merkle trie unwinding logic to maintain tree invariants, which is beyond the current scope.
Each unwinding operation is performed within a database transaction to ensure atomicity, and stage checkpoints are updated afterward to maintain consistency across the pipeline. This ensures that if the node crashes during unwinding, the database remains in a valid state.