Skip to content

feat(sync): add unwinding support for chain reorganizations#323

Closed
kariy wants to merge 14 commits intofeat/full-node-wipfrom
karii/doj-1091-featsync-unwinding-support
Closed

feat(sync): add unwinding support for chain reorganizations#323
kariy wants to merge 14 commits intofeat/full-node-wipfrom
karii/doj-1091-featsync-unwinding-support

Conversation

@kariy
Copy link
Member

@kariy kariy commented Oct 14, 2025

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.

@kariy kariy marked this pull request as draft October 14, 2025 01:55
@kariy kariy force-pushed the karii/doj-1091-featsync-unwinding-support branch from 9f1a0c7 to fb97356 Compare October 17, 2025 20:28
@kariy kariy changed the base branch from feat/full-node to feat/full-node-wip October 17, 2025 20:28
@blacksmith-sh blacksmith-sh bot deleted a comment from kariy Oct 17, 2025
@kariy kariy force-pushed the feat/full-node-wip branch 6 times, most recently from 09926a2 to 951a1fa Compare October 23, 2025 21:03
kariy and others added 14 commits October 23, 2025 17:06
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>
@kariy kariy force-pushed the karii/doj-1091-featsync-unwinding-support branch from 8102308 to 81cb748 Compare October 23, 2025 21:14
@kariy
Copy link
Member Author

kariy commented Oct 23, 2025

superseded by #337

@kariy kariy closed this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant