From e26b0ea55b0ee908ba7dcead6f225a9aeb91d515 Mon Sep 17 00:00:00 2001 From: Tzahi Date: Sun, 22 Sep 2024 12:01:54 +0300 Subject: [PATCH] chore(execution): add l2_gas_price to PendingData (#643) --- crates/papyrus_execution/src/lib.rs | 8 +++++--- crates/papyrus_execution/src/objects.rs | 2 ++ crates/papyrus_rpc/src/pending.rs | 1 + crates/papyrus_rpc/src/v0_8/api/api_impl.rs | 2 ++ .../starknet_client/src/reader/objects/pending_data.rs | 9 +++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index e4502626ff..3564b03870 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -303,6 +303,7 @@ fn create_block_context( block_timestamp, l1_gas_price, l1_data_gas_price, + l2_gas_price, sequencer_address, l1_da_mode, ) = match maybe_pending_data { @@ -311,6 +312,7 @@ fn create_block_context( pending_data.timestamp, pending_data.l1_gas_price, pending_data.l1_data_gas_price, + pending_data.l2_gas_price, pending_data.sequencer, pending_data.l1_da_mode, ), @@ -324,6 +326,7 @@ fn create_block_context( header.timestamp, header.l1_gas_price, header.l1_data_gas_price, + header.l2_gas_price, header.sequencer, header.l1_da_mode, ) @@ -351,9 +354,8 @@ fn create_block_context( NonZeroU128::new(l1_gas_price.price_in_fri.0).unwrap_or(NonZeroU128::MIN), NonZeroU128::new(l1_data_gas_price.price_in_wei.0).unwrap_or(NonZeroU128::MIN), NonZeroU128::new(l1_data_gas_price.price_in_fri.0).unwrap_or(NonZeroU128::MIN), - // TODO(Aner - Shahak): fix to come from pending_data/block_header. - NonZeroU128::MIN, - NonZeroU128::MIN, + NonZeroU128::new(l2_gas_price.price_in_wei.0).unwrap_or(NonZeroU128::MIN), + NonZeroU128::new(l2_gas_price.price_in_fri.0).unwrap_or(NonZeroU128::MIN), ), }; let chain_info = ChainInfo { diff --git a/crates/papyrus_execution/src/objects.rs b/crates/papyrus_execution/src/objects.rs index 60f4a0bfa7..78dcb0c710 100644 --- a/crates/papyrus_execution/src/objects.rs +++ b/crates/papyrus_execution/src/objects.rs @@ -502,6 +502,8 @@ pub struct PendingData { pub l1_gas_price: GasPricePerToken, /// The data price of the pending block. pub l1_data_gas_price: GasPricePerToken, + /// The L2 gas price of the pending block. + pub l2_gas_price: GasPricePerToken, /// The data availability mode of the pending block. pub l1_da_mode: L1DataAvailabilityMode, /// The sequencer address of the pending block. diff --git a/crates/papyrus_rpc/src/pending.rs b/crates/papyrus_rpc/src/pending.rs index 38118b8453..34b3e22836 100644 --- a/crates/papyrus_rpc/src/pending.rs +++ b/crates/papyrus_rpc/src/pending.rs @@ -17,6 +17,7 @@ pub(crate) fn client_pending_data_to_execution_pending_data( timestamp: client_pending_data.block.timestamp(), l1_gas_price: client_pending_data.block.l1_gas_price(), l1_data_gas_price: client_pending_data.block.l1_data_gas_price(), + l2_gas_price: client_pending_data.block.l2_gas_price(), l1_da_mode: client_pending_data.block.l1_da_mode(), sequencer: client_pending_data.block.sequencer_address(), } diff --git a/crates/papyrus_rpc/src/v0_8/api/api_impl.rs b/crates/papyrus_rpc/src/v0_8/api/api_impl.rs index 0cb9f8acbb..3afe3ec93b 100644 --- a/crates/papyrus_rpc/src/v0_8/api/api_impl.rs +++ b/crates/papyrus_rpc/src/v0_8/api/api_impl.rs @@ -1143,6 +1143,7 @@ impl JsonRpcServer for JsonRpcServerImpl { timestamp: pending_block.timestamp(), l1_gas_price: pending_block.l1_gas_price(), l1_data_gas_price: pending_block.l1_data_gas_price(), + l2_gas_price: pending_block.l2_gas_price(), l1_da_mode: pending_block.l1_da_mode(), sequencer: pending_block.sequencer_address(), // The pending state diff should be empty since we look at the state in the @@ -1259,6 +1260,7 @@ impl JsonRpcServer for JsonRpcServerImpl { timestamp: client_pending_data.block.timestamp(), l1_gas_price: client_pending_data.block.l1_gas_price(), l1_data_gas_price: client_pending_data.block.l1_data_gas_price(), + l2_gas_price: client_pending_data.block.l2_gas_price(), l1_da_mode: client_pending_data.block.l1_da_mode(), sequencer: client_pending_data.block.sequencer_address(), // The pending state diff should be empty since we look at the state in the diff --git a/crates/starknet_client/src/reader/objects/pending_data.rs b/crates/starknet_client/src/reader/objects/pending_data.rs index f611da2661..a24dba9e18 100644 --- a/crates/starknet_client/src/reader/objects/pending_data.rs +++ b/crates/starknet_client/src/reader/objects/pending_data.rs @@ -159,6 +159,13 @@ impl PendingBlockOrDeprecated { PendingBlockOrDeprecated::Current(block) => block.l1_data_gas_price, } } + pub fn l2_gas_price(&self) -> GasPricePerToken { + match self { + // In older versions, L2 gas price was 0. + PendingBlockOrDeprecated::Deprecated(_) => GasPricePerToken::default(), + PendingBlockOrDeprecated::Current(block) => block.l2_gas_price, + } + } pub fn l1_da_mode(&self) -> L1DataAvailabilityMode { match self { // In older versions, all blocks were using calldata. @@ -196,6 +203,8 @@ pub struct PendingBlock { pub status: BlockStatus, pub l1_gas_price: GasPricePerToken, pub l1_data_gas_price: GasPricePerToken, + #[serde(default)] + pub l2_gas_price: GasPricePerToken, pub transactions: Vec, pub timestamp: BlockTimestamp, pub sequencer_address: SequencerContractAddress,