Skip to content

Commit

Permalink
build(fee): add l2_gas field to gas vector
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Jul 25, 2024
1 parent d1ebb90 commit 932bdce
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions crates/blockifier/src/concurrency/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ pub fn fill_sequencer_balance_reads(
) {
let storage_read_values = if fee_transfer_call_info.inner_calls.is_empty() {
&mut fee_transfer_call_info.storage_read_values
} else
// Proxy pattern.
{
} else {
// Proxy pattern.
assert_eq!(
fee_transfer_call_info.inner_calls.len(),
1,
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier/src/fee/actual_cost_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ fn test_calculate_tx_gas_usage_basic<'a>(#[values(false, true)] use_kzg_da: bool
let manual_gas_computation = GasVector {
l1_gas: u128_from_usize(manual_starknet_gas_usage + manual_sharp_gas_usage),
l1_data_gas: manual_sharp_blob_gas_usage,
..Default::default()
};

assert_eq!(l2_to_l1_messages_gas_usage_vector, manual_gas_computation);
Expand Down Expand Up @@ -272,6 +273,7 @@ fn test_calculate_tx_gas_usage_basic<'a>(#[values(false, true)] use_kzg_da: bool
l1_data_gas: combined_cases_starknet_resources
.get_state_changes_cost(use_kzg_da)
.l1_data_gas,
..Default::default()
};

assert_eq!(expected_gas_vector, gas_usage_vector);
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/fee/fee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fn test_discounted_gas_overdraft(
gas: GasVector {
l1_gas: u128_from_usize(l1_gas_used),
l1_data_gas: u128_from_usize(l1_data_gas_used),
..Default::default()
},
..Default::default()
};
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/fee/gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn get_da_gas_cost(state_changes_count: &StateChangesCount, use_kzg_da: bool
(u128_from_usize(gas), 0)
};

GasVector { l1_gas, l1_data_gas: blob_gas }
GasVector { l1_gas, l1_data_gas: blob_gas, ..Default::default() }
}

/// Returns the number of felts added to the output messages segment as a result of adding
Expand Down Expand Up @@ -195,7 +195,7 @@ pub fn compute_discounted_gas_from_gas_vector(
tx_context: &TransactionContext,
) -> u128 {
let gas_prices = &tx_context.block_context.block_info.gas_prices;
let GasVector { l1_gas: gas_usage, l1_data_gas: blob_gas_usage } = gas_usage_vector;
let GasVector { l1_gas: gas_usage, l1_data_gas: blob_gas_usage, .. } = gas_usage_vector;
let fee_type = tx_context.tx_info.fee_type();
let gas_price = gas_prices.get_gas_price_by_fee_type(&fee_type);
let data_gas_price = gas_prices.get_data_gas_price_by_fee_type(&fee_type);
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fn test_get_message_segment_length(
fn test_compute_discounted_gas_from_gas_vector() {
let tx_context =
BlockContext::create_for_testing().to_tx_context(&account_invoke_tx(invoke_tx_args! {}));
let gas_usage = GasVector { l1_gas: 100, l1_data_gas: 2 };
let gas_usage = GasVector { l1_gas: 100, l1_data_gas: 2, ..Default::default() };
let actual_result = compute_discounted_gas_from_gas_vector(&gas_usage, &tx_context);

let result_div_ceil = gas_usage.l1_gas
Expand Down
7 changes: 4 additions & 3 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ pub struct DeprecatedTransactionInfo {
pub struct GasVector {
pub l1_gas: u128,
pub l1_data_gas: u128,
pub l2_gas: u128,
}

impl GasVector {
pub fn from_l1_gas(l1_gas: u128) -> Self {
Self { l1_gas, l1_data_gas: 0 }
Self { l1_gas, ..Default::default() }
}

pub fn from_l1_data_gas(l1_data_gas: u128) -> Self {
Self { l1_gas: 0, l1_data_gas }
Self { l1_data_gas, ..Default::default() }
}

/// Computes the cost (in fee token units) of the gas vector (saturating on overflow).
Expand Down Expand Up @@ -462,7 +463,7 @@ impl TransactionResources {
use_kzg_da: bool,
with_reverted_steps: bool,
) -> ResourcesMapping {
let GasVector { l1_gas, l1_data_gas } =
let GasVector { l1_gas, l1_data_gas, .. } =
self.starknet_resources.to_gas_vector(versioned_constants, use_kzg_da);
let mut resources = self.vm_resources.to_resources_mapping();
resources.0.extend(HashMap::from([
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) {
// TODO(Nimrod, 1/5/2024): Change these hard coded values to match to the transaction resources
// (currently matches only starknet resources).
let expected_gas = match use_kzg_da {
true => GasVector { l1_gas: 16023, l1_data_gas: 128 },
true => GasVector { l1_gas: 16023, l1_data_gas: 128, ..Default::default() },
false => GasVector::from_l1_gas(17675),
};
let expected_da_gas = match use_kzg_da {
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_execution/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl TryFrom<(CallInfo, GasVector)> for FunctionInvocation {
// Can't implement `TryFrom` because both types are from external crates.
fn vm_resources_to_execution_resources(
vm_resources: VmExecutionResources,
GasVector { l1_gas, l1_data_gas }: GasVector,
GasVector { l1_gas, l1_data_gas, .. }: GasVector,
) -> ExecutionResult<ExecutionResources> {
let mut builtin_instance_counter = HashMap::new();
for (builtin_name, count) in vm_resources.builtin_instance_counter {
Expand Down

0 comments on commit 932bdce

Please sign in to comment.