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

feat(starknet_api, protobuf): add l2_gas_price to block header #641

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
6 changes: 5 additions & 1 deletion crates/papyrus_common/resources/block_hash.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x0",
"price_in_wei": "0x0"
},
"state_root": "0x6c4171ece740d153a40106b18545f147d62c513a9cb67eb7b06f83a2508b3a4",
"sequencer": "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
"timestamp": 1693484880,
Expand Down Expand Up @@ -37651,4 +37655,4 @@
"0x600f222f797801af5de701de7e240790c6b0bac312ec2d6c3f298381299fe38"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x0",
"price_in_wei": "0x0"
},
"state_root": "0x3810b7805897aff09b3bba1d41fe2eb21a3853d98553794928684d1089f25cf",
"sequencer": "0x0",
"timestamp": 1643150436,
Expand Down Expand Up @@ -1381,4 +1385,4 @@
"0x2cf9ed8ec288e35a2939ffc60be5edef318251a74af6f8ed85fb44aa2ec218f"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x0",
"price_in_wei": "0x0"
},
"state_root": "0x46a99896768700c5848dbc53a6048e554884ea6b0e881ba2f9a3d4e3096feb6",
"sequencer": "0x0",
"timestamp": 1643463800,
Expand Down Expand Up @@ -2110,4 +2114,4 @@
"0x405d74766b46c3509843514f59a2b0fddd9c3ab193e0accd1f3168be36a2f0f"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x0",
"price_in_wei": "0x0"
},
"state_root": "0x5a5f26ce761d20ac9dfdc3a009b6adeaabac74b97de38c7633af690efd9b175",
"sequencer": "0x0",
"timestamp": 1643609156,
Expand Down Expand Up @@ -5293,4 +5297,4 @@
"0x4822394e8699126997fbdc7d4427926e01876e19970fadbfa0307653ec53e47"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x0",
"price_in_wei": "0x0"
},
"state_root": "0x67d06ffd8b41a4a4d4bbe0b6f991760e365aa499add0180b7ee52c0d6b67843",
"sequencer": "0x0",
"timestamp": 1652680274,
Expand Down Expand Up @@ -7641,4 +7645,4 @@
"0x521761e9ed44deb91b85e46f2f93b35fca588784424fecda7d44d14b70a2939"
]
}
}
}
21 changes: 21 additions & 0 deletions crates/papyrus_protobuf/src/converters/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ impl TryFrom<protobuf::SignedBlockHeader> for SignedBlockHeader {
.into(),
),
};
let l2_gas_price = GasPricePerToken {
price_in_fri: GasPrice(
value
.l2_gas_price_fri
.ok_or(ProtobufConversionError::MissingField {
field_description: "SignedBlockHeader::l2_gas_price_fri",
})?
.into(),
),
price_in_wei: GasPrice(
value
.l2_gas_price_wei
.ok_or(ProtobufConversionError::MissingField {
field_description: "SignedBlockHeader::l2_gas_price_wei",
})?
.into(),
),
};

let receipt_commitment = value
.receipts
Expand All @@ -198,6 +216,7 @@ impl TryFrom<protobuf::SignedBlockHeader> for SignedBlockHeader {
block_number: BlockNumber(value.number),
l1_gas_price,
l1_data_gas_price,
l2_gas_price,
state_root,
sequencer,
timestamp,
Expand Down Expand Up @@ -264,6 +283,8 @@ impl From<(BlockHeader, Vec<BlockSignature>)> for protobuf::SignedBlockHeader {
gas_price_fri: Some(header.l1_gas_price.price_in_fri.0.into()),
data_gas_price_wei: Some(header.l1_data_gas_price.price_in_wei.0.into()),
data_gas_price_fri: Some(header.l1_data_gas_price.price_in_fri.0.into()),
l2_gas_price_wei: Some(header.l2_gas_price.price_in_wei.0.into()),
l2_gas_price_fri: Some(header.l2_gas_price.price_in_fri.0.into()),
l1_data_availability_mode: l1_data_availability_mode_to_enum_int(header.l1_da_mode),
signatures: signatures.iter().map(|signature| (*signature).into()).collect(),
}
Expand Down
4 changes: 4 additions & 0 deletions crates/papyrus_protobuf/src/proto/p2p/proto/header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ message SignedBlockHeader {
L1DataAvailabilityMode l1_data_availability_mode = 16;
// for now, we assume a small consensus, so this fits in 1M. Else, these will be repeated and extracted from this message.
repeated ConsensusSignature signatures = 17;
// TODO(Shahak): Move l2_gas_price up next to the gas price context and renumber,
// once we insert l2 gas fields to the p2p specs.
optional Uint128 l2_gas_price_fri = 18; // Added on v0.13.3.
optional Uint128 l2_gas_price_wei = 19; // Added on v0.13.3.
// can be more explicit here about the signature structure as this is not part of account abstraction
}

Expand Down
4 changes: 4 additions & 0 deletions crates/papyrus_storage/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub(crate) struct StorageBlockHeader {
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
Expand Down Expand Up @@ -169,6 +170,7 @@ impl<'env, Mode: TransactionKind> HeaderStorageReader for StorageTxn<'env, Mode>
block_number: block_header.block_number,
l1_gas_price: block_header.l1_gas_price,
l1_data_gas_price: block_header.l1_data_gas_price,
l2_gas_price: block_header.l2_gas_price,
state_root: block_header.state_root,
sequencer: block_header.sequencer,
timestamp: block_header.timestamp,
Expand Down Expand Up @@ -247,6 +249,7 @@ impl<'env> HeaderStorageWriter for StorageTxn<'env, RW> {
block_number: block_header.block_number,
l1_gas_price: block_header.l1_gas_price,
l1_data_gas_price: block_header.l1_data_gas_price,
l2_gas_price: block_header.l2_gas_price,
state_root: block_header.state_root,
sequencer: block_header.sequencer,
timestamp: block_header.timestamp,
Expand Down Expand Up @@ -353,6 +356,7 @@ impl<'env> HeaderStorageWriter for StorageTxn<'env, RW> {
block_number: reverted_header.block_number,
l1_gas_price: reverted_header.l1_gas_price,
l1_data_gas_price: reverted_header.l1_data_gas_price,
l2_gas_price: reverted_header.l2_gas_price,
state_root: reverted_header.state_root,
sequencer: reverted_header.sequencer,
timestamp: reverted_header.timestamp,
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_storage/src/serialization/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ auto_storage_serde! {
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_storage/src/test_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ auto_impl_get_test_instance! {
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ auto_impl_get_test_instance! {
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_api/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct BlockHeader {
pub block_number: BlockNumber,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub l2_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
Expand Down
Loading
Loading