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

refactor(blockifier): diff of StateCache is StateChanges #2174

Merged
merged 1 commit into from
Nov 25, 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
7 changes: 6 additions & 1 deletion crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ impl<S: StateReader> TransactionExecutor<S> {

log::debug!("Final block weights: {:?}.", self.bouncer.get_accumulated_weights());
Ok((
self.block_state.as_mut().expect(BLOCK_STATE_ACCESS_ERR).to_state_diff()?.into(),
self.block_state
.as_mut()
.expect(BLOCK_STATE_ACCESS_ERR)
.to_state_diff()?
.state_maps
.into(),
visited_segments,
*self.bouncer.get_accumulated_weights(),
))
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> {
let execution_output_inner = match execution_result {
Ok(_) => {
let tx_reads_writes = transactional_state.cache.take();
let writes = tx_reads_writes.to_state_diff();
let writes = tx_reads_writes.to_state_diff().state_maps;
let contract_classes = transactional_state.class_hash_to_class.take();
let visited_pcs = transactional_state.visited_pcs;
// The versioned state does not carry the visited PCs.
Expand Down
9 changes: 5 additions & 4 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ impl<S: StateReader> CachedState<S> {

/// Returns the state diff resulting from the performed writes, with respect to the parent
/// state.
pub fn to_state_diff(&mut self) -> StateResult<StateMaps> {
pub fn to_state_diff(&mut self) -> StateResult<StateChanges> {
self.update_initial_values_of_write_only_access()?;
Ok(self.cache.borrow().to_state_diff())
}

// TODO(Yoni, 1/8/2024): remove this function.
/// Returns the state changes made on this state.
pub fn get_actual_state_changes(&mut self) -> StateResult<StateChanges> {
Ok(StateChanges { state_maps: self.to_state_diff()? })
self.to_state_diff()
}

pub fn update_cache(
Expand Down Expand Up @@ -399,8 +399,9 @@ pub struct StateCache {
impl StateCache {
/// Returns the state diff resulting from the performed writes, with respect to the initial
/// reads. Assumes (and enforces) all initial reads are cached.
pub fn to_state_diff(&self) -> StateMaps {
self.writes.diff(&self.initial_reads)
pub fn to_state_diff(&self) -> StateChanges {
let state_maps = self.writes.diff(&self.initial_reads);
StateChanges { state_maps }
}

fn declare_contract(&mut self, class_hash: ClassHash) {
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/state/cached_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn cached_state_state_diff_conversion() {
address_to_nonce: IndexMap::from_iter([(contract_address2, nonce!(1_u64))]),
};

assert_eq!(expected_state_diff, state.to_state_diff().unwrap().into());
assert_eq!(expected_state_diff, state.to_state_diff().unwrap().state_maps.into());
}

fn create_state_changes_for_test<S: StateReader>(
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_execution/src/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ pub fn induced_state_diff(
transactional_state: &mut CachedState<MutRefState<'_, CachedState<ExecutionStateReader>>>,
deprecated_declared_class_hash: Option<ClassHash>,
) -> ExecutionResult<ThinStateDiff> {
let blockifier_state_diff = CommitmentStateDiff::from(transactional_state.to_state_diff()?);
let blockifier_state_diff =
CommitmentStateDiff::from(transactional_state.to_state_diff()?.state_maps);
// Determine which contracts were deployed and which were replaced by comparing their
// previous class hash (default value suggests it didn't exist before).
let mut deployed_contracts = IndexMap::new();
Expand Down
Loading