diff --git a/Cargo.lock b/Cargo.lock index d12a2c0c223..148d8f32c3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -926,6 +926,7 @@ dependencies = [ "serde", "starknet-types-core", "starknet_api", + "starknet_committer", "strum", "tempfile", "thiserror 1.0.69", diff --git a/crates/apollo_batcher/Cargo.toml b/crates/apollo_batcher/Cargo.toml index ab4d3b006d5..0adf50771d3 100644 --- a/crates/apollo_batcher/Cargo.toml +++ b/crates/apollo_batcher/Cargo.toml @@ -42,6 +42,7 @@ lru.workspace = true reqwest = { workspace = true, features = ["json"] } serde.workspace = true starknet_api.workspace = true +starknet_committer.workspace = true strum = { workspace = true, features = ["derive"] } thiserror.workspace = true tokio.workspace = true diff --git a/crates/apollo_batcher/src/batcher.rs b/crates/apollo_batcher/src/batcher.rs index 750cc75f084..8b279ca9cb6 100644 --- a/crates/apollo_batcher/src/batcher.rs +++ b/crates/apollo_batcher/src/batcher.rs @@ -67,11 +67,6 @@ use apollo_storage::partial_block_hash::{ PartialBlockHashComponentsStorageWriter, }; use apollo_storage::state::{StateStorageReader, StateStorageWriter}; -use apollo_storage::state_commitment_infos::{ - CompressedStateCommitmentInfos, - StateCommitmentInfosStorageReader, - StateCommitmentInfosStorageWriter, -}; use apollo_storage::storage_reader_server::{ DynamicConfigError, DynamicConfigProvider, @@ -127,6 +122,7 @@ use starknet_api::core::{ContractAddress, GlobalRoot, Nonce, StateDiffCommitment use starknet_api::state::{StateNumber, ThinStateDiff}; use starknet_api::transaction::fields::Calldata; use starknet_api::transaction::TransactionHash; +use starknet_committer::patricia_merkle_tree::types::CompressedStateCommitmentInfos; use tokio::sync::{Mutex, Semaphore}; use tokio::task::AbortHandle; use tracing::{debug, error, info, instrument, trace, warn, Instrument}; @@ -1627,33 +1623,20 @@ impl Batcher { Ok(block_hash) } + /// Serves the state commitment infos of recently committed heights from memory. `None` means + /// the height is not cached: not committed yet, committed without accessed keys, or older than + /// the cache window. pub fn get_state_commitment_infos( &mut self, block_number: BlockNumber, ) -> BatcherResult> { self.get_commitment_results_and_write_to_storage()?; - if let Some(state_commitment_infos) = - self.commitment_manager.recent_state_commitment_infos_cache.get(&block_number) - { - return Ok(Some(state_commitment_infos.clone())); - } - - self.storage_reader.get_state_commitment_infos(block_number).map_err(|err| { - error!("Failed to get state commitment infos from storage: {err}"); - BatcherError::InternalError - }) + Ok(self.commitment_manager.recent_state_commitment_infos_cache.get(&block_number).cloned()) } pub fn has_state_commitment_infos(&mut self, block_number: BlockNumber) -> BatcherResult { self.get_commitment_results_and_write_to_storage()?; - if self.commitment_manager.recent_state_commitment_infos_cache.contains(&block_number) { - return Ok(true); - } - - self.storage_reader.has_state_commitment_infos(block_number).map_err(|err| { - error!("Failed to check state commitment infos existence in storage: {err}"); - BatcherError::InternalError - }) + Ok(self.commitment_manager.recent_state_commitment_infos_cache.contains(&block_number)) } /// Warms the state commitment infos cache from the committer with the heights in @@ -1902,14 +1885,6 @@ pub trait BatcherStorageReader: Send + Sync { fn get_block_hash(&self, height: BlockNumber) -> StorageResult>; - fn get_state_commitment_infos( - &self, - height: BlockNumber, - ) -> StorageResult>; - - /// Returns whether the state commitment infos for the given height are stored. - fn has_state_commitment_infos(&self, height: BlockNumber) -> StorageResult; - fn get_parent_hash_and_partial_block_hash_components( &self, height: BlockNumber, @@ -2006,17 +1981,6 @@ impl BatcherStorageReader for StorageReader { self.begin_ro_txn()?.get_block_hash(&height) } - fn get_state_commitment_infos( - &self, - height: BlockNumber, - ) -> StorageResult> { - self.begin_ro_txn()?.get_state_commitment_infos(height) - } - - fn has_state_commitment_infos(&self, height: BlockNumber) -> StorageResult { - self.begin_ro_txn()?.has_state_commitment_infos(height) - } - fn get_parent_hash_and_partial_block_hash_components( &self, height: BlockNumber, @@ -2057,17 +2021,14 @@ pub trait BatcherStorageWriter: Send + Sync { fn revert_block(&mut self, height: BlockNumber); - /// Sets the global root and block hash (unless it's None) for the given height, and persists - /// the commitment infos (when present) in the same transaction. + /// Sets the global root and block hash (unless it's None) for the given height. /// Increments the block hash marker by 1. /// Block hash is optional because for old blocks, the block hash was set separately. - /// Commitment infos are optional for blocks that doesn't come from decision_reached flow. fn set_global_root_and_block_hash( &mut self, height: BlockNumber, global_root: GlobalRoot, block_hash: Option, - state_commitment_infos: Option, ) -> StorageResult<()>; fn set_block_hash(&mut self, height: BlockNumber, block_hash: BlockHash) -> StorageResult<()>; @@ -2112,14 +2073,10 @@ impl BatcherStorageWriter for StorageWriter { height: BlockNumber, global_root: GlobalRoot, block_hash: Option, - state_commitment_infos: Option, ) -> StorageResult<()> { info!( "Setting global root and block hash for height {height}. Root: {global_root:?}, Block \ - hash: {block_hash:?}, compressed commitment infos byte length: {:?}.", - state_commitment_infos - .as_ref() - .map(|state_commitment_infos| state_commitment_infos.payload.0.len()) + hash: {block_hash:?}." ); let mut txn = self .begin_rw_txn()? @@ -2128,9 +2085,6 @@ impl BatcherStorageWriter for StorageWriter { if let Some(block_hash) = block_hash { txn = txn.set_block_hash(&height, block_hash)?; } - if let Some(state_commitment_infos) = state_commitment_infos { - txn = txn.append_state_commitment_infos(height, &state_commitment_infos)?; - } txn.commit() } diff --git a/crates/apollo_batcher/src/batcher_test.rs b/crates/apollo_batcher/src/batcher_test.rs index 1d71c916024..2cbee5ede6a 100644 --- a/crates/apollo_batcher/src/batcher_test.rs +++ b/crates/apollo_batcher/src/batcher_test.rs @@ -1649,7 +1649,7 @@ async fn revert_block() { // The commit of the reverted height is still pending when the revert is requested, so its // result is written, and cached, before the storage is reverted. - storage_writer.expect_set_global_root_and_block_hash().times(1).returning(|_, _, _, _| Ok(())); + storage_writer.expect_set_global_root_and_block_hash().times(1).returning(|_, _, _| Ok(())); let mut storage_reader = mock_storage_reader_for_revert(); storage_reader .expect_get_parent_hash_and_partial_block_hash_components() @@ -2045,8 +2045,8 @@ async fn get_block_hash_after_reading_commitment_results() { mock_dependencies.storage_writer.expect_set_global_root_and_block_hash(); set_global_root_expectation.times(1); set_global_root_expectation - .with(eq(INITIAL_HEIGHT), eq(global_root), always(), always()) - .returning(|_, _, _, _| Ok(())); + .with(eq(INITIAL_HEIGHT), eq(global_root), always()) + .returning(|_, _, _| Ok(())); let mut batcher = create_batcher(mock_dependencies).await; @@ -2087,7 +2087,7 @@ async fn get_state_commitment_infos_after_reading_commitment_results() { .storage_writer .expect_set_global_root_and_block_hash() .times(1) - .returning(|_, _, _, _| Ok(())); + .returning(|_, _, _| Ok(())); let mut batcher = create_batcher(mock_dependencies).await; diff --git a/crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs b/crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs index 633a6bb78cb..dab5866e968 100644 --- a/crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs +++ b/crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs @@ -14,7 +14,6 @@ use apollo_committer_types::committer_types::{ }; use apollo_committer_types::communication::{CommitterRequestLabelValue, SharedCommitterClient}; use apollo_storage::accessed_keys::AccessedKeys as StorageAccessedKeys; -use apollo_storage::state_commitment_infos::CompressedStateCommitmentInfos; use lru::LruCache; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::block_hash::block_hash_calculator::{ @@ -23,6 +22,7 @@ use starknet_api::block_hash::block_hash_calculator::{ }; use starknet_api::core::StateDiffCommitment; use starknet_api::state::ThinStateDiff; +use starknet_committer::patricia_merkle_tree::types::CompressedStateCommitmentInfos; use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; use tokio::sync::mpsc::{channel, Receiver, Sender}; use tokio::time::{sleep, Duration}; @@ -310,17 +310,12 @@ impl CommitmentManager { } // Add commitment infos to cache. - if let Some(state_commitment_infos) = state_commitment_infos.clone() { + if let Some(state_commitment_infos) = state_commitment_infos { self.recent_state_commitment_infos_cache.put(height, state_commitment_infos); } // Write the block hash and global root to storage. - storage_writer.set_global_root_and_block_hash( - height, - global_root, - block_hash, - state_commitment_infos, - )?; + storage_writer.set_global_root_and_block_hash(height, global_root, block_hash)?; GLOBAL_ROOT_HEIGHT.increment(1); } diff --git a/crates/apollo_batcher/src/commitment_manager/commitment_manager_test.rs b/crates/apollo_batcher/src/commitment_manager/commitment_manager_test.rs index cb4a1724320..923dcf27d51 100644 --- a/crates/apollo_batcher/src/commitment_manager/commitment_manager_test.rs +++ b/crates/apollo_batcher/src/commitment_manager/commitment_manager_test.rs @@ -393,9 +393,7 @@ async fn test_add_task_wait_for_full_channel(mut mock_dependencies: MockDependen let set_global_root_expectation = mock_dependencies.storage_writer.expect_set_global_root_and_block_hash(); set_global_root_expectation.times(expected_n_calls); - set_global_root_expectation - .withf(move |h, _, _, _| *h == height) - .returning(|_, _, _, _| Ok(())); + set_global_root_expectation.withf(move |h, _, _| *h == height).returning(|_, _, _| Ok(())); } let (mut commitment_manager, storage_reader, mut storage_writer) = diff --git a/crates/apollo_batcher/src/commitment_manager/types.rs b/crates/apollo_batcher/src/commitment_manager/types.rs index b20e47d8d34..131be4a2bde 100644 --- a/crates/apollo_batcher/src/commitment_manager/types.rs +++ b/crates/apollo_batcher/src/commitment_manager/types.rs @@ -12,9 +12,9 @@ use apollo_committer_types::committer_types::{ RevertBlockResponse, }; use apollo_committer_types::communication::CommitterRequestLabelValue; -use apollo_storage::state_commitment_infos::CompressedStateCommitmentInfos; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::core::GlobalRoot; +use starknet_committer::patricia_merkle_tree::types::CompressedStateCommitmentInfos; use tracing::warn; /// Input for commitment tasks. diff --git a/crates/apollo_batcher/src/test_utils.rs b/crates/apollo_batcher/src/test_utils.rs index 93181ea3c55..2eca079cb38 100644 --- a/crates/apollo_batcher/src/test_utils.rs +++ b/crates/apollo_batcher/src/test_utils.rs @@ -20,11 +20,6 @@ use apollo_l1_events_types::MockL1EventsProviderClient; use apollo_mempool_types::communication::MockMempoolClient; use apollo_mempool_types::mempool_types::CommitBlockArgs; use apollo_storage::accessed_keys::AccessedKeys; -use apollo_storage::state_commitment_infos::{ - CompressedPayload, - CompressedStateCommitmentInfos, - STATE_COMMITMENT_INFOS_VERSION, -}; use async_trait::async_trait; use blockifier::blockifier::transaction_executor::BlockExecutionSummary; use blockifier::bouncer::{BouncerWeights, CasmHashComputationData}; @@ -43,6 +38,11 @@ use starknet_api::test_utils::l1_handler::{executable_l1_handler_tx, L1HandlerTx use starknet_api::transaction::fields::{Fee, TransactionSignature}; use starknet_api::transaction::TransactionHash; use starknet_api::{class_hash, contract_address, nonce, tx_hash}; +use starknet_committer::patricia_merkle_tree::types::{ + CompressedPayload, + CompressedStateCommitmentInfos, + STATE_COMMITMENT_INFOS_VERSION, +}; use starknet_types_core::felt::Felt; use tokio::sync::mpsc::{Receiver, Sender, UnboundedSender}; use tokio::time::sleep; diff --git a/crates/apollo_reverts/src/lib.rs b/crates/apollo_reverts/src/lib.rs index 8577ca7af8e..19c35d2a368 100644 --- a/crates/apollo_reverts/src/lib.rs +++ b/crates/apollo_reverts/src/lib.rs @@ -13,7 +13,6 @@ use apollo_storage::global_root::GlobalRootStorageWriter; use apollo_storage::header::HeaderStorageWriter; use apollo_storage::partial_block_hash::PartialBlockHashComponentsStorageWriter; use apollo_storage::state::StateStorageWriter; -use apollo_storage::state_commitment_infos::StateCommitmentInfosStorageWriter; use apollo_storage::StorageWriter; use futures::future::pending; use futures::never::Never; @@ -146,11 +145,7 @@ pub fn revert_block(storage_writer: &mut StorageWriter, target_block_marker: Blo .revert_global_root(&target_block_marker) .unwrap(); - let txn = txn - .revert_accessed_keys(target_block_marker) - .unwrap() - .revert_state_commitment_infos(target_block_marker) - .unwrap(); + let txn = txn.revert_accessed_keys(target_block_marker).unwrap(); txn.commit().unwrap(); } diff --git a/crates/apollo_storage/Cargo.toml b/crates/apollo_storage/Cargo.toml index f21d2d7e9d4..ebb6becc76d 100644 --- a/crates/apollo_storage/Cargo.toml +++ b/crates/apollo_storage/Cargo.toml @@ -41,7 +41,6 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["arbitrary_precision"] } starknet-types-core = { workspace = true, features = ["papyrus-serialization"] } starknet_api.workspace = true -starknet_committer.workspace = true tempfile = { workspace = true, optional = true } thiserror.workspace = true tokio = { workspace = true, features = ["rt-multi-thread"] } diff --git a/crates/apollo_storage/src/lib.rs b/crates/apollo_storage/src/lib.rs index 0ad1c88aaac..5ebb5d6ecc6 100644 --- a/crates/apollo_storage/src/lib.rs +++ b/crates/apollo_storage/src/lib.rs @@ -90,7 +90,6 @@ pub mod global_root_marker; #[allow(missing_docs)] pub mod metrics; pub mod partial_block_hash; -pub mod state_commitment_infos; pub mod storage_metrics; // TODO(yair): Make the compression_utils module pub(crate) or extract it from the crate. #[doc(hidden)] @@ -185,7 +184,6 @@ use crate::header::StorageBlockHeader; use crate::metrics::{register_metrics, STORAGE_COMMIT_LATENCY}; use crate::mmap_file::MMapFileStats; use crate::state::data::IndexedDeprecatedContractClass; -use crate::state_commitment_infos::CompressedStateCommitmentInfos; use crate::storage_reader_server::{ create_storage_reader_server, ServerConfig, @@ -279,7 +277,6 @@ fn open_storage_internal( stateless_compiled_class_hash_v2: db_writer .create_simple_table("stateless_compiled_class_hash_v2")?, accessed_keys: db_writer.create_simple_table("accessed_keys")?, - state_commitment_infos: db_writer.create_simple_table("state_commitment_infos")?, }); let (file_writers, file_readers) = open_storage_files( &storage_config.db_config, @@ -992,8 +989,7 @@ struct_field_names! { compiled_class_hash: TableIdentifier<(ClassHash, BlockNumber), VersionZeroWrapper, CommonPrefix>, stateless_compiled_class_hash_v2: TableIdentifier, SimpleTable>, - accessed_keys: TableIdentifier, SimpleTable>, - state_commitment_infos: TableIdentifier, SimpleTable> + accessed_keys: TableIdentifier, SimpleTable> } } @@ -1163,7 +1159,6 @@ struct FileHandlers { transaction_output: FileHandler, Mode>, transaction: FileHandler, Mode>, accessed_keys: FileHandler, Mode>, - state_commitment_infos: FileHandler, Mode>, } impl FileHandlers { @@ -1205,13 +1200,6 @@ impl FileHandlers { self.clone().accessed_keys.append(accessed_keys) } - fn append_state_commitment_infos( - &self, - state_commitment_infos: &CompressedStateCommitmentInfos, - ) -> LocationInFile { - self.clone().state_commitment_infos.append(state_commitment_infos) - } - // TODO(dan): Consider 1. flushing only the relevant files, 2. flushing concurrently. #[latency_histogram("storage_file_handler_flush_latency_seconds", false)] fn flush(&self) { @@ -1223,7 +1211,6 @@ impl FileHandlers { self.transaction_output.flush(); self.transaction.flush(); self.accessed_keys.flush(); - self.state_commitment_infos.flush(); } } @@ -1238,7 +1225,6 @@ impl FileHandlers { ("transaction_output".to_string(), self.transaction_output.stats()), ("transaction".to_string(), self.transaction.stats()), ("accessed_keys".to_string(), self.accessed_keys.stats()), - ("state_commitment_infos".to_string(), self.state_commitment_infos.stats()), ]) } @@ -1307,17 +1293,6 @@ impl FileHandlers { msg: format!("AccessedKeys at location {location:?} not found."), }) } - - // Returns the compressed commitment infos at the given location or an error in case they don't - // exist. - pub(crate) fn get_state_commitment_infos_unchecked( - &self, - location: LocationInFile, - ) -> StorageResult { - self.state_commitment_infos.get(location)?.ok_or(StorageError::DBInconsistency { - msg: format!("StateCommitmentInfos at location {location:?} not found."), - }) - } } fn open_storage_files( @@ -1355,8 +1330,6 @@ fn open_storage_files( let (transaction_writer, transaction_reader) = open_storage_file!("transaction", Transaction)?; let (accessed_keys_writer, accessed_keys_reader) = open_storage_file!("accessed_keys", AccessedKeys)?; - let (state_commitment_infos_writer, state_commitment_infos_reader) = - open_storage_file!("state_commitment_infos", StateCommitmentInfos)?; Ok(( FileHandlers { @@ -1367,7 +1340,6 @@ fn open_storage_files( transaction_output: transaction_output_writer, transaction: transaction_writer, accessed_keys: accessed_keys_writer, - state_commitment_infos: state_commitment_infos_writer, }, FileHandlers { thin_state_diff: thin_state_diff_reader, @@ -1377,7 +1349,6 @@ fn open_storage_files( transaction_output: transaction_output_reader, transaction: transaction_reader, accessed_keys: accessed_keys_reader, - state_commitment_infos: state_commitment_infos_reader, }, )) } @@ -1399,6 +1370,4 @@ pub enum OffsetKind { Transaction, /// An accessed-keys file. AccessedKeys, - /// A state-commitment-infos file. - StateCommitmentInfos, } diff --git a/crates/apollo_storage/src/serialization/serializers.rs b/crates/apollo_storage/src/serialization/serializers.rs index 08f30e5ca9a..838c4db4be0 100644 --- a/crates/apollo_storage/src/serialization/serializers.rs +++ b/crates/apollo_storage/src/serialization/serializers.rs @@ -371,7 +371,6 @@ auto_storage_serde! { TransactionOutput = 4, Transaction = 5, AccessedKeys = 6, - StateCommitmentInfos = 7, } pub struct PartialBlockHashComponents { pub header_commitments: BlockHeaderCommitments, diff --git a/crates/apollo_storage/src/state_commitment_infos.rs b/crates/apollo_storage/src/state_commitment_infos.rs deleted file mode 100644 index 78b3266beb1..00000000000 --- a/crates/apollo_storage/src/state_commitment_infos.rs +++ /dev/null @@ -1,130 +0,0 @@ -//! Storage for the per-block OS-input commitment infos (state-trie commitment data for the OS). -//! -//! Persists the already-compressed `CompressedStateCommitmentInfos` the committer produces. - -use starknet_api::block::BlockNumber; -pub use starknet_committer::patricia_merkle_tree::types::{ - CompressedPayload, - CompressedStateCommitmentInfos, - STATE_COMMITMENT_INFOS_VERSION, -}; - -#[cfg(test)] -#[path = "state_commitment_infos_test.rs"] -mod state_commitment_infos_test; - -use crate::db::serialization::{StorageSerde, StorageSerdeError}; -use crate::db::table_types::Table; -use crate::db::{TransactionKind, RW}; -use crate::mmap_file::LocationInFile; -use crate::{OffsetKind, StorageResult, StorageTransaction}; - -impl StorageSerde for CompressedStateCommitmentInfos { - fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> { - self.version.serialize_into(res)?; - self.payload.0.serialize_into(res) - } - - fn deserialize_from(bytes: &mut impl std::io::Read) -> Option { - Some(Self { - version: u8::deserialize_from(bytes)?, - payload: CompressedPayload(Vec::::deserialize_from(bytes)?), - }) - } -} - -/// Interface for reading the OS-input commitment infos from storage. -pub trait StateCommitmentInfosStorageReader { - /// Returns the compressed commitment infos for the given block, or `None` if not stored. - fn get_state_commitment_infos( - &self, - block_number: BlockNumber, - ) -> StorageResult>; - - /// Returns whether the compressed commitment infos for the given block are stored, without - /// reading the stored blob. - fn has_state_commitment_infos(&self, block_number: BlockNumber) -> StorageResult; -} - -/// Interface for writing the OS-input commitment infos to storage. -pub trait StateCommitmentInfosStorageWriter -where - Self: Sized, -{ - /// Appends the compressed commitment infos for the given block to storage. - fn append_state_commitment_infos( - self, - block_number: BlockNumber, - state_commitment_infos: &CompressedStateCommitmentInfos, - ) -> StorageResult; - - /// Removes the commitment infos for the given block from storage. - /// If no entry exists for the block, returns without error. - fn revert_state_commitment_infos(self, block_number: BlockNumber) -> StorageResult; -} - -impl StateCommitmentInfosStorageReader<::Mode> - for T -{ - fn get_state_commitment_infos( - &self, - block_number: BlockNumber, - ) -> StorageResult> { - let Some(location) = self.state_commitment_infos_location(block_number)? else { - return Ok(None); - }; - Ok(Some(self.file_handlers().get_state_commitment_infos_unchecked(location)?)) - } - - fn has_state_commitment_infos(&self, block_number: BlockNumber) -> StorageResult { - Ok(self.state_commitment_infos_location(block_number)?.is_some()) - } -} - -trait StateCommitmentInfosLocationReader { - /// Looks up the stored location of the given block's compressed commitment infos, without - /// reading the blob itself. - fn state_commitment_infos_location( - &self, - block_number: BlockNumber, - ) -> StorageResult>; -} - -impl StateCommitmentInfosLocationReader for T { - fn state_commitment_infos_location( - &self, - block_number: BlockNumber, - ) -> StorageResult> { - let table = self.open_table(&self.tables().state_commitment_infos)?; - Ok(table.get(self.txn(), &block_number)?) - } -} - -impl> StateCommitmentInfosStorageWriter for T { - fn append_state_commitment_infos( - self, - block_number: BlockNumber, - state_commitment_infos: &CompressedStateCommitmentInfos, - ) -> StorageResult { - let file_offset_table = self.open_table(&self.tables().file_offsets)?; - let state_commitment_infos_table = - self.open_table(&self.tables().state_commitment_infos)?; - - let location = self.file_handlers().append_state_commitment_infos(state_commitment_infos); - state_commitment_infos_table.upsert(self.txn(), &block_number, &location)?; - file_offset_table.upsert( - self.txn(), - &OffsetKind::StateCommitmentInfos, - &location.next_offset(), - )?; - - Ok(self) - } - - fn revert_state_commitment_infos(self, block_number: BlockNumber) -> StorageResult { - let state_commitment_infos_table = - self.open_table(&self.tables().state_commitment_infos)?; - state_commitment_infos_table.delete(self.txn(), &block_number)?; - Ok(self) - } -} diff --git a/crates/apollo_storage/src/state_commitment_infos_test.rs b/crates/apollo_storage/src/state_commitment_infos_test.rs deleted file mode 100644 index 4ad48812416..00000000000 --- a/crates/apollo_storage/src/state_commitment_infos_test.rs +++ /dev/null @@ -1,76 +0,0 @@ -use starknet_api::block::BlockNumber; - -use crate::state_commitment_infos::{ - CompressedPayload, - CompressedStateCommitmentInfos, - StateCommitmentInfosStorageReader, - StateCommitmentInfosStorageWriter, - STATE_COMMITMENT_INFOS_VERSION, -}; -use crate::test_utils::get_test_storage; - -/// Non-default version, so the round-trip proves the field is stored rather than assumed. -fn dummy_state_commitment_infos() -> CompressedStateCommitmentInfos { - CompressedStateCommitmentInfos { - version: STATE_COMMITMENT_INFOS_VERSION + 1, - payload: CompressedPayload(b"compressed-state-commitment-infos".to_vec()), - } -} - -#[test] -fn append_and_get_state_commitment_infos() { - let (reader, mut writer) = get_test_storage().0; - let height = BlockNumber(5); - let state_commitment_infos = dummy_state_commitment_infos(); - - // No infos stored for the height yet. - assert_eq!(reader.begin_ro_txn().unwrap().get_state_commitment_infos(height).unwrap(), None); - - writer - .begin_rw_txn() - .unwrap() - .append_state_commitment_infos(height, &state_commitment_infos) - .unwrap() - .commit() - .unwrap(); - - assert_eq!( - reader.begin_ro_txn().unwrap().get_state_commitment_infos(height).unwrap(), - Some(state_commitment_infos) - ); - // A different height is still empty. - assert_eq!( - reader.begin_ro_txn().unwrap().get_state_commitment_infos(BlockNumber(6)).unwrap(), - None - ); -} - -#[test] -fn revert_state_commitment_infos() { - let (reader, mut writer) = get_test_storage().0; - let height = BlockNumber(5); - - writer - .begin_rw_txn() - .unwrap() - .append_state_commitment_infos(height, &dummy_state_commitment_infos()) - .unwrap() - .commit() - .unwrap(); - - assert!(reader.begin_ro_txn().unwrap().has_state_commitment_infos(height).unwrap()); - - writer.begin_rw_txn().unwrap().revert_state_commitment_infos(height).unwrap().commit().unwrap(); - - assert_eq!(reader.begin_ro_txn().unwrap().get_state_commitment_infos(height).unwrap(), None); - assert!(!reader.begin_ro_txn().unwrap().has_state_commitment_infos(height).unwrap()); - - // Reverting a height with no stored infos is a no-op. - writer - .begin_rw_txn() - .unwrap() - .revert_state_commitment_infos(BlockNumber(99)) - .unwrap() - .commit() - .unwrap(); -}