diff --git a/Cargo.lock b/Cargo.lock index 05cfd11c17..cdeebd27b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2925,12 +2925,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -4506,7 +4500,6 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", - "ttl_cache", "url", "web3", ] @@ -5413,15 +5406,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "ttl_cache" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4189890526f0168710b6ee65ceaedf1460c48a14318ceec933cb26baa492096a" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "typenum" version = "1.17.0" diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index 87cb190f1f..622f3cf536 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -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" } diff --git a/crates/shared/src/sources/uniswap_v2/pool_fetching.rs b/crates/shared/src/sources/uniswap_v2/pool_fetching.rs index b7966663f9..377ecdcc6d 100644 --- a/crates/shared/src/sources/uniswap_v2/pool_fetching.rs +++ b/crates/shared/src/sources/uniswap_v2/pool_fetching.rs @@ -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::{ @@ -15,7 +16,6 @@ use { sync::{LazyLock, RwLock}, time::Duration, }, - ttl_cache::TtlCache, }; const POOL_SWAP_GAS_COST: usize = 60_000; @@ -184,8 +184,7 @@ impl BaselineSolvable for Pool { pub struct PoolFetcher { pub pool_reader: Reader, pub web3: Web3, - pub cache_time: Duration, - pub non_existent_pools: RwLock>, + pub non_existent_pools: RwLock>, } impl PoolFetcher { @@ -193,8 +192,7 @@ impl PoolFetcher { 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())), } } } @@ -207,8 +205,8 @@ where async fn fetch(&self, token_pairs: HashSet, at_block: Block) -> Result> { 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 @@ -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)