Skip to content

Commit

Permalink
chore(execution): add l2_gas_price to PendingData (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
TzahiTaub committed Sep 22, 2024
1 parent 3634605 commit e26b0ea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
),
Expand All @@ -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,
)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions crates/papyrus_execution/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_rpc/src/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
2 changes: 2 additions & 0 deletions crates/papyrus_rpc/src/v0_8/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions crates/starknet_client/src/reader/objects/pending_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Transaction>,
pub timestamp: BlockTimestamp,
pub sequencer_address: SequencerContractAddress,
Expand Down

0 comments on commit e26b0ea

Please sign in to comment.