diff --git a/bin/withdrawal-finalizer/src/metrics.rs b/bin/withdrawal-finalizer/src/metrics.rs index 235dafec..c8d5bbe2 100644 --- a/bin/withdrawal-finalizer/src/metrics.rs +++ b/bin/withdrawal-finalizer/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for main binary +#![allow(unexpected_cfgs)] + use std::time::Duration; use ethers::types::U256; diff --git a/chain-events/src/metrics.rs b/chain-events/src/metrics.rs index c6da4f24..1ec1ec55 100644 --- a/chain-events/src/metrics.rs +++ b/chain-events/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for chain events +#![allow(unexpected_cfgs)] + use vise::{Counter, Gauge, Metrics}; /// Chain events metrics. diff --git a/client/src/lib.rs b/client/src/lib.rs index c609735c..fe36add5 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -415,10 +415,13 @@ impl ZksyncMiddleware for Provider

{ let sender = log.topics[1].into(); - let proof = self + // Proof can be not ready yet. + let Some(proof) = self .get_log_proof(withdrawal_hash, Some(l2_to_l1_log_index as u64)) .await? - .expect("Log proof should be present. qed"); + else { + return Ok(None); + }; let message: Bytes = match ethers::abi::decode(&[ParamType::Bytes], &log.data) .expect("log data is valid rlp data; qed") diff --git a/client/src/metrics.rs b/client/src/metrics.rs index 53735eca..0209de1b 100644 --- a/client/src/metrics.rs +++ b/client/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for client +#![allow(unexpected_cfgs)] + use std::time::Duration; use vise::{Buckets, Histogram, LabeledFamily, Metrics}; diff --git a/deny.toml b/deny.toml index 98c54f90..dc298291 100644 --- a/deny.toml +++ b/deny.toml @@ -12,7 +12,9 @@ db-path = "~/.cargo/advisory-db" db-urls = ["https://github.com/rustsec/advisory-db"] yanked = "warn" ignore = [ - "RUSTSEC-2023-0052" + "RUSTSEC-2023-0052", + "RUSTSEC-2024-0384", + "RUSTSEC-2024-0421" ] [licenses] diff --git a/finalizer/src/lib.rs b/finalizer/src/lib.rs index a5264821..30590fe8 100644 --- a/finalizer/src/lib.rs +++ b/finalizer/src/lib.rs @@ -44,6 +44,9 @@ const OUT_OF_FUNDS_BACKOFF: Duration = Duration::from_secs(10); /// Backoff period if one of the loop iterations has failed. const LOOP_ITERATION_ERROR_BACKOFF: Duration = Duration::from_secs(5); +/// Interval between successful loop iterations. +const LOOP_ITERATION_OK_INTERVAL: Duration = Duration::from_secs(1); + /// A newtype that represents a set of addresses in JSON format. #[derive(Debug, Eq, PartialEq)] pub struct AddrList(pub Vec

); @@ -491,11 +494,12 @@ fn is_gas_required_exceeds_allowance(e: &::Error } // Request finalization parameters for a set of withdrawals in parallel. +// Returns `None` if params for some withdrawal are not ready yet. async fn request_finalize_params( pgpool: &PgPool, middleware: M2, hash_and_indices: &[(H256, u16, u64)], -) -> Vec +) -> Option> where M2: ZksyncMiddleware, { @@ -504,20 +508,30 @@ where // Run all parametere fetching in parallel. // Filter out errors and log them and increment a metric counter. // Return successful fetches. - for (i, result) in futures::future::join_all(hash_and_indices.iter().map(|(h, i, id)| { + let params_opt = futures::future::join_all(hash_and_indices.iter().map(|(h, i, id)| { middleware .finalize_withdrawal_params(*h, *i as usize) - .map_ok(|r| { - let mut r = r.expect("always able to ask withdrawal params; qed"); - r.id = *id; + .map_ok(|mut r| { + if let Some(r) = r.as_mut() { + r.id = *id; + } r }) .map_err(crate::Error::from) })) - .await - .into_iter() - .enumerate() - { + .await; + + // If any element is `None` then return `None`. + let mut params = Vec::with_capacity(params_opt.len()); + for result in params_opt { + match result { + Ok(Some(param)) => params.push(Ok(param)), + Ok(None) => return None, + Err(err) => params.push(Err(err)), + } + } + + for (i, result) in params.into_iter().enumerate() { match result { Ok(r) => ok_results.push(r), Err(e) => { @@ -535,7 +549,7 @@ where } } - ok_results + Some(ok_results) } // Continiously query the new withdrawals that have been seen by watcher @@ -556,6 +570,8 @@ async fn params_fetcher_loop( { tracing::error!("params fetcher iteration ended with {e}"); tokio::time::sleep(LOOP_ITERATION_ERROR_BACKOFF).await; + } else { + tokio::time::sleep(LOOP_ITERATION_OK_INTERVAL).await; } } } @@ -584,7 +600,12 @@ where .map(|p| (p.key.tx_hash, p.key.event_index_in_tx as u16, p.id)) .collect(); - let params = request_finalize_params(pool, &middleware, &hash_and_index_and_id).await; + let Some(params) = request_finalize_params(pool, &middleware, &hash_and_index_and_id).await + else { + // Early-return if params are not ready. + tracing::info!("Params are not ready"); + return Ok(()); + }; let already_finalized: Vec<_> = get_finalized_withdrawals(¶ms, zksync_contract, l1_bridge) .await? diff --git a/finalizer/src/metrics.rs b/finalizer/src/metrics.rs index d90fa7cd..3ed09a6c 100644 --- a/finalizer/src/metrics.rs +++ b/finalizer/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for finalizer +#![allow(unexpected_cfgs)] + use vise::{Counter, Gauge, Metrics}; /// Finalizer metrics diff --git a/storage/src/metrics.rs b/storage/src/metrics.rs index dfc1d1cd..fa544137 100644 --- a/storage/src/metrics.rs +++ b/storage/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for storage +#![allow(unexpected_cfgs)] + use std::time::Duration; use vise::{Buckets, Histogram, LabeledFamily, Metrics}; diff --git a/tx-sender/src/metrics.rs b/tx-sender/src/metrics.rs index 1feb7b31..66670edf 100644 --- a/tx-sender/src/metrics.rs +++ b/tx-sender/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for tx sender +#![allow(unexpected_cfgs)] + use vise::{Counter, Metrics}; /// TX Sender metrics diff --git a/watcher/src/metrics.rs b/watcher/src/metrics.rs index 0af6eee4..1f768a1f 100644 --- a/watcher/src/metrics.rs +++ b/watcher/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for withdrawal watcher +#![allow(unexpected_cfgs)] + use vise::{Gauge, Metrics}; /// Watcher metrics diff --git a/withdrawals-meterer/src/metrics.rs b/withdrawals-meterer/src/metrics.rs index 65eb9abb..5d246927 100644 --- a/withdrawals-meterer/src/metrics.rs +++ b/withdrawals-meterer/src/metrics.rs @@ -1,5 +1,7 @@ //! Metrics for withdrawal meterer +#![allow(unexpected_cfgs)] + use vise::{EncodeLabelSet, EncodeLabelValue, Family, Gauge, LabeledFamily, Metrics}; /// Kinds of withdrawal volumes currently being metered by application