Skip to content

Commit

Permalink
enable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-magnet committed Dec 19, 2024
1 parent d8d39de commit c8a7ca7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions committer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions committer/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -119,7 +122,7 @@ pub fn state_committer(
cancel_token: CancellationToken,
config: &config::Config,
registry: &Registry,
fee_tracker: FeeTracker<L1>,
fee_tracker: FeeTracker<CachingApi<L1>>,
) -> Result<tokio::task::JoinHandle<()>> {
let state_committer = services::StateCommitter::new(
l1,
Expand Down Expand Up @@ -327,9 +330,9 @@ pub fn fee_tracker(
cancel_token: CancellationToken,
config: &config::Config,
registry: &Registry,
) -> Result<(FeeTracker<L1>, tokio::task::JoinHandle<()>)> {
) -> Result<(FeeTracker<CachingApi<L1>>, 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,
Expand Down
8 changes: 4 additions & 4 deletions packages/services/src/fee_tracker/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,26 @@ pub mod l1 {
}

pub mod cache {
use std::{collections::BTreeMap, ops::RangeInclusive};
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};

use tokio::sync::RwLock;

use crate::Error;

use super::l1::{Api, BlockFees, Fees, SequentialBlockFees};

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CachingApi<P> {
fees_provider: P,
cache: RwLock<BTreeMap<u64, Fees>>,
cache: Arc<RwLock<BTreeMap<u64, Fees>>>,
cache_limit: usize,
}

impl<P> CachingApi<P> {
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,
}
}
Expand Down

0 comments on commit c8a7ca7

Please sign in to comment.