Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Sep 27, 2023
1 parent 8e763d8 commit bad1d3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion finalizer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(unused_crate_dependencies)]
#![warn(missing_docs)]
#![warn(unused_extern_crates)]
#![warn(unused_imports)]

//! Finalization logic implementation.
Expand Down Expand Up @@ -52,7 +53,6 @@ pub struct Finalizer<M1, M2> {
query_db_pagination_limit: u64,
tx_fee_limit: U256,
tx_retry_timeout: Duration,

account_address: Address,
}

Expand Down
1 change: 0 additions & 1 deletion withdrawals-meterer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
35 changes: 20 additions & 15 deletions withdrawals-meterer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,43 +23,41 @@ 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<i64>,
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?;

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();
drop(guard);

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
Expand Down

0 comments on commit bad1d3a

Please sign in to comment.