Skip to content

Commit

Permalink
make api_server report open batch's fee input
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Sep 13, 2024
1 parent 82ed8f9 commit 7c0de25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
26 changes: 26 additions & 0 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,32 @@ impl BlocksDal<'_, '_> {
Ok(())
}

pub async fn get_last_l1_batch_fee_input(&mut self) -> DalResult<BatchFeeInput> {
let row = sqlx::query!(
r#"
SELECT
l1_gas_price,
l2_fair_gas_price,
fair_pubdata_price
FROM
l1_batches
ORDER BY
number DESC
LIMIT
1
"#
)
.instrument("get_last_l1_batch_fee_input")
.fetch_one(self.storage)
.await?;

Ok(BatchFeeInput::pubdata_independent(
row.l1_gas_price as u64,
row.l2_fair_gas_price as u64,
row.fair_pubdata_price as u64,
))
}

pub async fn get_last_sealed_l2_block_header(&mut self) -> DalResult<Option<L2BlockHeader>> {
let header = sqlx::query_as!(
StorageL2BlockHeader,
Expand Down
17 changes: 5 additions & 12 deletions core/node/fee_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,18 @@ impl ApiFeeInputProvider {
impl BatchFeeModelInputProvider for ApiFeeInputProvider {
async fn get_batch_fee_input_scaled(
&self,
l1_gas_price_scale_factor: f64,
l1_pubdata_price_scale_factor: f64,
_l1_gas_price_scale_factor: f64,
_l1_pubdata_price_scale_factor: f64,
) -> anyhow::Result<BatchFeeInput> {
let inner_input = self
.inner
.get_batch_fee_input_scaled(l1_gas_price_scale_factor, l1_pubdata_price_scale_factor)
.await
.context("cannot get batch fee input from base provider")?;
let last_l2_block_params = self
let batch_fee_input = self
.connection_pool
.connection_tagged("api_fee_input_provider")
.await?
.blocks_dal()
.get_last_sealed_l2_block_header()
.get_last_l1_batch_fee_input()
.await?;

Ok(last_l2_block_params
.map(|header| inner_input.stricter(header.batch_fee_input))
.unwrap_or(inner_input))
Ok(batch_fee_input)
}

/// Returns the fee model parameters.
Expand Down

0 comments on commit 7c0de25

Please sign in to comment.