From ff51985f5e11ed0dc1698e25d6623c983cdff1d6 Mon Sep 17 00:00:00 2001 From: Nimrod Weiss Date: Wed, 14 Aug 2024 14:57:29 +0300 Subject: [PATCH] build(fee): add calldata and signature l2 cost --- crates/blockifier/src/transaction/objects.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index 3ddc2ab6ce..d68272d667 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -190,6 +190,10 @@ impl GasVector { Self { l1_data_gas, ..Default::default() } } + pub fn from_l2_gas(l2_gas: u128) -> Self { + Self { l2_gas, ..Default::default() } + } + /// Computes the cost (in fee token units) of the gas vector (saturating on overflow). pub fn saturated_cost(&self, gas_price: u128, blob_gas_price: u128) -> Fee { let l1_gas_cost = self.l1_gas.checked_mul(gas_price).unwrap_or_else(|| { @@ -350,16 +354,12 @@ impl StarknetResources { versioned_constants: &VersionedConstants, include_l2_gas: bool, ) -> GasVector { - if include_l2_gas { - todo!() - } else { - // TODO(Avi, 20/2/2024): Calculate the number of bytes instead of the number of felts. - let total_data_size = u128_from_usize(self.calldata_length + self.signature_length); - let l1_gas = (versioned_constants.l2_resource_gas_costs.gas_per_data_felt - * total_data_size) - .to_integer(); - GasVector::from_l1_gas(l1_gas) - } + // TODO(Avi, 20/2/2024): Calculate the number of bytes instead of the number of felts. + let total_data_size = u128_from_usize(self.calldata_length + self.signature_length); + let gas = (versioned_constants.l2_resource_gas_costs.gas_per_data_felt * total_data_size) + .to_integer(); + // Does that make sense?? + if include_l2_gas { GasVector::from_l2_gas(gas) } else { GasVector::from_l1_gas(gas) } } /// Returns an estimation of the gas usage for processing L1<>L2 messages on L1. Accounts for