This repository was archived by the owner on Jan 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
feat(supervisor/core): Handle unsafe reorg #2498
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eb01136
implemented rewinder for log storage
sadiq1971 9d937fc
added method to metrix
sadiq1971 6ce5852
merged main
sadiq1971 4fb77c0
rewind_from -> rewind_to
sadiq1971 a8b2dbd
Merge branch 'main' of github.com:op-rs/kona into sa/feat/log-storage…
sadiq1971 40e25aa
added non working implementation
sadiq1971 35b8c4e
bug fix and test case added
sadiq1971 73a3002
merged main
sadiq1971 ca490f4
error return modified
sadiq1971 e6bd684
removed unwanted changes
sadiq1971 53f1e25
merged main
sadiq1971 d9404c9
added chain rewinder
sadiq1971 6cb2a16
merged main
sadiq1971 a56586b
merged main
sadiq1971 ef5de72
removed storage changes
sadiq1971 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| use alloy_primitives::ChainId; | ||
| use derive_more::Constructor; | ||
| use kona_interop::DerivedRefPair; | ||
| use kona_supervisor_storage::{LogStorageReader, StorageError, StorageRewinder}; | ||
| use thiserror::Error; | ||
| use tracing::{error, info, warn}; | ||
|
|
||
| /// Initiates supervisor-level rewinds based on chain events or storage conflicts. | ||
| /// | ||
| /// This coordinates per-chain rewind logic using the underlying [`StorageRewinder`] implementation, | ||
| /// and encapsulates the context in which rewinds should occur. | ||
| /// | ||
| /// It is used in response to: | ||
| /// - Local derivation conflicts (failure updating supervisor state) | ||
| /// - L1-originated reorgs affecting derived state | ||
| #[derive(Debug, Constructor)] | ||
| pub struct ChainRewinder<DB> { | ||
| chain_id: ChainId, | ||
| db: DB, | ||
| } | ||
|
|
||
| #[expect(dead_code)] // todo: to be removed in the follow up PR | ||
| impl<DB> ChainRewinder<DB> | ||
| where | ||
| DB: StorageRewinder + LogStorageReader, | ||
| { | ||
| /// Handles a local reorg by rewinding supervisor state from the conflicting derived pair. | ||
| /// | ||
| /// This is triggered when an update to supervisor storage fails due to an | ||
| /// integrity violation (e.g., mismatched on storing local safe block hash). | ||
| fn handle_local_reorg(&self, derived_pair: &DerivedRefPair) -> Result<(), StorageError> { | ||
| warn!( | ||
| target: "rewinder", | ||
| chain = %self.chain_id, | ||
| derived_block = %derived_pair.derived, | ||
| "Local derivation conflict detected — rewinding..." | ||
| ); | ||
| // get the same block from log storage | ||
| let conflicting_block = | ||
| self.db.get_block(derived_pair.derived.number).inspect_err(|err| { | ||
| error!( | ||
| target: "rewinder", | ||
| chain = %self.chain_id, | ||
| block_number = derived_pair.derived.number, | ||
| %err, | ||
| "Error retrieving conflicting block for reorg" | ||
| ); | ||
| })?; | ||
|
|
||
| // cross-check whether the block is conflicting | ||
| if conflicting_block == derived_pair.derived { | ||
| return Ok(()) | ||
| } | ||
|
|
||
| // rewind the log storage to remove all the blocks till the conflicting one | ||
| self.db.rewind_log_storage(&conflicting_block.id()).inspect_err(|err| { | ||
| error!( | ||
| target: "rewinder", | ||
| chain = %self.chain_id, | ||
| block_number = derived_pair.derived.number, | ||
| %err, | ||
| "Error rewinding the log storage" | ||
| ); | ||
| })?; | ||
|
|
||
| // todo: sync the log storage - to prevent a reset | ||
| // todo: save the derived_pair - now it should succeed | ||
|
|
||
| info!( | ||
| target: "rewinder", | ||
| chain = self.chain_id, | ||
| "Rewind successful after local derivation conflict" | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Handles a rewind due to an L1 reorg. | ||
| /// | ||
| /// This method is expected to revert supervisor state based on the L1 reorg by finding the new | ||
| /// valid state and removing any derived data that is no longer valid due to upstream | ||
| /// reorganization. | ||
| fn handle_l1_reorg(&self) -> Result<(), StorageError> { | ||
| warn!( | ||
| target: "rewinder", | ||
| chain = self.chain_id, | ||
| "L1 reorg handling is not yet implemented. Skipping rewind." | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Error type for the [`ChainRewinder`]. | ||
| #[derive(Error, Debug, PartialEq, Eq)] | ||
| pub enum ChainRewinderError { | ||
| /// Failed on storage operations | ||
| #[error(transparent)] | ||
| StorageError(#[from] StorageError), | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //! Rewinder module for reverting supervisor state during re-org | ||
|
|
||
| mod chain; | ||
|
|
||
| pub use chain::{ChainRewinder, ChainRewinderError}; |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.