Skip to content

Commit

Permalink
Merge pull request #2605 from eqlabs/krisztian/use-blockifier-for-inn…
Browse files Browse the repository at this point in the history
…er-call-gas-vector-calculation

refactor(executor): use blockifier's inner call gas vector calculation
  • Loading branch information
kkovaacs authored Feb 18, 2025
2 parents 8d0cdf6 + 9dfd000 commit 37a9446
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ axum = "0.7.5"
base64 = "0.13.1"
bincode = "2.0.0-rc.3"
bitvec = "1.0.1"
blockifier = "0.14.0-rc.1"
blockifier = { version = "0.14.0-rc.1", features = ["node_api"] }
bloomfilter = "1.0.12"
bytes = "1.4.0"
cached = "0.44.0"
Expand Down
6 changes: 0 additions & 6 deletions crates/executor/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ pub fn simulate(
state_diff,
block_context.versioned_constants(),
&gas_vector_computation_mode,
block_context.block_info().use_kzg_da,
),
})
})
Expand Down Expand Up @@ -222,7 +221,6 @@ pub fn trace(
state_diff,
block_context.versioned_constants(),
&gas_vector_computation_mode,
block_context.block_info().use_kzg_da,
);
traces.push((hash, trace));
}
Expand Down Expand Up @@ -372,30 +370,26 @@ fn to_trace(
state_diff: StateDiff,
versioned_constants: &VersionedConstants,
gas_vector_computation_mode: &GasVectorComputationMode,
use_kzg_da: bool,
) -> TransactionTrace {
let validate_invocation = execution_info.validate_call_info.map(|call_info| {
FunctionInvocation::from_call_info(
call_info,
versioned_constants,
gas_vector_computation_mode,
use_kzg_da,
)
});
let maybe_function_invocation = execution_info.execute_call_info.map(|call_info| {
FunctionInvocation::from_call_info(
call_info,
versioned_constants,
gas_vector_computation_mode,
use_kzg_da,
)
});
let fee_transfer_invocation = execution_info.fee_transfer_call_info.map(|call_info| {
FunctionInvocation::from_call_info(
call_info,
versioned_constants,
gas_vector_computation_mode,
use_kzg_da,
)
});

Expand Down
55 changes: 4 additions & 51 deletions crates/executor/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::{BTreeMap, HashSet};

use blockifier::execution::call_info::OrderedL2ToL1Message;
use blockifier::fee::resources::{StarknetResources, TransactionResources};
use blockifier::transaction::objects::TransactionExecutionInfo;
use pathfinder_common::{
CasmHash,
Expand Down Expand Up @@ -314,68 +313,22 @@ pub struct DataAvailabilityResources {
}

impl FunctionInvocation {
// This estimation purposefully ignores some of the gas costs since we don't
// have all the necessary defails to compute them and those will be taken
// into account only when computing the transaction receipt.
// Ignored costs include state change costs, code size related costs for
// DECLARE, L1 handler payload size and Starknet OS overhead.
fn estimate_gas_consumed(
call_info: &blockifier::execution::call_info::CallInfo,
versioned_constants: &blockifier::versioned_constants::VersionedConstants,
gas_vector_computation_mode: &starknet_api::transaction::fields::GasVectorComputationMode,
use_kzg_da: bool,
) -> GasVector {
let execution_summary = call_info.summarize(versioned_constants);
let sierra_gas = execution_summary.charged_resources.gas_consumed;
let vm_resources = execution_summary
.charged_resources
.vm_resources
.filter_unused_builtins();
let state_changes = blockifier::state::cached_state::StateChanges::default();
let state_resources = blockifier::fee::resources::StateResources::new(
&state_changes,
None,
Default::default(),
);
let starknet_resources =
StarknetResources::new(0, 0, 0, state_resources, None, execution_summary);
let tx_resources = TransactionResources {
starknet_resources,
computation: blockifier::fee::resources::ComputationResources {
vm_resources,
n_reverted_steps: 0,
sierra_gas,
reverted_sierra_gas: 0u64.into(),
},
};
tx_resources.to_gas_vector(versioned_constants, use_kzg_da, gas_vector_computation_mode)
}

pub fn from_call_info(
call_info: blockifier::execution::call_info::CallInfo,
versioned_constants: &blockifier::versioned_constants::VersionedConstants,
gas_vector_computation_mode: &starknet_api::transaction::fields::GasVectorComputationMode,
use_kzg_da: bool,
) -> Self {
let gas_consumed = Self::estimate_gas_consumed(
&call_info,
versioned_constants,
gas_vector_computation_mode,
use_kzg_da,
);
let gas_consumed = call_info
.summarize(versioned_constants)
.to_partial_gas_vector(versioned_constants, gas_vector_computation_mode);

let messages = ordered_l2_to_l1_messages(&call_info);

let internal_calls = call_info
.inner_calls
.into_iter()
.map(|call_info| {
Self::from_call_info(
call_info,
versioned_constants,
gas_vector_computation_mode,
use_kzg_da,
)
Self::from_call_info(call_info, versioned_constants, gas_vector_computation_mode)
})
.collect();

Expand Down

0 comments on commit 37a9446

Please sign in to comment.