diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 760afc8861..05ee20a2f4 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -90,19 +90,19 @@ impl GasPrices { gas_prices } - pub fn get_l1_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice { - self.get_gas_prices_by_fee_type(fee_type).l1_gas_price + pub fn l1_gas_price(&self, fee_type: &FeeType) -> NonzeroGasPrice { + self.gas_price_vector(fee_type).l1_gas_price } - pub fn get_l1_data_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice { - self.get_gas_prices_by_fee_type(fee_type).l1_data_gas_price + pub fn l1_data_gas_price(&self, fee_type: &FeeType) -> NonzeroGasPrice { + self.gas_price_vector(fee_type).l1_data_gas_price } - pub fn get_l2_gas_price_by_fee_type(&self, fee_type: &FeeType) -> NonzeroGasPrice { - self.get_gas_prices_by_fee_type(fee_type).l2_gas_price + pub fn l2_gas_price(&self, fee_type: &FeeType) -> NonzeroGasPrice { + self.gas_price_vector(fee_type).l2_gas_price } - pub fn get_gas_prices_by_fee_type(&self, fee_type: &FeeType) -> &GasPriceVector { + pub fn gas_price_vector(&self, fee_type: &FeeType) -> &GasPriceVector { match fee_type { FeeType::Strk => &self.strk_gas_prices, FeeType::Eth => &self.eth_gas_prices, diff --git a/crates/blockifier/src/context.rs b/crates/blockifier/src/context.rs index e77c5e0382..5c6700b9d0 100644 --- a/crates/blockifier/src/context.rs +++ b/crates/blockifier/src/context.rs @@ -39,10 +39,7 @@ impl TransactionContext { self.tx_info.gas_mode() } pub fn get_gas_prices(&self) -> &GasPriceVector { - self.block_context - .block_info - .gas_prices - .get_gas_prices_by_fee_type(&self.tx_info.fee_type()) + self.block_context.block_info.gas_prices.gas_price_vector(&self.tx_info.fee_type()) } /// Returns the initial Sierra gas of the transaction. diff --git a/crates/blockifier/src/execution/entry_point.rs b/crates/blockifier/src/execution/entry_point.rs index 048023e0c1..1f7bb418bd 100644 --- a/crates/blockifier/src/execution/entry_point.rs +++ b/crates/blockifier/src/execution/entry_point.rs @@ -293,9 +293,9 @@ impl EntryPointExecutionContext { if l1_gas_per_step.is_zero() { u64::MAX } else { - let induced_l1_gas_limit = context.max_fee.saturating_div( - block_info.gas_prices.get_l1_gas_price_by_fee_type(&tx_info.fee_type()), - ); + let induced_l1_gas_limit = context + .max_fee + .saturating_div(block_info.gas_prices.l1_gas_price(&tx_info.fee_type())); (l1_gas_per_step.inv() * induced_l1_gas_limit.0).to_integer() } } diff --git a/crates/blockifier/src/fee/fee_utils.rs b/crates/blockifier/src/fee/fee_utils.rs index 89a3685f3e..e217d3d6b2 100644 --- a/crates/blockifier/src/fee/fee_utils.rs +++ b/crates/blockifier/src/fee/fee_utils.rs @@ -79,7 +79,7 @@ pub fn get_fee_by_gas_vector( gas_vector: GasVector, fee_type: &FeeType, ) -> Fee { - gas_vector.cost(block_info.gas_prices.get_gas_prices_by_fee_type(fee_type)) + gas_vector.cost(block_info.gas_prices.gas_price_vector(fee_type)) } /// Returns the current fee balance and a boolean indicating whether the balance covers the fee. diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 479e2d78e7..c53d6092d5 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -310,7 +310,7 @@ impl AccountTransaction { L1Gas, l1_gas_resource_bounds, minimal_gas_amount_vector.to_discounted_l1_gas(tx_context.get_gas_prices()), - block_info.gas_prices.get_l1_gas_price_by_fee_type(fee_type), + block_info.gas_prices.l1_gas_price(fee_type), )], ValidResourceBounds::AllResources(AllResourceBounds { l1_gas: l1_gas_resource_bounds, @@ -318,7 +318,7 @@ impl AccountTransaction { l1_data_gas: l1_data_gas_resource_bounds, }) => { let GasPriceVector { l1_gas_price, l1_data_gas_price, l2_gas_price } = - block_info.gas_prices.get_gas_prices_by_fee_type(fee_type); + block_info.gas_prices.gas_price_vector(fee_type); vec![ ( L1Gas, diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index a73a74f19c..ae72695dba 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -548,13 +548,13 @@ fn test_max_fee_limit_validate( GasVectorComputationMode::All => create_all_resource_bounds( estimated_min_gas_usage_vector.l1_gas, block_info.gas_prices - .get_l1_gas_price_by_fee_type(&account_tx.fee_type()).into(), + .l1_gas_price(&account_tx.fee_type()).into(), estimated_min_gas_usage_vector.l2_gas, block_info.gas_prices - .get_l2_gas_price_by_fee_type(&account_tx.fee_type()).into(), + .l2_gas_price(&account_tx.fee_type()).into(), estimated_min_gas_usage_vector.l1_data_gas, block_info.gas_prices - .get_l1_data_gas_price_by_fee_type(&account_tx.fee_type()).into(), + .l1_data_gas_price(&account_tx.fee_type()).into(), ), }, ..tx_args @@ -1052,9 +1052,7 @@ fn test_max_fee_computation_from_tx_bounds(block_context: BlockContext) { account_tx_max_fee, (steps_per_l1_gas * max_fee - .checked_div( - block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Eth), - ) + .checked_div(block_context.block_info.gas_prices.eth_gas_prices.l1_gas_price,) .unwrap() .0) .to_integer(), @@ -1108,8 +1106,7 @@ fn test_max_fee_to_max_steps_conversion( ) .into(); let actual_fee = u128::from(actual_gas_used.0) * 100000000000; - let actual_strk_gas_price = - block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Strk); + let actual_strk_gas_price = block_context.block_info.gas_prices.strk_gas_prices.l1_gas_price; let execute_calldata = create_calldata( contract_address, "with_arg", @@ -1205,11 +1202,11 @@ fn test_insufficient_max_fee_reverts( let resource_used_depth1 = match gas_mode { GasVectorComputationMode::NoL2Gas => l1_resource_bounds( tx_execution_info1.receipt.gas.l1_gas, - block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Strk).into(), + block_context.block_info.gas_prices.strk_gas_prices.l1_gas_price.into(), ), GasVectorComputationMode::All => ValidResourceBounds::all_bounds_from_vectors( &tx_execution_info1.receipt.gas, - block_context.block_info.gas_prices.get_gas_prices_by_fee_type(&FeeType::Strk), + &block_context.block_info.gas_prices.strk_gas_prices, ), }; let tx_execution_info2 = run_invoke_tx( diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index 3f6a43b4d1..edf7058021 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -291,7 +291,7 @@ fn test_simulate_validate_pre_validate_with_charge_fee( } // Second scenario: resource bounds greater than balance. - let gas_price = block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.l1_gas_price(&fee_type); let balance_over_gas_price = BALANCE.checked_div(gas_price).unwrap(); let result = account_invoke_tx(invoke_tx_args! { max_fee: Fee(BALANCE.0 + 1), @@ -409,7 +409,7 @@ fn test_simulate_validate_pre_validate_not_charge_fee( execute_and_check_gas_and_fee!(Fee(10), l1_resource_bounds(10_u8.into(), 10_u8.into())); // Second scenario: resource bounds greater than balance. - let gas_price = block_context.block_info.gas_prices.get_l1_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.l1_gas_price(&fee_type); let balance_over_gas_price = BALANCE.checked_div(gas_price).unwrap(); execute_and_check_gas_and_fee!( Fee(BALANCE.0 + 1), @@ -548,7 +548,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_l1_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.l1_gas_price(&fee_type); let FlavorTestInitialState { mut state, account_address, @@ -714,7 +714,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_l1_gas_price_by_fee_type(&fee_type); + let gas_price = block_context.block_info.gas_prices.l1_gas_price(&fee_type); let chain_info = &block_context.chain_info; let fee_token_address = chain_info.fee_token_address(&fee_type); diff --git a/crates/blockifier/src/transaction/post_execution_test.rs b/crates/blockifier/src/transaction/post_execution_test.rs index 98956e0813..939c407b29 100644 --- a/crates/blockifier/src/transaction/post_execution_test.rs +++ b/crates/blockifier/src/transaction/post_execution_test.rs @@ -269,7 +269,7 @@ fn test_revert_on_resource_overuse( block_context.block_info.use_kzg_da = true; let gas_mode = resource_bounds.get_gas_vector_computation_mode(); let fee_type = if version == TransactionVersion::THREE { FeeType::Strk } else { FeeType::Eth }; - let gas_prices = block_context.block_info.gas_prices.get_gas_prices_by_fee_type(&fee_type); + let gas_prices = block_context.block_info.gas_prices.gas_price_vector(&fee_type); let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = init_data_by_version(&block_context.chain_info, cairo_version); diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 2a6d85ad98..a7a222e9cc 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1083,7 +1083,7 @@ fn test_insufficient_new_resource_bounds_pre_validation( l1_gas_price: actual_strk_l1_gas_price, l1_data_gas_price: actual_strk_l1_data_gas_price, l2_gas_price: actual_strk_l2_gas_price, - } = block_context.block_info.gas_prices.get_gas_prices_by_fee_type(&FeeType::Strk); + } = block_context.block_info.gas_prices.strk_gas_prices; let minimal_gas_vector = estimate_minimal_gas_vector(block_context, tx, &GasVectorComputationMode::All); @@ -1217,9 +1217,8 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( let gas_prices = &block_context.block_info.gas_prices; // TODO(Aner, 21/01/24) change to linear combination. - let minimal_fee = minimal_l1_gas - .checked_mul(gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Eth).into()) - .unwrap(); + let minimal_fee = + minimal_l1_gas.checked_mul(gas_prices.eth_gas_prices.l1_gas_price.get()).unwrap(); // Max fee too low (lower than minimal estimated fee). let invalid_max_fee = Fee(minimal_fee.0 - 1); let invalid_v1_tx = account_invoke_tx( @@ -1237,7 +1236,7 @@ fn test_insufficient_deprecated_resource_bounds_pre_validation( ); // Test V3 transaction. - let actual_strk_l1_gas_price = gas_prices.get_l1_gas_price_by_fee_type(&FeeType::Strk); + let actual_strk_l1_gas_price = gas_prices.strk_gas_prices.l1_gas_price; // Max L1 gas amount too low, old resource bounds. // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the conversion works. @@ -1291,7 +1290,7 @@ fn test_actual_fee_gt_resource_bounds( block_context.block_info.use_kzg_da = true; let mut nonce_manager = NonceManager::default(); let gas_mode = resource_bounds.get_gas_vector_computation_mode(); - let gas_prices = block_context.block_info.gas_prices.get_gas_prices_by_fee_type(&FeeType::Strk); + let gas_prices = &block_context.block_info.gas_prices.strk_gas_prices; let account_contract = FeatureContract::AccountWithoutValidations(account_cairo_version); let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let state = &mut test_state( diff --git a/crates/papyrus_execution/src/objects.rs b/crates/papyrus_execution/src/objects.rs index f80ab9e6c2..d44c769310 100644 --- a/crates/papyrus_execution/src/objects.rs +++ b/crates/papyrus_execution/src/objects.rs @@ -164,9 +164,9 @@ pub(crate) fn tx_execution_output_to_fee_estimation( ) -> ExecutionResult { let gas_prices = &block_context.block_info().gas_prices; let (l1_gas_price, l1_data_gas_price, l2_gas_price) = ( - gas_prices.get_l1_gas_price_by_fee_type(&tx_execution_output.price_unit.into()).get(), - gas_prices.get_l1_data_gas_price_by_fee_type(&tx_execution_output.price_unit.into()).get(), - gas_prices.get_l2_gas_price_by_fee_type(&tx_execution_output.price_unit.into()).get(), + gas_prices.l1_gas_price(&tx_execution_output.price_unit.into()).get(), + gas_prices.l1_data_gas_price(&tx_execution_output.price_unit.into()).get(), + gas_prices.l2_gas_price(&tx_execution_output.price_unit.into()).get(), ); let gas_vector = tx_execution_output.execution_info.receipt.gas;