Skip to content

Commit bd74ea5

Browse files
committed
core, graph: only use Amp start block resolver for Amp subgraphs
1 parent 004eb1e commit bd74ea5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

core/src/subgraph/registrar.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ async fn resolve_amp_start_block<AC: amp::Client>(
430430
block_number: BlockNumber,
431431
) -> Result<BlockPtr, anyhow::Error> {
432432
let sql = format!(
433-
"SELECT * FROM {}.{} WHERE _block_num = {}",
433+
"SELECT * FROM {}.{} WHERE _block_num = {} LIMIT 1",
434434
context_dataset, context_table, block_number
435435
);
436436

@@ -569,6 +569,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, AC: amp::Clien
569569

570570
let network_name: Word = manifest.network_name().into();
571571
let resolved_name = amp_chain_names.resolve(&network_name);
572+
let is_amp_subgraph = manifest.is_amp_subgraph();
572573

573574
let chain = chains
574575
.get::<C>(resolved_name.clone())
@@ -604,7 +605,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, AC: amp::Clien
604605
// Genesis block — no resolution needed.
605606
(0, _, _) => None,
606607
// Amp subgraph with start_block > 0 — try Amp-based resolution.
607-
(min, Some(client), Some((dataset, table))) => {
608+
(min, Some(client), Some((dataset, table))) if is_amp_subgraph => {
608609
match resolve_amp_start_block(client.as_ref(), &logger, dataset, table, min - 1)
609610
.await
610611
{
@@ -823,7 +824,7 @@ mod tests {
823824
assert_eq!(queries.len(), 1);
824825
assert_eq!(
825826
queries[0],
826-
"SELECT * FROM my_dataset.blocks WHERE _block_num = 99"
827+
"SELECT * FROM my_dataset.blocks WHERE _block_num = 99 LIMIT 1"
827828
);
828829
}
829830

@@ -850,7 +851,7 @@ mod tests {
850851
let queries = client.recorded_queries();
851852
assert_eq!(
852853
queries[0],
853-
"SELECT * FROM eth_mainnet.blocks WHERE _block_num = 99"
854+
"SELECT * FROM eth_mainnet.blocks WHERE _block_num = 99 LIMIT 1"
854855
);
855856
}
856857

graph/src/data/subgraph/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ impl<C: Blockchain> SubgraphManifest<C> {
991991
Ok(resolved)
992992
}
993993

994+
pub fn is_amp_subgraph(&self) -> bool {
995+
self.data_sources
996+
.iter()
997+
.all(|ds| matches!(ds, DataSource::Amp(_)))
998+
}
999+
9941000
pub fn network_name(&self) -> String {
9951001
// Assume the manifest has been validated, ensuring network names are homogenous
9961002
self.data_sources

0 commit comments

Comments
 (0)