Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor(concurrency): add consistency validations for declared_contr…
Browse files Browse the repository at this point in the history
…acts (#1936)
  • Loading branch information
OriStarkware authored Jun 2, 2024
1 parent ffbb85d commit 5fdc9ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/concurrency/versioned_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ impl<S: StateReader> VersionedState<S> {
T: StateReader,
{
let writes = self.get_writes_up_to_index(from_index);
parent_state.update_cache(&writes);

parent_state.update_contract_class_cache(
parent_state.update_cache(
&writes,
self.compiled_contract_classes.get_writes_up_to_index(from_index),
);
}
Expand Down
17 changes: 9 additions & 8 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ impl<S: StateReader> CachedState<S> {
Ok(self.to_state_diff()?.into())
}

pub fn update_cache(&mut self, write_updates: &StateMaps) {
let mut cache = self.cache.borrow_mut();
cache.writes.extend(write_updates);
}

pub fn update_contract_class_cache(
pub fn update_cache(
&mut self,
write_updates: &StateMaps,
local_contract_cache_updates: ContractClassMapping,
) {
// Check consistency between declared_contracts and class_hash_to_class.
for (&key, &value) in &write_updates.declared_contracts {
assert_eq!(value, local_contract_cache_updates.contains_key(&key));
}
let mut cache = self.cache.borrow_mut();
cache.writes.extend(write_updates);
self.class_hash_to_class.get_mut().extend(local_contract_cache_updates);
}

Expand Down Expand Up @@ -110,9 +112,8 @@ impl<S: StateReader> UpdatableState for CachedState<S> {
class_hash_to_class: &ContractClassMapping,
visited_pcs: &HashMap<ClassHash, HashSet<usize>>,
) {
self.update_cache(writes);
// TODO(OriF,15/5/24): Reconsider the clone.
self.update_contract_class_cache(class_hash_to_class.clone());
self.update_cache(writes, class_hash_to_class.clone());
self.update_visited_pcs_cache(visited_pcs);
}
}
Expand Down

0 comments on commit 5fdc9ea

Please sign in to comment.