diff --git a/crates/blockifier/src/blockifier/stateful_validator.rs b/crates/blockifier/src/blockifier/stateful_validator.rs index 867f13b9038..8cf9ed410e5 100644 --- a/crates/blockifier/src/blockifier/stateful_validator.rs +++ b/crates/blockifier/src/blockifier/stateful_validator.rs @@ -135,7 +135,10 @@ impl StatefulValidator { .expect(BLOCK_STATE_ACCESS_ERR) .get_actual_state_changes()?, &ChargedResources { vm_resources: execution_resources, gas_for_fee }, - CallInfo::summarize_many(validate_call_info.iter()), + CallInfo::summarize_many( + validate_call_info.iter(), + &tx_context.block_context.versioned_constants, + ), 0, ); diff --git a/crates/blockifier/src/blockifier/transaction_executor.rs b/crates/blockifier/src/blockifier/transaction_executor.rs index 224fb95387f..16dcefb6b9c 100644 --- a/crates/blockifier/src/blockifier/transaction_executor.rs +++ b/crates/blockifier/src/blockifier/transaction_executor.rs @@ -113,7 +113,7 @@ impl TransactionExecutor { self.bouncer.try_update( &transactional_state, &tx_state_changes_keys, - &tx_execution_info.summarize(), + &tx_execution_info.summarize(&self.block_context.versioned_constants), &tx_execution_info.receipt.resources, )?; transactional_state.commit(); diff --git a/crates/blockifier/src/concurrency/worker_logic.rs b/crates/blockifier/src/concurrency/worker_logic.rs index eb26f2a26e8..2d8a00a339b 100644 --- a/crates/blockifier/src/concurrency/worker_logic.rs +++ b/crates/blockifier/src/concurrency/worker_logic.rs @@ -250,7 +250,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> { let bouncer_result = self.bouncer.lock().expect("Bouncer lock failed.").try_update( &tx_versioned_state, &tx_state_changes_keys, - &tx_execution_info.summarize(), + &tx_execution_info.summarize(&self.block_context.versioned_constants), &tx_execution_info.receipt.resources, ); if let Err(error) = bouncer_result { diff --git a/crates/blockifier/src/execution/call_info.rs b/crates/blockifier/src/execution/call_info.rs index e6f8d84693c..02a9740680a 100644 --- a/crates/blockifier/src/execution/call_info.rs +++ b/crates/blockifier/src/execution/call_info.rs @@ -14,6 +14,7 @@ use crate::execution::contract_class::TrackedResource; use crate::execution::entry_point::CallEntryPoint; use crate::state::cached_state::StorageEntry; use crate::utils::u64_from_usize; +use crate::versioned_constants::VersionedConstants; #[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))] #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] @@ -167,7 +168,7 @@ impl CallInfo { event_summary } - pub fn summarize(&self) -> ExecutionSummary { + pub fn summarize(&self, _versioned_constants: &VersionedConstants) -> ExecutionSummary { let mut executed_class_hashes: HashSet = HashSet::new(); let mut visited_storage_entries: HashSet = HashSet::new(); let mut event_summary = EventSummary::default(); @@ -207,8 +208,11 @@ impl CallInfo { } } - pub fn summarize_many<'a>(call_infos: impl Iterator) -> ExecutionSummary { - call_infos.map(|call_info| call_info.summarize()).sum() + pub fn summarize_many<'a>( + call_infos: impl Iterator, + versioned_constants: &VersionedConstants, + ) -> ExecutionSummary { + call_infos.map(|call_info| call_info.summarize(versioned_constants)).sum() } } diff --git a/crates/blockifier/src/fee/gas_usage_test.rs b/crates/blockifier/src/fee/gas_usage_test.rs index d08a57697c1..10cdb2c96d0 100644 --- a/crates/blockifier/src/fee/gas_usage_test.rs +++ b/crates/blockifier/src/fee/gas_usage_test.rs @@ -69,7 +69,8 @@ fn starknet_resources() -> StarknetResources { .into_iter() .map(|call_info| call_info.with_some_class_hash()) .collect(); - let execution_summary = CallInfo::summarize_many(call_infos.iter()); + let execution_summary = + CallInfo::summarize_many(call_infos.iter(), &VersionedConstants::latest_constants()); let state_resources = StateResources::new_for_testing(StateChangesCount { n_storage_updates: 7, n_class_hash_updates: 11, @@ -95,7 +96,7 @@ fn test_get_event_gas_cost( .into_iter() .map(|call_info| call_info.with_some_class_hash()) .collect(); - let execution_summary = CallInfo::summarize_many(call_infos.iter()); + let execution_summary = CallInfo::summarize_many(call_infos.iter(), versioned_constants); let starknet_resources = StarknetResources::new(0, 0, 0, StateResources::default(), None, execution_summary); assert_eq!( @@ -142,7 +143,7 @@ fn test_get_event_gas_cost( .into_iter() .map(|call_info| call_info.with_some_class_hash()) .collect(); - let execution_summary = CallInfo::summarize_many(call_infos.iter()); + let execution_summary = CallInfo::summarize_many(call_infos.iter(), versioned_constants); // 8 keys and 11 data words overall. let expected_gas = (data_word_cost * (event_key_factor * 8_u64 + 11_u64)).to_integer().into(); let expected_gas_vector = match gas_vector_computation_mode { diff --git a/crates/blockifier/src/fee/receipt_test.rs b/crates/blockifier/src/fee/receipt_test.rs index 3a412de0847..5b4286ce348 100644 --- a/crates/blockifier/src/fee/receipt_test.rs +++ b/crates/blockifier/src/fee/receipt_test.rs @@ -216,7 +216,7 @@ fn test_calculate_tx_gas_usage_basic<'a>( call_infos.push(call_info); } - let execution_summary = CallInfo::summarize_many(call_infos.iter()); + let execution_summary = CallInfo::summarize_many(call_infos.iter(), &versioned_constants); let l2_to_l1_state_changes_count = StateChangesCount { n_storage_updates: 0, @@ -431,7 +431,8 @@ fn test_calculate_tx_gas_usage( }; let execution_call_info = &tx_execution_info.execute_call_info.expect("Execution call info should exist."); - let execution_summary = CallInfo::summarize_many(vec![execution_call_info].into_iter()); + let execution_summary = + CallInfo::summarize_many(vec![execution_call_info].into_iter(), &versioned_constants); let starknet_resources = StarknetResources::new( calldata_length, signature_length, diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 9ccf6997405..cacef31ee47 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -606,7 +606,10 @@ impl AccountTransaction { &tx_context, &state.get_actual_state_changes()?, &ChargedResources { vm_resources: resources, gas_for_fee }, - CallInfo::summarize_many(validate_call_info.iter().chain(execute_call_info.iter())), + CallInfo::summarize_many( + validate_call_info.iter().chain(execute_call_info.iter()), + &tx_context.block_context.versioned_constants, + ), 0, ); @@ -675,7 +678,10 @@ impl AccountTransaction { &tx_context, &validate_state_changes, &ChargedResources { vm_resources: validate_resources, gas_for_fee }, - CallInfo::summarize_many(validate_call_info.iter()), + CallInfo::summarize_many( + validate_call_info.iter(), + &tx_context.block_context.versioned_constants, + ), execution_steps_consumed, ); @@ -699,6 +705,7 @@ impl AccountTransaction { }, CallInfo::summarize_many( validate_call_info.iter().chain(execute_call_info.iter()), + &tx_context.block_context.versioned_constants, ), 0, ); diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index c1032eb7e34..06e0e898352 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -32,6 +32,7 @@ use crate::fee::fee_checks::FeeCheckError; use crate::fee::fee_utils::get_fee_by_gas_vector; use crate::fee::receipt::TransactionReceipt; use crate::transaction::errors::{TransactionExecutionError, TransactionPreValidationError}; +use crate::versioned_constants::VersionedConstants; #[cfg(test)] #[path = "objects_test.rs"] @@ -225,8 +226,8 @@ impl TransactionExecutionInfo { /// Returns a summary of transaction execution, including executed class hashes, visited storage /// entries, L2-to-L1_payload_lengths, and the number of emitted events. - pub fn summarize(&self) -> ExecutionSummary { - CallInfo::summarize_many(self.non_optional_call_infos()) + pub fn summarize(&self, versioned_constants: &VersionedConstants) -> ExecutionSummary { + CallInfo::summarize_many(self.non_optional_call_infos(), versioned_constants) } } pub trait ExecutionResourcesTraits { diff --git a/crates/blockifier/src/transaction/objects_test.rs b/crates/blockifier/src/transaction/objects_test.rs index 22a4d8643a8..c1c339227cf 100644 --- a/crates/blockifier/src/transaction/objects_test.rs +++ b/crates/blockifier/src/transaction/objects_test.rs @@ -16,6 +16,7 @@ use crate::execution::call_info::{ }; use crate::execution::entry_point::CallEntryPoint; use crate::transaction::objects::TransactionExecutionInfo; +use crate::versioned_constants::VersionedConstants; #[derive(Debug, Default)] pub struct TestExecutionSummary { @@ -129,7 +130,7 @@ fn test_events_counter_in_tx_execution_info( }; assert_eq!( - tx_execution_info.summarize().event_summary.n_events, + tx_execution_info.summarize(&VersionedConstants::latest_constants()).event_summary.n_events, n_validate_events + n_execute_events + n_fee_transfer_events + n_inner_calls ); } @@ -158,7 +159,7 @@ fn test_events_counter_in_tx_execution_info_with_inner_call_info(#[case] n_execu }; assert_eq!( - tx_execution_info.summarize().event_summary.n_events, + tx_execution_info.summarize(&VersionedConstants::latest_constants()).event_summary.n_events, n_execute_events + n_fee_transfer_events + n_execution_events @@ -220,7 +221,7 @@ fn test_summarize( }; // Call the summarize method - let actual_summary = tx_execution_info.summarize(); + let actual_summary = tx_execution_info.summarize(&VersionedConstants::latest_constants()); // Compare the actual result with the expected result assert_eq!(actual_summary.executed_class_hashes, expected_summary.executed_class_hashes); diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index e47974c7205..dcf0cf0e411 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -162,7 +162,7 @@ impl ExecutableTransaction for L1HandlerTransaction { } = TransactionReceipt::from_l1_handler( &tx_context, l1_handler_payload_size, - CallInfo::summarize_many(execute_call_info.iter()), + CallInfo::summarize_many(execute_call_info.iter(), &block_context.versioned_constants), &ChargedResources { vm_resources: execution_resources, gas_for_fee }, &state.get_actual_state_changes()?, ); @@ -209,7 +209,7 @@ impl ExecutableTransaction for Transaction { // Check if the transaction is too large to fit any block. // TODO(Yoni, 1/8/2024): consider caching these two. - let tx_execution_summary = tx_execution_info.summarize(); + let tx_execution_summary = tx_execution_info.summarize(&block_context.versioned_constants); let mut tx_state_changes_keys = state.get_actual_state_changes()?.into_keys(); tx_state_changes_keys.update_sequencer_key_in_storage( &block_context.to_tx_context(self),