From dcb4ce37ddbca3c73bab61e119f10f8a7b9afdc9 Mon Sep 17 00:00:00 2001 From: aner-starkware <147302140+aner-starkware@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:54:20 +0300 Subject: [PATCH] refactor(blockifier): rename function gas_price to l1_gas_price (#340) --- crates/blockifier/src/blockifier/block.rs | 4 ++-- crates/blockifier/src/execution/entry_point.rs | 2 +- crates/blockifier/src/fee/fee_utils.rs | 4 ++-- crates/blockifier/src/fee/gas_usage.rs | 4 ++-- crates/blockifier/src/transaction/account_transaction.rs | 3 ++- .../blockifier/src/transaction/account_transactions_test.rs | 4 ++-- crates/blockifier/src/transaction/execution_flavors_test.rs | 6 +++--- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 83be85d1a6..903bc6cdd9 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -34,14 +34,14 @@ pub struct GasPrices { } impl GasPrices { - pub fn get_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonZeroU128 { + pub fn get_l1_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonZeroU128 { match fee_type { FeeType::Strk => self.strk_l1_gas_price, FeeType::Eth => self.eth_l1_gas_price, } } - pub fn get_data_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonZeroU128 { + pub fn get_l1_data_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonZeroU128 { match fee_type { FeeType::Strk => self.strk_l1_data_gas_price, FeeType::Eth => self.eth_l1_data_gas_price, diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index 998d80cadc..a2b1482f53 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -200,7 +200,7 @@ impl EntryPointExecutionContext { let tx_gas_upper_bound = match tx_info { TransactionInfo::Deprecated(context) => { let max_cairo_steps = context.max_fee.0 - / block_info.gas_prices.get_gas_price_by_fee_type(&tx_info.fee_type()); + / block_info.gas_prices.get_l1_gas_price_by_fee_type(&tx_info.fee_type()); // FIXME: This is saturating in the python bootstrapping test. Fix the value so // that it'll fit in a usize and remove the `as`. usize::try_from(max_cairo_steps).unwrap_or_else(|_| { diff --git a/crates/blockifier/src/fee/fee_utils.rs b/crates/blockifier/src/fee/fee_utils.rs index 3de23b228e..cce1b85227 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -75,8 +75,8 @@ pub fn get_fee_by_gas_vector( fee_type: &FeeType, ) -> Fee { gas_vector.saturated_cost( - u128::from(block_info.gas_prices.get_gas_price_by_fee_type(fee_type)), - u128::from(block_info.gas_prices.get_data_gas_price_by_fee_type(fee_type)), + u128::from(block_info.gas_prices.get_l1_gas_price_by_fee_type(fee_type)), + u128::from(block_info.gas_prices.get_l1_data_gas_price_by_fee_type(fee_type)), ) } diff --git a/crates/blockifier/src/fee/gas_usage.rs b/crates/blockifier/src/fee/gas_usage.rs index 3bfa13064e..8451d298ef 100644 --- a/crates/blockifier/src/fee/gas_usage.rs +++ b/crates/blockifier/src/fee/gas_usage.rs @@ -197,7 +197,7 @@ pub fn compute_discounted_gas_from_gas_vector( 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 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); + let gas_price = gas_prices.get_l1_gas_price_by_fee_type(&fee_type); + let data_gas_price = gas_prices.get_l1_data_gas_price_by_fee_type(&fee_type); gas_usage + u128_div_ceil(blob_gas_usage * u128::from(data_gas_price), gas_price) } diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 40be142f57..9cbe5a1db5 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -219,7 +219,8 @@ impl AccountTransaction { })?; } - let actual_l1_gas_price = block_info.gas_prices.get_gas_price_by_fee_type(fee_type); + let actual_l1_gas_price = + block_info.gas_prices.get_l1_gas_price_by_fee_type(fee_type); if max_l1_gas_price < actual_l1_gas_price.into() { return Err(TransactionFeeError::MaxL1GasPriceTooLow { max_l1_gas_price, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 5e99b92386..205f39194c 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -427,7 +427,7 @@ fn test_max_fee_limit_validate( // works. resource_bounds: l1_resource_bounds( estimated_min_l1_gas.try_into().expect("Failed to convert u128 to u64."), - block_info.gas_prices.get_gas_price_by_fee_type(&account_tx.fee_type()).into() + block_info.gas_prices.get_l1_gas_price_by_fee_type(&account_tx.fee_type()).into() ), ..tx_args }, @@ -913,7 +913,7 @@ fn test_max_fee_to_max_steps_conversion( let actual_gas_used_as_u128: u128 = actual_gas_used.into(); let actual_fee = actual_gas_used_as_u128 * 100000000000; let actual_strk_gas_price = - block_context.block_info.gas_prices.get_gas_price_by_fee_type(&FeeType::Strk); + block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Strk); let execute_calldata = create_calldata( contract_address, "with_arg", diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 5bc4acecd6..2ce9780ead 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -175,7 +175,7 @@ fn test_simulate_validate_charge_fee_pre_validate( // The max resource bounds fixture is not used here because this function already has the // maximum number of arguments. let resource_bounds = l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE); - let gas_price = block_context.block_info.gas_prices.get_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&fee_type); let FlavorTestInitialState { mut state, account_address, @@ -419,7 +419,7 @@ fn test_simulate_validate_charge_fee_mid_execution( ) { let block_context = BlockContext::create_for_account_testing(); let chain_info = &block_context.chain_info; - let gas_price = block_context.block_info.gas_prices.get_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&fee_type); let FlavorTestInitialState { mut state, account_address, @@ -575,7 +575,7 @@ fn test_simulate_validate_charge_fee_post_execution( #[case] is_deprecated: bool, ) { let block_context = BlockContext::create_for_account_testing(); - let gas_price = block_context.block_info.gas_prices.get_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&fee_type); let chain_info = &block_context.chain_info; let fee_token_address = chain_info.fee_token_address(&fee_type);