Skip to content

Commit 80f2783

Browse files
starknet_api: add and use StateRoots::EMPTY
1 parent 6e16f47 commit 80f2783

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

crates/central_systest_blobs/src/cende_blob_regression_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl BlobFactory {
433433
}
434434

435435
fn last_finalized_state_roots(&self) -> StateRoots {
436-
self.blocks.last().map(|block| block.state_roots).unwrap_or_default()
436+
self.blocks.last().map(|block| block.state_roots).unwrap_or(StateRoots::EMPTY)
437437
}
438438

439439
// =====================

crates/starknet_api/src/hash.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ impl HashOutput {
9191
}
9292

9393
/// Output of committing a state.
94-
#[derive(Clone, Copy, Debug, Deserialize, Default, PartialEq, Eq, Hash, Serialize)]
94+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, Serialize)]
9595
pub struct StateRoots {
9696
pub contracts_trie_root_hash: HashOutput,
9797
pub classes_trie_root_hash: HashOutput,
9898
}
9999

100100
impl StateRoots {
101+
pub const EMPTY: Self = Self {
102+
contracts_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE,
103+
classes_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE,
104+
};
105+
101106
pub fn global_root(&self) -> GlobalRoot {
102-
if self.contracts_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE
103-
&& self.classes_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE
104-
{
107+
if self == &Self::EMPTY {
105108
return GlobalRoot::ROOT_OF_EMPTY_STATE;
106109
}
107110
GlobalRoot(Poseidon::hash_array(&[

crates/starknet_committer/src/block_committer/commit_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async fn test_commit_two_consecutive_blocks_facts_layout(
8888
) {
8989
test_commit_two_consecutive_blocks::<FactsDb<MapStorage>>(
9090
FactsDb::new,
91-
FactsDbInitialRead(StateRoots::default()),
91+
FactsDbInitialRead(StateRoots::EMPTY),
9292
state_diffs,
9393
expected_roots,
9494
)

crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ pub async fn run_snap_sync(
455455
committer_config.db_path,
456456
committer_config.storage_config,
457457
)),
458-
state_roots: StateRoots::default(),
458+
state_roots: StateRoots::EMPTY,
459459
num_commits: 0,
460460
}));
461461

crates/starknet_committer_and_os_cli/src/committer_cli/snap_sync_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn test_storage_key_scan() {
290290
fn create_test_commit_state() -> Arc<Mutex<CommitState<MapStorage>>> {
291291
Arc::new(Mutex::new(CommitState {
292292
committer_db: IndexDb::new(MapStorage::default()),
293-
state_roots: StateRoots::default(),
293+
state_roots: StateRoots::EMPTY,
294294
num_commits: 0,
295295
}))
296296
}
@@ -324,7 +324,7 @@ async fn run_process_request_for_class_hashes(
324324
async fn test_process_request_empty_storage() {
325325
let (state_roots, num_commits) =
326326
run_process_request_for_class_hashes(ThinStateDiff::default(), 100).await;
327-
assert_eq!(state_roots, StateRoots::default());
327+
assert_eq!(state_roots, StateRoots::EMPTY);
328328
assert_eq!(num_commits, 1);
329329
}
330330

@@ -341,7 +341,7 @@ async fn test_process_request_commits_entries() {
341341
..Default::default()
342342
};
343343
let (state_roots, num_commits) = run_process_request_for_class_hashes(diff, 100).await;
344-
assert_ne!(state_roots, StateRoots::default());
344+
assert_ne!(state_roots, StateRoots::EMPTY);
345345
assert_eq!(num_commits, 1);
346346
}
347347

0 commit comments

Comments
 (0)