Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: Expose fair_pubdata_price for blocks and batches (matter-labs#2244
Browse files Browse the repository at this point in the history
)

## What ❔

* Exposing fair_pubdata_price in our block & batches API

## Why ❔

* This is crucial information for projects that need to replay our
transactions (for example era_test_node).
* Without this, they cannot compute the correct gas costs.
  • Loading branch information
mm-zk authored Jun 19, 2024
1 parent 496e6c1 commit 0d51cd6
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 112 deletions.
1 change: 1 addition & 0 deletions core/bin/external_node/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn block_details_base(hash: H256) -> api::BlockDetailsBase {
executed_at: None,
l1_gas_price: 0,
l2_fair_gas_price: 0,
fair_pubdata_price: None,
base_system_contracts_hashes: Default::default(),
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion core/lib/dal/src/blocks_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ impl BlocksWeb3Dal<'_, '_> {
execute_tx.confirmed_at AS "executed_at?",
miniblocks.l1_gas_price,
miniblocks.l2_fair_gas_price,
miniblocks.fair_pubdata_price,
miniblocks.bootloader_code_hash,
miniblocks.default_aa_code_hash,
miniblocks.protocol_version,
Expand Down Expand Up @@ -673,7 +674,8 @@ impl BlocksWeb3Dal<'_, '_> {
mb AS (
SELECT
l1_gas_price,
l2_fair_gas_price
l2_fair_gas_price,
fair_pubdata_price
FROM
miniblocks
WHERE
Expand All @@ -695,6 +697,7 @@ impl BlocksWeb3Dal<'_, '_> {
execute_tx.confirmed_at AS "executed_at?",
mb.l1_gas_price,
mb.l2_fair_gas_price,
mb.fair_pubdata_price,
l1_batches.bootloader_code_hash,
l1_batches.default_aa_code_hash
FROM
Expand Down
5 changes: 5 additions & 0 deletions core/lib/dal/src/models/storage_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ pub(crate) struct StorageBlockDetails {
pub l1_gas_price: i64,
// L2 gas price assumed in the corresponding batch
pub l2_fair_gas_price: i64,
// Cost of publishing 1 byte (in wei).
pub fair_pubdata_price: Option<i64>,
pub bootloader_code_hash: Option<Vec<u8>>,
pub default_aa_code_hash: Option<Vec<u8>>,
pub fee_account_address: Vec<u8>,
Expand Down Expand Up @@ -312,6 +314,7 @@ impl From<StorageBlockDetails> for api::BlockDetails {
.map(|executed_at| DateTime::<Utc>::from_naive_utc_and_offset(executed_at, Utc)),
l1_gas_price: details.l1_gas_price as u64,
l2_fair_gas_price: details.l2_fair_gas_price as u64,
fair_pubdata_price: details.fair_pubdata_price.map(|x| x as u64),
base_system_contracts_hashes: convert_base_system_contracts_hashes(
details.bootloader_code_hash,
details.default_aa_code_hash,
Expand Down Expand Up @@ -344,6 +347,7 @@ pub(crate) struct StorageL1BatchDetails {
pub executed_at: Option<NaiveDateTime>,
pub l1_gas_price: i64,
pub l2_fair_gas_price: i64,
pub fair_pubdata_price: Option<i64>,
pub bootloader_code_hash: Option<Vec<u8>>,
pub default_aa_code_hash: Option<Vec<u8>>,
}
Expand Down Expand Up @@ -385,6 +389,7 @@ impl From<StorageL1BatchDetails> for api::L1BatchDetails {
.map(|executed_at| DateTime::<Utc>::from_naive_utc_and_offset(executed_at, Utc)),
l1_gas_price: details.l1_gas_price as u64,
l2_fair_gas_price: details.l2_fair_gas_price as u64,
fair_pubdata_price: details.fair_pubdata_price.map(|x| x as u64),
base_system_contracts_hashes: convert_base_system_contracts_hashes(
details.bootloader_code_hash,
details.default_aa_code_hash,
Expand Down
1 change: 1 addition & 0 deletions core/lib/snapshots_applier/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn block_details_base(hash: H256) -> api::BlockDetailsBase {
executed_at: None,
l1_gas_price: 0,
l2_fair_gas_price: 0,
fair_pubdata_price: None,
base_system_contracts_hashes: Default::default(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ pub struct BlockDetailsBase {
pub executed_at: Option<DateTime<Utc>>,
pub l1_gas_price: u64,
pub l2_fair_gas_price: u64,
// Cost of publishing one byte (in wei).
pub fair_pubdata_price: Option<u64>,
pub base_system_contracts_hashes: BaseSystemContractsHashes,
}

Expand Down
1 change: 1 addition & 0 deletions core/node/node_sync/src/batch_status_updater/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn mock_block_details(number: u32, stage: L1BatchStage) -> api::BlockDetails {
.then(|| Utc.timestamp_opt(300, 0).unwrap()),
l1_gas_price: 1,
l2_fair_gas_price: 2,
fair_pubdata_price: None,
base_system_contracts_hashes: BaseSystemContractsHashes::default(),
},
operator_address: Address::zero(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn mock_block_details_base(number: u32, hash: Option<H256>) -> api::BlockDetails
executed_at: None,
l1_gas_price: 10,
l2_fair_gas_price: 100,
fair_pubdata_price: None,
base_system_contracts_hashes: Default::default(),
}
}
Expand Down

0 comments on commit 0d51cd6

Please sign in to comment.