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

Fix NonExistentPoolMap #2853

Merged
merged 3 commits into from
Aug 2, 2024
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
28 changes: 16 additions & 12 deletions 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 crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chrono = { workspace = true, features = ["clock"] }
clap = { workspace = true }
contracts = { path = "../contracts" }
database = { path = "../database" }
delay_map = "0.3"
ttl_cache = "0.5"
derivative = { workspace = true }
ethcontract = { workspace = true }
ethrpc = { path = "../ethrpc" }
Expand Down
7 changes: 2 additions & 5 deletions crates/shared/src/sources/uniswap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ impl UniV2BaselineSourceParameters {
PoolReadingStyle::Default => Box::new(pool_reader),
PoolReadingStyle::Swapr => Box::new(SwaprPoolReader(pool_reader)),
};
let fetcher = pool_fetching::PoolFetcher {
pool_reader,
web3: web3.clone(),
non_existent_pools: Default::default(),
};
let fetcher =
pool_fetching::PoolFetcher::new(pool_reader, web3.clone(), Default::default());
Ok(UniV2BaselineSource {
router,
pair_provider,
Expand Down
10 changes: 6 additions & 4 deletions crates/shared/src/sources/uniswap_v2/pool_fetching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use {
},
anyhow::Result,
contracts::{IUniswapLikePair, ERC20},
delay_map::HashSetDelay,
ethcontract::{errors::MethodError, BlockId, H160, U256},
futures::{
future::{self, BoxFuture},
Expand All @@ -17,6 +16,7 @@ use {
model::TokenPair,
num::rational::Ratio,
std::{collections::HashSet, sync::RwLock, time::Duration},
ttl_cache::TtlCache,
};

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

impl<Reader> PoolFetcher<Reader> {
pub fn new(reader: Reader, web3: Web3, cache_time: Duration) -> Self {
Self {
pool_reader: reader,
web3,
non_existent_pools: RwLock::new(HashSetDelay::new(cache_time)),
cache_time,
non_existent_pools: RwLock::new(TtlCache::new(usize::MAX)),
}
}
}
Expand Down Expand Up @@ -231,7 +233,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);
non_existent_pools.insert(pair, (), self.cache_time);
}
}
Ok(pools)
Expand Down
Loading