Skip to content

Commit

Permalink
refactor(blockifier): inject VC into CallInfo::summarize
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Nov 19, 2024
1 parent 975ff5a commit d525dc2
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
5 changes: 4 additions & 1 deletion crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ impl<S: StateReader> StatefulValidator<S> {
.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,
);

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<S: StateReader> TransactionExecutor<S> {
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();
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 @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<ClassHash> = HashSet::new();
let mut visited_storage_entries: HashSet<StorageEntry> = HashSet::new();
let mut event_summary = EventSummary::default();
Expand Down Expand Up @@ -207,8 +208,11 @@ impl CallInfo {
}
}

pub fn summarize_many<'a>(call_infos: impl Iterator<Item = &'a CallInfo>) -> ExecutionSummary {
call_infos.map(|call_info| call_info.summarize()).sum()
pub fn summarize_many<'a>(
call_infos: impl Iterator<Item = &'a CallInfo>,
versioned_constants: &VersionedConstants,
) -> ExecutionSummary {
call_infos.map(|call_info| call_info.summarize(versioned_constants)).sum()
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!(
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/fee/receipt_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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,
);

Expand All @@ -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,
);
Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions crates/blockifier/src/transaction/objects_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> 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()?,
);
Expand Down Expand Up @@ -209,7 +209,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> 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),
Expand Down

0 comments on commit d525dc2

Please sign in to comment.