Skip to content

Commit

Permalink
graph: Prevent duplicate source subgraphs in manifest validation
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Feb 11, 2025
1 parent 0260db4 commit b6b97d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 17 additions & 0 deletions graph/src/data/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,23 @@ impl<C: Blockchain> UnvalidatedSubgraphManifest<C> {
));
}

// Check for duplicate source subgraphs
let mut seen_sources = std::collections::HashSet::new();
for ds in data_sources.iter() {
if let DataSource::Subgraph(ds) = ds {
let source_id = ds.source.address();
if !seen_sources.insert(source_id.clone()) {
errors.push(SubgraphManifestValidationError::DataSourceValidation(
"subgraph".to_string(),
anyhow!(
"Multiple subgraph datasources cannot use the same source subgraph {}",
source_id
),
));
}
}
}

errors
}

Expand Down
4 changes: 1 addition & 3 deletions graph/src/data_source/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ impl UnresolvedDataSource {
.iter()
.any(|ds| matches!(ds, crate::data_source::DataSource::Subgraph(_)))
{
return Err(anyhow!(
"Nested subgraph data sources are not supported."
));
return Err(anyhow!("Nested subgraph data sources are not supported."));
}

if source_spec_version < &SPEC_VERSION_1_3_0 {
Expand Down

0 comments on commit b6b97d7

Please sign in to comment.