Skip to content

Commit

Permalink
chore(blockifier): rename the getters for the gas prices struct (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Nov 28, 2024
1 parent 23231e4 commit 48037a7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 41 deletions.
14 changes: 7 additions & 7 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions crates/blockifier/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ 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,
l2_gas: l2_gas_resource_bounds,
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,
Expand Down
17 changes: 7 additions & 10 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/transaction/execution_flavors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/post_execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 5 additions & 6 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions crates/papyrus_execution/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ pub(crate) fn tx_execution_output_to_fee_estimation(
) -> ExecutionResult<FeeEstimation> {
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;
Expand Down

0 comments on commit 48037a7

Please sign in to comment.