From bad1d3ab6f32b986313b3c9d5be95c74f8d612b1 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Wed, 27 Sep 2023 18:47:45 +0200 Subject: [PATCH] cleanup --- Cargo.lock | 1 - finalizer/src/lib.rs | 2 +- withdrawals-meterer/Cargo.toml | 1 - withdrawals-meterer/src/lib.rs | 35 +++++++++++++++++++--------------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 660cb715..1c605884 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4833,7 +4833,6 @@ dependencies = [ "metrics", "sqlx", "storage", - "thiserror", "tokio", "vlog", ] diff --git a/finalizer/src/lib.rs b/finalizer/src/lib.rs index 994694e0..90a57d5e 100644 --- a/finalizer/src/lib.rs +++ b/finalizer/src/lib.rs @@ -1,6 +1,7 @@ #![deny(unused_crate_dependencies)] #![warn(missing_docs)] #![warn(unused_extern_crates)] +#![warn(unused_imports)] //! Finalization logic implementation. @@ -52,7 +53,6 @@ pub struct Finalizer { query_db_pagination_limit: u64, tx_fee_limit: U256, tx_retry_timeout: Duration, - account_address: Address, } diff --git a/withdrawals-meterer/Cargo.toml b/withdrawals-meterer/Cargo.toml index 7d02372e..5ad1bd7b 100644 --- a/withdrawals-meterer/Cargo.toml +++ b/withdrawals-meterer/Cargo.toml @@ -10,7 +10,6 @@ edition = "2021" ethers = "2.0.10" lazy_static = "1.4.0" metrics = "0.21.1" -thiserror = "1.0.49" tokio = "1.32.0" client = { path = "../client" } diff --git a/withdrawals-meterer/src/lib.rs b/withdrawals-meterer/src/lib.rs index cd8d59aa..64f2f943 100644 --- a/withdrawals-meterer/src/lib.rs +++ b/withdrawals-meterer/src/lib.rs @@ -1,3 +1,10 @@ +#![deny(unused_crate_dependencies)] +#![warn(missing_docs)] +#![warn(unused_extern_crates)] +#![warn(unused_imports)] + +//! A utility crate that meters withdrawals amounts. + use std::{collections::HashMap, str::FromStr, sync::Arc}; use client::ETH_TOKEN_ADDRESS; @@ -16,21 +23,13 @@ lazy_static! { }; } -#[derive(Debug, thiserror::Error)] -#[allow(missing_docs)] -pub enum Error { - #[error(transparent)] - Storage(#[from] storage::Error), - - #[error("Received withdrawal for unknown token {0:?}")] - UnknownToken(Address), -} - +/// Given a set of withdrawal ids meter all of them to a metric +/// with a given name. pub async fn meter_finalized_withdrawals_storage( pool: &PgPool, ids: Vec, metric_name: &'static str, -) -> Result<(), Error> { +) -> Result<(), storage::Error> { let withdrawals = storage::get_withdrawals(pool, &ids).await?; meter_finalized_withdrawals(pool, &withdrawals, metric_name).await?; @@ -38,11 +37,16 @@ pub async fn meter_finalized_withdrawals_storage( Ok(()) } +/// Given a set of [`StoredWithdrawal`], meter all of them to a +/// metric with a given name. +/// +/// This function returns only storage error, all formatting, etc +/// errors will be just logged. pub async fn meter_finalized_withdrawals( pool: &PgPool, withdrawals: &[StoredWithdrawal], metric_name: &'static str, -) -> Result<(), Error> { +) -> Result<(), storage::Error> { for w in withdrawals { let guard = TOKEN_DECIMALS.read().await; let decimals = guard.get(&w.event.token).copied(); @@ -50,9 +54,10 @@ pub async fn meter_finalized_withdrawals( let decimals = match decimals { None => { - let decimals = storage::token_decimals(pool, w.event.token) - .await? - .ok_or(Error::UnknownToken(w.event.token))?; + let Some(decimals) = storage::token_decimals(pool, w.event.token).await? else { + vlog::error!("Received withdrawal from unknown token {:?}", w.event.token); + continue; + }; TOKEN_DECIMALS.write().await.insert(w.event.token, decimals); decimals