From fa76e6e64e068c7b8087d31972ee06e39999cfee Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Tue, 5 May 2026 14:47:16 +0300 Subject: [PATCH] starknet_api: add and use StateRoots::EMPTY --- .../src/cende_blob_regression_test.rs | 2 +- crates/starknet_api/src/hash.rs | 11 +++++++---- .../src/block_committer/commit_test.rs | 2 +- .../src/committer_cli/snap_sync.rs | 2 +- .../src/committer_cli/snap_sync_test.rs | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/central_systest_blobs/src/cende_blob_regression_test.rs b/crates/central_systest_blobs/src/cende_blob_regression_test.rs index c22dff48768..082a545df69 100644 --- a/crates/central_systest_blobs/src/cende_blob_regression_test.rs +++ b/crates/central_systest_blobs/src/cende_blob_regression_test.rs @@ -433,7 +433,7 @@ impl BlobFactory { } fn last_finalized_state_roots(&self) -> StateRoots { - self.blocks.last().map(|block| block.state_roots).unwrap_or_default() + self.blocks.last().map(|block| block.state_roots).unwrap_or(StateRoots::EMPTY) } // ===================== diff --git a/crates/starknet_api/src/hash.rs b/crates/starknet_api/src/hash.rs index ca0b3a72a33..dc1721ad336 100644 --- a/crates/starknet_api/src/hash.rs +++ b/crates/starknet_api/src/hash.rs @@ -91,17 +91,20 @@ impl HashOutput { } /// Output of committing a state. -#[derive(Clone, Copy, Debug, Deserialize, Default, PartialEq, Eq, Hash, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, Serialize)] pub struct StateRoots { pub contracts_trie_root_hash: HashOutput, pub classes_trie_root_hash: HashOutput, } impl StateRoots { + pub const EMPTY: Self = Self { + contracts_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE, + classes_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE, + }; + pub fn global_root(&self) -> GlobalRoot { - if self.contracts_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE - && self.classes_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE - { + if self == &Self::EMPTY { return GlobalRoot::ROOT_OF_EMPTY_STATE; } GlobalRoot(Poseidon::hash_array(&[ diff --git a/crates/starknet_committer/src/block_committer/commit_test.rs b/crates/starknet_committer/src/block_committer/commit_test.rs index 0579f2c9b84..a47e602427c 100644 --- a/crates/starknet_committer/src/block_committer/commit_test.rs +++ b/crates/starknet_committer/src/block_committer/commit_test.rs @@ -88,7 +88,7 @@ async fn test_commit_two_consecutive_blocks_facts_layout( ) { test_commit_two_consecutive_blocks::>( FactsDb::new, - FactsDbInitialRead(StateRoots::default()), + FactsDbInitialRead(StateRoots::EMPTY), state_diffs, expected_roots, ) diff --git a/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync.rs b/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync.rs index a99e628c37a..4ee9105479a 100644 --- a/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync.rs +++ b/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync.rs @@ -455,7 +455,7 @@ pub async fn run_snap_sync( committer_config.db_path, committer_config.storage_config, )), - state_roots: StateRoots::default(), + state_roots: StateRoots::EMPTY, num_commits: 0, })); diff --git a/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync_test.rs b/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync_test.rs index fd27c5c0c34..15f5532d431 100644 --- a/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync_test.rs +++ b/crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync_test.rs @@ -290,7 +290,7 @@ fn test_storage_key_scan() { fn create_test_commit_state() -> Arc>> { Arc::new(Mutex::new(CommitState { committer_db: IndexDb::new(MapStorage::default()), - state_roots: StateRoots::default(), + state_roots: StateRoots::EMPTY, num_commits: 0, })) } @@ -324,7 +324,7 @@ async fn run_process_request_for_class_hashes( async fn test_process_request_empty_storage() { let (state_roots, num_commits) = run_process_request_for_class_hashes(ThinStateDiff::default(), 100).await; - assert_eq!(state_roots, StateRoots::default()); + assert_eq!(state_roots, StateRoots::EMPTY); assert_eq!(num_commits, 1); } @@ -341,7 +341,7 @@ async fn test_process_request_commits_entries() { ..Default::default() }; let (state_roots, num_commits) = run_process_request_for_class_hashes(diff, 100).await; - assert_ne!(state_roots, StateRoots::default()); + assert_ne!(state_roots, StateRoots::EMPTY); assert_eq!(num_commits, 1); }