Skip to content

Commit

Permalink
feat(mempool): add l2_gas_price support in BlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
TzahiTaub authored and yoavGrs committed Sep 22, 2024
1 parent da4fbcf commit 38d02d8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/gateway/src/rpc_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct BlockHeader {
pub timestamp: BlockTimestamp,
pub l1_gas_price: ResourcePrice,
pub l1_data_gas_price: ResourcePrice,
pub l2_gas_price: ResourcePrice,
pub l1_da_mode: L1DataAvailabilityMode,
pub starknet_version: String,
}
Expand All @@ -90,9 +91,8 @@ impl TryInto<BlockInfo> for BlockHeader {
parse_gas_price(self.l1_gas_price.price_in_fri)?,
parse_gas_price(self.l1_data_gas_price.price_in_wei)?,
parse_gas_price(self.l1_data_gas_price.price_in_fri)?,
// TODO(Aner): add to BlockHeader and take the value from it.
NonZeroU128::MIN,
NonZeroU128::MIN,
parse_gas_price(self.l2_gas_price.price_in_wei)?,
parse_gas_price(self.l2_gas_price.price_in_fri)?,
),
use_kzg_da: matches!(self.l1_da_mode, L1DataAvailabilityMode::Blob),
})
Expand Down
4 changes: 4 additions & 0 deletions crates/gateway/src/rpc_state_reader_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ async fn test_get_block_info() {
price_in_wei: GasPrice(1),
price_in_fri: GasPrice(1),
},
l2_gas_price: ResourcePrice {
price_in_wei: GasPrice(1),
price_in_fri: GasPrice(1),
},
..Default::default()
})
.unwrap(),
Expand Down
5 changes: 5 additions & 0 deletions crates/papyrus_rpc/resources/V0_8/starknet_api_openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,11 @@
"description": "The price of l1 data gas in the block",
"$ref": "#/components/schemas/RESOURCE_PRICE"
},
"l2_gas_price": {
"title": "L2 gas price",
"description": "The price of l2 gas in the block",
"$ref": "#/components/schemas/RESOURCE_PRICE"
},
"l1_da_mode": {
"title": "L1 da mode",
"type": "string",
Expand Down
4 changes: 4 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 @@ -1530,6 +1530,10 @@ impl JsonRpcServerImpl {
price_in_wei: block.l1_data_gas_price().price_in_wei,
price_in_fri: block.l1_data_gas_price().price_in_fri,
},
l2_gas_price: ResourcePrice {
price_in_wei: block.l2_gas_price().price_in_wei,
price_in_fri: block.l2_gas_price().price_in_fri,
},
l1_da_mode: block.l1_da_mode(),
starknet_version: block.starknet_version(),
};
Expand Down
19 changes: 19 additions & 0 deletions crates/papyrus_rpc/src/v0_8/api/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ async fn get_block_w_full_transactions() {
price_in_wei: GasPrice(random::<u128>()),
price_in_fri: GasPrice(random::<u128>()),
};
let pending_l2_gas_price =
GasPricePerToken { price_in_wei: GasPrice(0), price_in_fri: GasPrice(0) };
let expected_pending_block = Block {
header: GeneralBlockHeader::PendingBlockHeader(PendingBlockHeader {
parent_hash: block_hash,
Expand All @@ -604,6 +606,10 @@ async fn get_block_w_full_transactions() {
price_in_fri: pending_l1_gas_price.price_in_fri,
},
l1_data_gas_price: ResourcePrice::default(),
l2_gas_price: ResourcePrice {
price_in_wei: pending_l2_gas_price.price_in_wei,
price_in_fri: pending_l2_gas_price.price_in_fri,
},
l1_da_mode: L1DataAvailabilityMode::Calldata,
starknet_version: starknet_version.to_string(),
}),
Expand Down Expand Up @@ -777,6 +783,8 @@ async fn get_block_w_full_transactions_and_receipts() {
price_in_wei: GasPrice(rng.next_u64().into()),
price_in_fri: GasPrice(rng.next_u64().into()),
};
let pending_l2_gas_price =
GasPricePerToken { price_in_wei: GasPrice(0), price_in_fri: GasPrice(0) };
let expected_pending_block = Block {
header: GeneralBlockHeader::PendingBlockHeader(PendingBlockHeader {
parent_hash: block_hash,
Expand All @@ -787,6 +795,10 @@ async fn get_block_w_full_transactions_and_receipts() {
price_in_fri: pending_l1_gas_price.price_in_fri,
},
l1_data_gas_price: ResourcePrice::default(),
l2_gas_price: ResourcePrice {
price_in_wei: pending_l2_gas_price.price_in_wei,
price_in_fri: pending_l2_gas_price.price_in_fri,
},
l1_da_mode: L1DataAvailabilityMode::Calldata,
starknet_version: starknet_version.to_string(),
}),
Expand Down Expand Up @@ -960,6 +972,8 @@ async fn get_block_w_transaction_hashes() {
price_in_wei: GasPrice(random::<u128>()),
price_in_fri: GasPrice(random::<u128>()),
};
let pending_l2_gas_price =
GasPricePerToken { price_in_wei: GasPrice(0), price_in_fri: GasPrice(0) };
let expected_pending_block = Block {
header: GeneralBlockHeader::PendingBlockHeader(PendingBlockHeader {
parent_hash: block_hash,
Expand All @@ -969,6 +983,10 @@ async fn get_block_w_transaction_hashes() {
price_in_wei: pending_l1_gas_price.price_in_wei,
price_in_fri: pending_l1_gas_price.price_in_fri,
},
l2_gas_price: ResourcePrice {
price_in_wei: pending_l2_gas_price.price_in_wei,
price_in_fri: pending_l2_gas_price.price_in_fri,
},
l1_data_gas_price: ResourcePrice::default(),
l1_da_mode: L1DataAvailabilityMode::Calldata,
starknet_version: starknet_version.to_string(),
Expand Down Expand Up @@ -3977,6 +3995,7 @@ auto_impl_get_test_instance! {
pub timestamp: BlockTimestamp,
pub l1_gas_price: ResourcePrice,
pub l1_data_gas_price: ResourcePrice,
pub l2_gas_price: ResourcePrice,
pub l1_da_mode: L1DataAvailabilityMode,
pub starknet_version: String,
}
Expand Down
6 changes: 6 additions & 0 deletions crates/papyrus_rpc/src/v0_8/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct BlockHeader {
pub timestamp: BlockTimestamp,
pub l1_gas_price: ResourcePrice,
pub l1_data_gas_price: ResourcePrice,
pub l2_gas_price: ResourcePrice,
pub l1_da_mode: L1DataAvailabilityMode,
pub starknet_version: String,
}
Expand All @@ -34,6 +35,7 @@ pub struct PendingBlockHeader {
pub timestamp: BlockTimestamp,
pub l1_gas_price: ResourcePrice,
pub l1_data_gas_price: ResourcePrice,
pub l2_gas_price: ResourcePrice,
pub l1_da_mode: L1DataAvailabilityMode,
pub starknet_version: String,
}
Expand Down Expand Up @@ -62,6 +64,10 @@ impl From<starknet_api::block::BlockHeader> for BlockHeader {
price_in_wei: header.l1_data_gas_price.price_in_wei,
price_in_fri: header.l1_data_gas_price.price_in_fri,
},
l2_gas_price: ResourcePrice {
price_in_wei: header.l2_gas_price.price_in_wei,
price_in_fri: header.l2_gas_price.price_in_fri,
},
l1_da_mode: header.l1_da_mode,
starknet_version: header.starknet_version.to_string(),
}
Expand Down

0 comments on commit 38d02d8

Please sign in to comment.