Skip to content

Commit

Permalink
feat(execution): add l2_gas_price to FeeEstimation
Browse files Browse the repository at this point in the history
  • Loading branch information
TzahiTaub authored and yoavGrs committed Sep 22, 2024
1 parent e26b0ea commit da4fbcf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/papyrus_execution/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ pub struct FeeEstimation {
pub data_gas_consumed: Felt,
/// The gas price for DA blob.
pub data_gas_price: GasPrice,
// TODO(Tzahi): Add l2_gas_consumed. Verify overall_fee estimation of l1_gas_price only is
// close enough (as there are roundings) to the fee of both l1_gas_price and l2_gas_price.
/// The L2 gas price for execution.
pub l2_gas_price: GasPrice,
/// The total amount of fee. This is equal to:
/// gas_consumed * gas_price + data_gas_consumed * data_gas_price.
pub overall_fee: Fee,
Expand Down Expand Up @@ -153,7 +157,7 @@ pub(crate) fn tx_execution_output_to_fee_estimation(
block_context: &BlockContext,
) -> ExecutionResult<FeeEstimation> {
let gas_prices = &block_context.block_info().gas_prices;
let (gas_price, data_gas_price) = (
let (l1_gas_price, l1_data_gas_price, l2_gas_price) = (
GasPrice(
gas_prices.get_l1_gas_price_by_fee_type(&tx_execution_output.price_unit.into()).get(),
),
Expand All @@ -162,15 +166,19 @@ pub(crate) fn tx_execution_output_to_fee_estimation(
.get_l1_data_gas_price_by_fee_type(&tx_execution_output.price_unit.into())
.get(),
),
GasPrice(
gas_prices.get_l2_gas_price_by_fee_type(&tx_execution_output.price_unit.into()).get(),
),
);

let gas_vector = tx_execution_output.execution_info.receipt.gas;

Ok(FeeEstimation {
gas_consumed: gas_vector.l1_gas.into(),
gas_price,
gas_price: l1_gas_price,
data_gas_consumed: gas_vector.l1_data_gas.into(),
data_gas_price,
data_gas_price: l1_data_gas_price,
l2_gas_price,
overall_fee: tx_execution_output.execution_info.receipt.fee,
unit: tx_execution_output.price_unit,
})
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_execution/src/testing_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ auto_impl_get_test_instance! {
pub gas_price: GasPrice,
pub data_gas_consumed: Felt,
pub data_gas_price: GasPrice,
pub l2_gas_price: GasPrice,
pub overall_fee: Fee,
pub unit: PriceUnit,
}
Expand Down
8 changes: 8 additions & 0 deletions crates/papyrus_rpc/src/v0_8/execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ lazy_static! {
price_in_wei: GasPrice(100 * u128::pow(10, 9)),
price_in_fri: GasPrice(0),
};
//TODO: Tests for data_gas_price and l2_gas_price.
pub static ref DATA_GAS_PRICE: GasPricePerToken = GasPricePerToken{
price_in_wei: GasPrice(1),
price_in_fri: GasPrice(0),
};
pub static ref L2_GAS_PRICE: GasPricePerToken = GasPricePerToken{
price_in_wei: GasPrice(1),
price_in_fri: GasPrice(0),
};
pub static ref MAX_FEE: Fee = Fee(1000000 * GAS_PRICE.price_in_wei.0);
pub static ref BLOCK_TIMESTAMP: BlockTimestamp = BlockTimestamp(1234);
pub static ref SEQUENCER_ADDRESS: SequencerContractAddress =
Expand All @@ -175,6 +180,7 @@ lazy_static! {
gas_price: GAS_PRICE.price_in_wei,
data_gas_consumed: Felt::ZERO,
data_gas_price: DATA_GAS_PRICE.price_in_wei,
l2_gas_price: L2_GAS_PRICE.price_in_wei,
overall_fee: Fee(166500000000000,),
unit: PriceUnit::Wei,
};
Expand All @@ -184,6 +190,7 @@ lazy_static! {
gas_price: GAS_PRICE.price_in_wei,
data_gas_consumed: Felt::ZERO,
data_gas_price: DATA_GAS_PRICE.price_in_wei,
l2_gas_price: L2_GAS_PRICE.price_in_wei,
overall_fee: Fee(166500000000000,),
unit: PriceUnit::Wei,
};
Expand Down Expand Up @@ -1208,6 +1215,7 @@ async fn call_estimate_message_fee() {
gas_price: GAS_PRICE.price_in_wei,
data_gas_consumed: Felt::ZERO,
data_gas_price: DATA_GAS_PRICE.price_in_wei,
l2_gas_price: L2_GAS_PRICE.price_in_wei,
overall_fee: Fee(0),
unit: PriceUnit::default(),
};
Expand Down

0 comments on commit da4fbcf

Please sign in to comment.