Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: state root - replaced_classes #116

Merged
merged 2 commits into from
May 15, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix: state root - replaced_classes
- feat(db): backups
- fix: state root for nonce
- fix: store the first history in storage ket
Expand Down
21 changes: 14 additions & 7 deletions crates/client/sync/src/commitments/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use starknet_api::hash::StarkFelt;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{Event, Transaction};
use starknet_core::types::{
ContractStorageDiffItem, DeclaredClassItem, DeployedContractItem, NonceUpdate, StateUpdate, StorageEntry,
ContractStorageDiffItem, DeclaredClassItem, DeployedContractItem, NonceUpdate, ReplacedClassItem, StateUpdate,
StorageEntry,
};
use starknet_ff::FieldElement;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -74,6 +75,18 @@ pub fn build_commitment_state_diff(state_update: &StateUpdate) -> CommitmentStat
commitment_state_diff.address_to_class_hash.insert(address, class_hash);
}

for ReplacedClassItem { contract_address, class_hash } in state_update.state_diff.replaced_classes.iter() {
let address = ContractAddress::from_field_element(contract_address);
let class_hash = ClassHash::from_field_element(class_hash);
commitment_state_diff.address_to_class_hash.insert(address, class_hash);
}

for DeclaredClassItem { class_hash, compiled_class_hash } in state_update.state_diff.declared_classes.iter() {
let class_hash = ClassHash::from_field_element(class_hash);
let compiled_class_hash = CompiledClassHash::from_field_element(compiled_class_hash);
commitment_state_diff.class_hash_to_compiled_class_hash.insert(class_hash, compiled_class_hash);
}

for NonceUpdate { contract_address, nonce } in state_update.state_diff.nonces.iter() {
let contract_address = ContractAddress::from_field_element(contract_address);
let nonce_value = Nonce::from_field_element(nonce);
Expand All @@ -91,12 +104,6 @@ pub fn build_commitment_state_diff(state_update: &StateUpdate) -> CommitmentStat
commitment_state_diff.storage_updates.insert(contract_address, storage_map);
}

for DeclaredClassItem { class_hash, compiled_class_hash } in state_update.state_diff.declared_classes.iter() {
let class_hash = ClassHash::from_field_element(class_hash);
let compiled_class_hash = CompiledClassHash::from_field_element(compiled_class_hash);
commitment_state_diff.class_hash_to_compiled_class_hash.insert(class_hash, compiled_class_hash);
}

commitment_state_diff
}

Expand Down