Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ttl-cache dependency #3207

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ contracts = { path = "../contracts" }
dashmap = { workspace = true }
database = { path = "../database" }
derive_more = { workspace = true }
ttl_cache = "0.5"
derivative = { workspace = true }
ethcontract = { workspace = true }
ethrpc = { path = "../ethrpc" }
Expand Down
14 changes: 6 additions & 8 deletions crates/shared/src/sources/uniswap_v2/pool_fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
super::pair_provider::PairProvider,
crate::{baseline_solver::BaselineSolvable, ethrpc::Web3, recent_block_cache::Block},
anyhow::Result,
cached::{Cached, TimedCache},
contracts::{errors::EthcontractErrorType, IUniswapLikePair, ERC20},
ethcontract::{errors::MethodError, BlockId, H160, U256},
futures::{
Expand All @@ -15,7 +16,6 @@ use {
sync::{LazyLock, RwLock},
time::Duration,
},
ttl_cache::TtlCache,
};

const POOL_SWAP_GAS_COST: usize = 60_000;
Expand Down Expand Up @@ -184,17 +184,15 @@ impl BaselineSolvable for Pool {
pub struct PoolFetcher<Reader> {
pub pool_reader: Reader,
pub web3: Web3,
pub cache_time: Duration,
pub non_existent_pools: RwLock<TtlCache<TokenPair, ()>>,
pub non_existent_pools: RwLock<TimedCache<TokenPair, ()>>,
}

impl<Reader> PoolFetcher<Reader> {
pub fn new(reader: Reader, web3: Web3, cache_time: Duration) -> Self {
Self {
pool_reader: reader,
web3,
cache_time,
non_existent_pools: RwLock::new(TtlCache::new(usize::MAX)),
non_existent_pools: RwLock::new(TimedCache::with_lifespan(cache_time.as_secs())),
}
}
}
Expand All @@ -207,8 +205,8 @@ where
async fn fetch(&self, token_pairs: HashSet<TokenPair>, at_block: Block) -> Result<Vec<Pool>> {
let mut token_pairs: Vec<_> = token_pairs.into_iter().collect();
{
let non_existent_pools = self.non_existent_pools.read().unwrap();
token_pairs.retain(|pair| !non_existent_pools.contains_key(pair));
let mut non_existent_pools = self.non_existent_pools.write().unwrap();
token_pairs.retain(|pair| non_existent_pools.cache_get(pair).is_none());
}
let block = BlockId::Number(at_block.into());
let futures = token_pairs
Expand All @@ -230,7 +228,7 @@ where
tracing::debug!(token_pairs = ?new_missing_pairs, "stop indexing liquidity");
let mut non_existent_pools = self.non_existent_pools.write().unwrap();
for pair in new_missing_pairs {
non_existent_pools.insert(pair, (), self.cache_time);
non_existent_pools.cache_set(pair, ());
}
}
Ok(pools)
Expand Down
Loading