Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

// =====================
Expand Down
11 changes: 7 additions & 4 deletions crates/starknet_api/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async fn test_commit_two_consecutive_blocks_facts_layout(
) {
test_commit_two_consecutive_blocks::<FactsDb<MapStorage>>(
FactsDb::new,
FactsDbInitialRead(StateRoots::default()),
FactsDbInitialRead(StateRoots::EMPTY),
state_diffs,
expected_roots,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn test_storage_key_scan() {
fn create_test_commit_state() -> Arc<Mutex<CommitState<MapStorage>>> {
Arc::new(Mutex::new(CommitState {
committer_db: IndexDb::new(MapStorage::default()),
state_roots: StateRoots::default(),
state_roots: StateRoots::EMPTY,
num_commits: 0,
}))
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Loading