diff --git a/bin/withdrawal-finalizer/src/main.rs b/bin/withdrawal-finalizer/src/main.rs index d654c135..e472001c 100644 --- a/bin/withdrawal-finalizer/src/main.rs +++ b/bin/withdrawal-finalizer/src/main.rs @@ -219,9 +219,7 @@ async fn main() -> Result<()> { let zksync_contract = IZkSync::new(config.diamond_proxy_addr, client_l1.clone()); - let first_block_today = client::get_first_block_today(None, &client_l2) - .await? - .unwrap(); + let first_block_today = client::get_first_block_today(None, &client_l2).await?; let watcher = Watcher::new(client_l2.clone(), pgpool.clone(), first_block_today).await?; @@ -271,7 +269,7 @@ async fn main() -> Result<()> { config.one_withdrawal_gas_limit, config.batch_finalization_gas_limit, ); - vlog::info!("first L2 miniblock mined today is {first_block_today}"); + vlog::info!("first L2 miniblock mined today is {first_block_today:?}"); let finalizer = finalizer::Finalizer::new( pgpool, diff --git a/finalizer/src/lib.rs b/finalizer/src/lib.rs index 4b3f8110..eb912f84 100644 --- a/finalizer/src/lib.rs +++ b/finalizer/src/lib.rs @@ -83,18 +83,26 @@ where l1_bridge: IL1Bridge, tx_retry_timeout: usize, account_address: Address, - first_block_today: U64, + first_block_today: Option, ) -> Result { - let max_finalized_today = - storage::max_finalized_l2_miniblock_since_block(&pgpool, first_block_today.as_u64()) - .await? - .unwrap_or(first_block_today.as_u64()); + let max_finalized_today = match first_block_today { + Some(first_block_today) => { + storage::max_finalized_l2_miniblock_since_block(&pgpool, first_block_today.as_u64()) + .await? + } + None => None, + }; + + let historic_interval = match (first_block_today, max_finalized_today) { + (None, None) | (None, Some(_)) | (Some(_), None) => None, + (Some(from), Some(to)) => Some((from, to.into())), + }; // we need to tell the meter to meter only finalized withdrawls let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new( pgpool.clone(), "era_withdrawal_finalizer_meter", - Some((first_block_today, max_finalized_today.into())), + historic_interval, ) .await; let tx_fee_limit = ethers::utils::parse_ether(TX_FEE_LIMIT) diff --git a/watcher/src/lib.rs b/watcher/src/lib.rs index 35695a5f..9afb9b17 100644 --- a/watcher/src/lib.rs +++ b/watcher/src/lib.rs @@ -42,15 +42,22 @@ where ::Provider: JsonRpcClient, { #[allow(clippy::too_many_arguments)] - pub async fn new(l2_provider: Arc, pgpool: PgPool, first_block_today: U64) -> Result { - let max_l2_miniblock = storage::max_l2_miniblock(&pgpool) - .await? - .unwrap_or(first_block_today.as_u64()); + pub async fn new( + l2_provider: Arc, + pgpool: PgPool, + first_block_today: Option, + ) -> Result { + let max_l2_miniblock = storage::max_l2_miniblock(&pgpool).await?; + + let historic_interval = match (first_block_today, max_l2_miniblock) { + (None, None) | (None, Some(_)) | (Some(_), None) => None, + (Some(from), Some(to)) => Some((from, to.into())), + }; let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new( pgpool.clone(), "era_withdrawal_finalizer_watcher_meter", - Some((first_block_today, max_l2_miniblock.into())), + historic_interval, ) .await;