Skip to content
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

refactor(executor): use blockifier's inner call gas vector calculation #2605

Merged
Merged
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
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 @@ -138,7 +138,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 @@ -221,7 +220,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 @@ -371,30 +369,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
Loading