Skip to content

Commit 0f3a67a

Browse files
jmg-duartegithub-actions-bot
authored andcommitted
Revert "Fetch uncached V3 pools on demand so cold quotes find liquidity (#4560)" (#4629)
# Description The original PR led to `fetch_liquidity` taking orders of magnitude more than usual on service restarts. When performing tests this becomes particularly bad because of the deployment neighboring nature. <img width="739" height="614" alt="image" src="https://github.com/user-attachments/assets/3423386a-4199-4009-a353-078919d8980a" /> # Changes * Reverts commit 8cb2626. ## How to test Tested in prod, notice how the spikes disappear <img width="1099" height="606" alt="image" src="https://github.com/user-attachments/assets/9468e91e-b021-4af7-9f16-df02e3237fa7" />
1 parent a8d2048 commit 0f3a67a

4 files changed

Lines changed: 77 additions & 354 deletions

File tree

crates/liquidity-sources/src/uniswap_v3/graph_api.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
crate::{
66
json_map,
77
subgraph::{ContainsId, SubgraphClient},
8-
uniswap_v3::{BlockTarget, V3PoolDataSource},
8+
uniswap_v3::V3PoolDataSource,
99
},
1010
alloy::primitives::{Address, U256},
1111
anyhow::Result,
@@ -168,15 +168,6 @@ impl UniV3SubgraphClient {
168168
.saturating_sub(MAX_REORG_BLOCK_COUNT))
169169
}
170170

171-
/// The subgraph queries by concrete block, so `Latest` resolves to the
172-
/// safe head.
173-
async fn resolve_block(&self, target: BlockTarget) -> Result<u64> {
174-
match target {
175-
BlockTarget::Latest => self.get_safe_block().await,
176-
BlockTarget::Number(n) => Ok(n),
177-
}
178-
}
179-
180171
fn all_pools_query(include_ticks_filter: bool) -> String {
181172
let tick_filter = if include_ticks_filter {
182173
r#"ticks_: { liquidityNet_not: "0" }"#
@@ -247,8 +238,7 @@ impl UniV3SubgraphClient {
247238
impl V3PoolDataSource for UniV3SubgraphClient {
248239
/// The subgraph supports historical queries, so every returned pool is
249240
/// consistently anchored at `target_block`.
250-
async fn get_registered_pools(&self, target_block: BlockTarget) -> Result<RegisteredPools> {
251-
let target_block = self.resolve_block(target_block).await?;
241+
async fn get_registered_pools(&self, target_block: u64) -> Result<RegisteredPools> {
252242
let variables = json_map! {
253243
"block" => target_block,
254244
};
@@ -268,12 +258,8 @@ impl V3PoolDataSource for UniV3SubgraphClient {
268258
async fn get_pools_with_ticks_by_ids(
269259
&self,
270260
ids: &[Address],
271-
target_block: BlockTarget,
261+
target_block: u64,
272262
) -> Result<PoolsWithTicks> {
273-
if ids.is_empty() {
274-
return Ok(PoolsWithTicks::default());
275-
}
276-
let target_block = self.resolve_block(target_block).await?;
277263
let (pools, ticks) = futures::try_join!(
278264
self.get_pools_by_pool_ids(ids, target_block),
279265
self.get_ticks_by_pools_ids(ids, target_block)

crates/liquidity-sources/src/uniswap_v3/mod.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,20 @@ use {
2727
/// the indexer's actual block can be later than `target_block`.
2828
#[async_trait]
2929
pub trait V3PoolDataSource: Send + Sync + 'static {
30-
/// Fetch the full set of pools the source knows about as of `target_block`.
31-
/// `PoolData::ticks` is always `None` here — callers needing ticks must use
32-
/// [`Self::get_pools_with_ticks_by_ids`] separately. The split lets a cheap
33-
/// "what pools exist?" lookup skip the expensive tick fetch.
34-
async fn get_registered_pools(&self, target_block: BlockTarget) -> Result<RegisteredPools>;
30+
/// Fetch the full set of pools the source knows about as of a block at or
31+
/// after `target_block`. `PoolData::ticks` is always `None` here — callers
32+
/// needing ticks must use [`Self::get_pools_with_ticks_by_ids`] separately.
33+
/// The split lets a cheap "what pools exist?" lookup skip the expensive
34+
/// tick fetch.
35+
async fn get_registered_pools(&self, target_block: u64) -> Result<RegisteredPools>;
3536

36-
/// Fetch pools + their active ticks for the given pool addresses as of
37-
/// `target_block`. The returned `fetched_block_number` is the actual
38-
/// snapshot block (`>=` a requested [`BlockTarget::Number`]); callers
39-
/// should use it as the event-replay anchor.
37+
/// Fetch pools + their active ticks for the given pool addresses as of a
38+
/// block at or after `target_block`. The returned `fetched_block_number` is
39+
/// the actual snapshot block (`>= target_block`); callers should use it as
40+
/// the event-replay anchor.
4041
async fn get_pools_with_ticks_by_ids(
4142
&self,
4243
ids: &[Address],
43-
target_block: BlockTarget,
44+
target_block: u64,
4445
) -> Result<PoolsWithTicks>;
4546
}
46-
47-
/// Which block a [`V3PoolDataSource`] anchors its snapshot to.
48-
#[derive(Clone, Copy, Debug)]
49-
pub enum BlockTarget {
50-
/// The latest block the source can serve: the subgraph resolves this to its
51-
/// safe head, the indexer serves at-head without waiting.
52-
Latest,
53-
/// A specific block; the source returns data at or after it.
54-
Number(u64),
55-
}

0 commit comments

Comments
 (0)