Skip to content

Commit eeb92b6

Browse files
committed
apply stateful compression conditionally
1 parent a7b2bfa commit eeb92b6

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

crates/executor/src/implementation/blockifier/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'a> BlockExecutor<'a> for StarknetVMProcessor<'a> {
292292
}
293293

294294
fn take_execution_output(&mut self) -> ExecutorResult<ExecutionOutput> {
295-
let states = utils::state_update_from_cached_state(&self.state);
295+
let states = utils::state_update_from_cached_state(&self.state, true);
296296
let transactions = std::mem::take(&mut self.transactions);
297297
let stats = std::mem::take(&mut self.stats);
298298
Ok(ExecutionOutput { stats, states, transactions })

crates/executor/src/implementation/blockifier/utils.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use blockifier::execution::contract_class::{
1111
use blockifier::fee::fee_utils::get_fee_by_gas_vector;
1212
use blockifier::state::cached_state::{self, TransactionalState};
1313
use blockifier::state::state_api::{StateReader, UpdatableState};
14-
use blockifier::state::stateful_compression::{allocate_aliases_in_storage, compress};
14+
use blockifier::state::stateful_compression::allocate_aliases_in_storage;
1515
use blockifier::transaction::account_transaction::{
1616
AccountTransaction, ExecutionFlags as BlockifierExecutionFlags,
1717
};
@@ -499,18 +499,32 @@ pub fn block_context_from_envs(
499499
BlockContext::new(block_info, chain_info, versioned_constants, BouncerConfig::max())
500500
}
501501

502-
pub(super) fn state_update_from_cached_state(state: &CachedState<'_>) -> StateUpdatesWithClasses {
503-
let alias_contract_address = contract_address!(ALIAS_CONTRACT_ADDRESS);
504-
allocate_aliases_in_storage(&mut state.inner.lock().cached_state, alias_contract_address)
505-
.unwrap();
502+
pub(super) fn state_update_from_cached_state(
503+
state: &CachedState<'_>,
504+
stateful_compression: bool,
505+
) -> StateUpdatesWithClasses {
506+
let state_diff = if stateful_compression {
507+
let mut state_lock = state.inner.lock();
506508

507-
let state_diff = state.inner.lock().cached_state.to_state_diff().unwrap().state_maps;
508-
let state_diff =
509-
compress(&state_diff, &state.inner.lock().cached_state, alias_contract_address);
509+
let alias_contract_address = contract_address!(ALIAS_CONTRACT_ADDRESS);
510+
allocate_aliases_in_storage(&mut state_lock.cached_state, alias_contract_address)
511+
.expect("failed to allocated aliases");
510512

511-
assert!(state_diff.is_ok(), "failed to compress state diff");
513+
#[cfg(debug_assertions)]
514+
{
515+
use blockifier::state::stateful_compression::compress;
512516

513-
let state_diff = state.inner.lock().cached_state.to_state_diff().unwrap().state_maps;
517+
let state_diff = state_lock.cached_state.to_state_diff().unwrap().state_maps;
518+
let compressed_state_diff =
519+
compress(&state_diff, &state_lock.cached_state, alias_contract_address);
520+
521+
debug_assert!(compressed_state_diff.is_ok(), "failed to compress state diff");
522+
}
523+
524+
state_lock.cached_state.to_state_diff().unwrap().state_maps
525+
} else {
526+
state.inner.lock().cached_state.to_state_diff().unwrap().state_maps
527+
};
514528

515529
let mut declared_contract_classes: BTreeMap<
516530
katana_primitives::class::ClassHash,

0 commit comments

Comments
 (0)