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 4439172
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 29 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
53 changes: 35 additions & 18 deletions crates/rpc/src/method/simulate_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![felt!("0x1")],
computation_resources: declare_fee_transfer_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 4,
l2_gas: 0,
},
}
}

Expand All @@ -956,8 +958,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![],
computation_resources: declare_validate_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 1,
l2_gas: 0,
},
}
}

Expand Down Expand Up @@ -1234,8 +1238,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![],
computation_resources: universal_deployer_validate_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 1,
l2_gas: 0,
},
}
}

Expand Down Expand Up @@ -1308,7 +1314,7 @@ pub(crate) mod tests {
pedersen_builtin_applications: 7,
..Default::default()
},
execution_resources: pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources { l1_gas: 4, l2_gas: 0 },
}
],
class_hash: Some(DUMMY_ACCOUNT_CLASS_HASH.0),
Expand All @@ -1334,7 +1340,10 @@ pub(crate) mod tests {
*DEPLOYED_CONTRACT_ADDRESS.get(),
],
computation_resources: universal_deployer_execute_computation_resources(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 6,
l2_gas: 0,
},
}
}

Expand Down Expand Up @@ -1371,8 +1380,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![felt!("0x1")],
computation_resources: universal_deployer_fee_transfer_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 4,
l2_gas: 0,
},
}
}

Expand Down Expand Up @@ -1622,8 +1633,10 @@ pub(crate) mod tests {
],
messages: vec![],
result: vec![],
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 1,
l2_gas: 0,
},
computation_resources: invoke_validate_computation_resources(),
}
}
Expand Down Expand Up @@ -1654,8 +1667,8 @@ pub(crate) mod tests {
},
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 12840,
..Default::default()
l1_gas: 1,
l2_gas: 0,
},
}],
class_hash: Some(DUMMY_ACCOUNT_CLASS_HASH.0),
Expand All @@ -1672,8 +1685,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![test_storage_value.0],
computation_resources: invoke_execute_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 3,
l2_gas: 0,
},
}
}

Expand Down Expand Up @@ -1709,8 +1724,10 @@ pub(crate) mod tests {
messages: vec![],
result: vec![felt!("0x1")],
computation_resources: invoke_fee_transfer_computation_resources(),
execution_resources:
pathfinder_executor::types::InnerCallExecutionResources::default(),
execution_resources: pathfinder_executor::types::InnerCallExecutionResources {
l1_gas: 4,
l2_gas: 0,
},
}
}

Expand Down

0 comments on commit 4439172

Please sign in to comment.