Skip to content

Commit

Permalink
fix(executor): fix inner call execution resources
Browse files Browse the repository at this point in the history
  • Loading branch information
kkovaacs committed Jan 15, 2025
1 parent b306103 commit 2e97034
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
28 changes: 23 additions & 5 deletions crates/executor/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use blockifier::state::cached_state::CachedState;
use blockifier::state::errors::StateError;
use blockifier::transaction::transaction_execution::Transaction;
use blockifier::transaction::transactions::ExecutableTransaction;
use blockifier::versioned_constants::VersionedConstants;
use cached::{Cached, SizedCache};
use pathfinder_common::{
BlockHash,
Expand Down Expand Up @@ -125,7 +126,12 @@ pub fn simulate(
fee_type,
&minimal_l1_gas_amount_vector,
),
trace: to_trace(transaction_type, tx_info, state_diff),
trace: to_trace(
transaction_type,
tx_info,
state_diff,
block_context.versioned_constants(),
),
});
}
Err(error) => {
Expand Down Expand Up @@ -203,7 +209,12 @@ pub fn trace(
})?;
tx_state.commit();

let trace = to_trace(tx_type, tx_info, state_diff);
let trace = to_trace(
tx_type,
tx_info,
state_diff,
block_context.versioned_constants(),
);
traces.push((hash, trace));
}

Expand Down Expand Up @@ -350,10 +361,17 @@ fn to_trace(
transaction_type: TransactionType,
execution_info: blockifier::transaction::objects::TransactionExecutionInfo,
state_diff: StateDiff,
versioned_constants: &VersionedConstants,
) -> TransactionTrace {
let validate_invocation = execution_info.validate_call_info.map(Into::into);
let maybe_function_invocation = execution_info.execute_call_info.map(Into::into);
let fee_transfer_invocation = execution_info.fee_transfer_call_info.map(Into::into);
let validate_invocation = execution_info
.validate_call_info
.map(|call_info| FunctionInvocation::from_call_info(call_info, versioned_constants));
let maybe_function_invocation = execution_info
.execute_call_info
.map(|call_info| FunctionInvocation::from_call_info(call_info, versioned_constants));
let fee_transfer_invocation = execution_info
.fee_transfer_call_info
.map(|call_info| FunctionInvocation::from_call_info(call_info, versioned_constants));

let computation_resources = validate_invocation
.as_ref()
Expand Down
35 changes: 29 additions & 6 deletions crates/executor/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, HashSet};

use blockifier::execution::call_info::OrderedL2ToL1Message;
use blockifier::fee::fee_utils::get_vm_resources_cost;
use blockifier::transaction::objects::TransactionExecutionInfo;
use pathfinder_common::{
CasmHash,
Expand Down Expand Up @@ -311,11 +312,18 @@ pub struct DataAvailabilityResources {
pub l1_data_gas: u128,
}

impl From<blockifier::execution::call_info::CallInfo> for FunctionInvocation {
fn from(call_info: blockifier::execution::call_info::CallInfo) -> Self {
impl FunctionInvocation {
pub fn from_call_info(
call_info: blockifier::execution::call_info::CallInfo,
versioned_constants: &blockifier::versioned_constants::VersionedConstants,
) -> Self {
let messages = ordered_l2_to_l1_messages(&call_info);

let internal_calls = call_info.inner_calls.into_iter().map(Into::into).collect();
let internal_calls = call_info
.inner_calls
.into_iter()
.map(|call_info| Self::from_call_info(call_info, versioned_constants))
.collect();

let events = call_info
.execution
Expand All @@ -332,6 +340,22 @@ impl From<blockifier::execution::call_info::CallInfo> for FunctionInvocation {
.map(IntoFelt::into_felt)
.collect();

let gas_vector = match call_info.tracked_resource {
blockifier::execution::contract_class::TrackedResource::CairoSteps => {
get_vm_resources_cost(
versioned_constants,
&call_info.resources,
0,
&starknet_api::transaction::fields::GasVectorComputationMode::NoL2Gas,
)
}
blockifier::execution::contract_class::TrackedResource::SierraGas => GasVector {
l1_gas: 0u64.into(),
l1_data_gas: 0u64.into(),
l2_gas: call_info.execution.gas_consumed.into(),
},
};

Self {
calldata: call_info
.call
Expand All @@ -357,9 +381,8 @@ impl From<blockifier::execution::call_info::CallInfo> for FunctionInvocation {
result,
computation_resources: call_info.resources.into(),
execution_resources: InnerCallExecutionResources {
l1_gas: call_info.execution.gas_consumed.into(),
// TODO: Use proper l2_gas value for Starknet 0.13.3
l2_gas: 0,
l1_gas: gas_vector.l1_gas.0.into(),
l2_gas: gas_vector.l2_gas.0.into(),
},
}
}
Expand Down

0 comments on commit 2e97034

Please sign in to comment.