diff --git a/committer/src/main.rs b/committer/src/main.rs index 9a654eea..202ecece 100644 --- a/committer/src/main.rs +++ b/committer/src/main.rs @@ -7,6 +7,7 @@ mod setup; use api::launch_api_server; use errors::{Result, WithContext}; use metrics::prometheus::Registry; +use services::fee_tracker::port::cache::CachingApi; use setup::last_finalization_metric; use tokio_util::sync::CancellationToken; diff --git a/committer/src/setup.rs b/committer/src/setup.rs index 0cfe9c43..8e2fcd18 100644 --- a/committer/src/setup.rs +++ b/committer/src/setup.rs @@ -9,7 +9,10 @@ use metrics::{ }; use services::{ block_committer::{port::l1::Contract, service::BlockCommitter}, - fee_tracker::service::{FeeThresholds, FeeTracker, SmaPeriods}, + fee_tracker::{ + port::cache::CachingApi, + service::{FeeThresholds, FeeTracker, SmaPeriods}, + }, state_committer::port::Storage, state_listener::service::StateListener, state_pruner::service::StatePruner, @@ -119,7 +122,7 @@ pub fn state_committer( cancel_token: CancellationToken, config: &config::Config, registry: &Registry, - fee_tracker: FeeTracker, + fee_tracker: FeeTracker>, ) -> Result> { let state_committer = services::StateCommitter::new( l1, @@ -327,9 +330,9 @@ pub fn fee_tracker( cancel_token: CancellationToken, config: &config::Config, registry: &Registry, -) -> Result<(FeeTracker, tokio::task::JoinHandle<()>)> { +) -> Result<(FeeTracker>, tokio::task::JoinHandle<()>)> { let fee_tracker = FeeTracker::new( - l1, + CachingApi::new(l1, 24 * 3600 / 12), services::fee_tracker::service::Config { sma_periods: SmaPeriods { short: config.app.fee_algo.short_sma_blocks, diff --git a/packages/services/src/fee_tracker/port.rs b/packages/services/src/fee_tracker/port.rs index e9112e94..e7ba4f55 100644 --- a/packages/services/src/fee_tracker/port.rs +++ b/packages/services/src/fee_tracker/port.rs @@ -188,7 +188,7 @@ pub mod l1 { } pub mod cache { - use std::{collections::BTreeMap, ops::RangeInclusive}; + use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc}; use tokio::sync::RwLock; @@ -196,10 +196,10 @@ pub mod cache { use super::l1::{Api, BlockFees, Fees, SequentialBlockFees}; - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct CachingApi

{ fees_provider: P, - cache: RwLock>, + cache: Arc>>, cache_limit: usize, } @@ -207,7 +207,7 @@ pub mod cache { pub fn new(fees_provider: P, cache_limit: usize) -> Self { Self { fees_provider, - cache: RwLock::new(BTreeMap::new()), + cache: Arc::new(RwLock::new(BTreeMap::new())), cache_limit, } }