Skip to content

Commit

Permalink
tweak the logic to rely on unsealed batches with a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Sep 13, 2024
1 parent a3c70ec commit d042e29
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.

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

24 changes: 13 additions & 11 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ impl BlocksDal<'_, '_> {
Ok(())
}

pub async fn get_last_l1_batch_fee_input(&mut self) -> DalResult<BatchFeeInput> {
pub async fn get_unsealed_l1_batch_fee_input(&mut self) -> DalResult<Option<BatchFeeInput>> {
let row = sqlx::query!(
r#"
SELECT
Expand All @@ -826,21 +826,23 @@ impl BlocksDal<'_, '_> {
fair_pubdata_price
FROM
l1_batches
ORDER BY
number DESC
LIMIT
1
WHERE
NOT is_sealed
"#
)
.instrument("get_last_l1_batch_fee_input")
.fetch_one(self.storage)
.fetch_optional(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,
))
if let Some(row) = row {
Ok(Some(BatchFeeInput::pubdata_independent(
row.l1_gas_price as u64,
row.l2_fair_gas_price as u64,
row.fair_pubdata_price as u64,
)))
} else {
Ok(None)
}
}

pub async fn get_last_sealed_l2_block_header(&mut self) -> DalResult<Option<L2BlockHeader>> {
Expand Down
35 changes: 28 additions & 7 deletions core/node/fee_model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fmt, fmt::Debug, sync::Arc};

use anyhow::Context;
use async_trait::async_trait;
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_types::{
Expand Down Expand Up @@ -126,18 +127,38 @@ 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 batch_fee_input = self
if let Some(batch_fee_input) = self
.connection_pool
.connection_tagged("api_fee_input_provider")
.await?
.blocks_dal()
.get_last_l1_batch_fee_input()
.await?;

Ok(batch_fee_input)
.get_unsealed_l1_batch_fee_input()
.await?
{
Ok(batch_fee_input)
} else {
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
.connection_pool
.connection_tagged("api_fee_input_provider")
.await?
.blocks_dal()
.get_last_sealed_l2_block_header()
.await?;
Ok(last_l2_block_params
.map(|header| inner_input.stricter(header.batch_fee_input))
.unwrap_or(inner_input))
}
}

/// Returns the fee model parameters.
Expand Down

0 comments on commit d042e29

Please sign in to comment.