Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier): rename function gas_price to l1_gas_price #340

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/fee/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
}

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 @@ -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)
}
3 changes: 2 additions & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/transaction/execution_flavors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
Loading