Skip to content

Commit

Permalink
fix: state root - replaced_classes (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: antiyro <[email protected]>
  • Loading branch information
jbcaron and antiyro authored May 15, 2024
1 parent 07beabf commit 9aff719
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit 9aff719

Please sign in to comment.