Skip to content

blockifier: Time transaction and entrypoint executions. #7210 #64

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

Open
wants to merge 4 commits into
base: replay
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use std::iter::Sum;
use std::ops::{Add, AddAssign};
use std::time::Duration;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde::Serialize;
Expand Down Expand Up @@ -207,12 +208,13 @@ pub struct CallInfo {
pub tracked_resource: TrackedResource,

// Additional information gathered during execution.
pub time: std::time::Duration,
pub call_counter: usize,
pub storage_read_values: Vec<Felt>,
pub accessed_storage_keys: HashSet<StorageKey>,
pub read_class_hash_values: Vec<ClassHash>,
pub accessed_contract_addresses: HashSet<ContractAddress>,
/// Execution time of the contract call.
/// None implies that the time was not measured.
pub time: Option<Duration>,
}

impl CallInfo {
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/execution/entry_point_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ pub fn finalize_execution(
accessed_storage_keys: syscall_handler_base.accessed_keys,
read_class_hash_values: syscall_handler_base.read_class_hash_values,
accessed_contract_addresses: syscall_handler_base.accessed_contract_addresses,
time: std::time::Duration::default(),
call_counter: 0,
time: None,
})
}

Expand Down
12 changes: 5 additions & 7 deletions crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::time::Instant;

use cairo_vm::serde::deserialize_program::{
deserialize_array_of_bigint_hex,
Expand Down Expand Up @@ -115,10 +116,8 @@ pub fn execute_entry_point_call(
state: &mut dyn State,
context: &mut EntryPointExecutionContext,
) -> EntryPointExecutionResult<CallInfo> {
let current_call_counter = context.call_counter;
context.call_counter += 1;
let pre_time = std::time::Instant::now();
let mut result = match compiled_class {
let pre_execution_instant = Instant::now();
let mut call_info = match compiled_class {
RunnableCompiledClass::V0(compiled_class) => {
deprecated_entry_point_execution::execute_entry_point_call(
call,
Expand Down Expand Up @@ -153,9 +152,8 @@ pub fn execute_entry_point_call(
}
}
}?;
result.time = pre_time.elapsed();
result.call_counter = current_call_counter;
Ok(result)
call_info.time = Some(pre_execution_instant.elapsed());
Ok(call_info)
}

pub fn update_remaining_gas(remaining_gas: &mut u64, call_info: &CallInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ fn create_callinfo(
accessed_contract_addresses: syscall_handler.base.accessed_contract_addresses,
read_class_hash_values: syscall_handler.base.read_class_hash_values,
tracked_resource: TrackedResource::SierraGas,
time: std::time::Duration::default(),
call_counter: 0,
time: None,
})
}
4 changes: 4 additions & 0 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::Arc;
use std::time::Instant;

use starknet_api::abi::abi_utils::selector_from_name;
use starknet_api::block::GasPriceVector;
Expand Down Expand Up @@ -796,6 +797,8 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {
block_context: &BlockContext,
concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let pre_execution_instant = Instant::now();

let tx_context = Arc::new(block_context.to_tx_context(self));
self.verify_tx_version(tx_context.tx_info.version())?;

Expand Down Expand Up @@ -836,6 +839,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {
gas: total_gas,
},
revert_error,
time: Some(pre_execution_instant.elapsed()),
};
Ok(tx_execution_info)
}
Expand Down
4 changes: 4 additions & 0 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::time::Duration;

use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
Expand Down Expand Up @@ -209,6 +210,9 @@ pub struct TransactionExecutionInfo {
/// (including L1 gas and additional OS resources estimation),
/// and total gas consumed.
pub receipt: TransactionReceipt,
/// Total execution time of the transaction.
/// None implies that the time was not measured.
pub time: Option<Duration>,
}

impl TransactionExecutionInfo {
Expand Down
4 changes: 4 additions & 0 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::Arc;
use std::time::Instant;

use starknet_api::contract_class::ClassInfo;
use starknet_api::core::{calculate_contract_address, ContractAddress, Nonce};
Expand Down Expand Up @@ -142,6 +143,8 @@ impl<U: UpdatableState> ExecutableTransaction<U> for L1HandlerTransaction {
block_context: &BlockContext,
_concurrency_mode: bool,
) -> TransactionExecutionResult<TransactionExecutionInfo> {
let pre_execution_instant = Instant::now();

let tx_context = Arc::new(block_context.to_tx_context(self));
let limit_steps_by_resources = false;
// The Sierra gas limit for L1 handler transaction is set to max_execute_sierra_gas.
Expand Down Expand Up @@ -184,6 +187,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for L1HandlerTransaction {
gas: total_gas,
},
revert_error: None,
time: Some(pre_execution_instant.elapsed()),
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ fn test_invoke_tx(
gas: total_gas,
},
revert_error: None,
time: None,
};

// Test execution info result.
Expand Down Expand Up @@ -1702,6 +1703,7 @@ fn test_declare_tx(
gas: expected_total_gas,
},
revert_error: None,
time: None,
};

// Test execution info result.
Expand Down Expand Up @@ -1947,6 +1949,7 @@ fn test_deploy_account_tx(
gas: expected_total_gas,
},
revert_error: None,
time: None,
};

// Test execution info result.
Expand Down Expand Up @@ -2538,6 +2541,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) {
gas: total_gas,
},
revert_error: None,
time: None,
};

// Check the actual returned execution info.
Expand Down
Loading