Skip to content

Commit

Permalink
feat(papyrus_storage): add revert class manager marker
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Feb 5, 2025
1 parent 1de3775 commit 9dc2f88
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions crates/papyrus_storage/src/class_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! TODO(DanB): Add Documentation
use starknet_api::block::BlockNumber;

use crate::db::table_types::Table;
Expand All @@ -21,7 +20,12 @@ where
// To enforce that no commit happen after a failure, we consume and return Self on success.
fn update_class_manager_block_marker(self, block_number: &BlockNumber) -> StorageResult<Self>;

// TODO(DanB): add revert functionality
/// When reverting a block, if the class manager marker points to the block afterward, revert
/// the marker.
fn try_revert_class_manager_marker(
self,
reverted_block_number: BlockNumber,
) -> StorageResult<Self>;
}

impl<Mode: TransactionKind> ClassManagerStorageReader for StorageTxn<'_, Mode> {
Expand All @@ -41,4 +45,16 @@ impl ClassManagerStorageWriter for StorageTxn<'_, RW> {
)?;
Ok(self)
}

fn try_revert_class_manager_marker(
self,
reverted_block_number: BlockNumber,
) -> StorageResult<Self> {
let cur_marker = self.get_class_manager_block_marker()?;
if cur_marker == reverted_block_number.unchecked_next() {
Ok(self.update_class_manager_block_marker(&reverted_block_number)?)
} else {
Ok(self)
}
}
}

0 comments on commit 9dc2f88

Please sign in to comment.