Skip to content

Commit 4e41104

Browse files
committed
graph: Prevent duplicate source subgraphs in manifest validation
1 parent 07b47f7 commit 4e41104

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

graph/src/data/subgraph/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,23 @@ impl<C: Blockchain> UnvalidatedSubgraphManifest<C> {
719719
));
720720
}
721721

722+
// Check for duplicate source subgraphs
723+
let mut seen_sources = std::collections::HashSet::new();
724+
for ds in data_sources.iter() {
725+
if let DataSource::Subgraph(ds) = ds {
726+
let source_id = ds.source.address();
727+
if !seen_sources.insert(source_id.clone()) {
728+
errors.push(SubgraphManifestValidationError::DataSourceValidation(
729+
"subgraph".to_string(),
730+
anyhow!(
731+
"Multiple subgraph datasources cannot use the same source subgraph {}",
732+
source_id
733+
),
734+
));
735+
}
736+
}
737+
}
738+
722739
errors
723740
}
724741

graph/src/data_source/subgraph.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ impl UnresolvedDataSource {
292292
.iter()
293293
.any(|ds| matches!(ds, crate::data_source::DataSource::Subgraph(_)))
294294
{
295-
return Err(anyhow!(
296-
"Nested subgraph data sources are not supported."
297-
));
295+
return Err(anyhow!("Nested subgraph data sources are not supported."));
298296
}
299297

300298
if source_spec_version < &SPEC_VERSION_1_3_0 {

store/test-store/tests/chain/ethereum/manifest.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ dataSources:
318318
- Profile
319319
network: mainnet
320320
source:
321-
address: 'QmSource'
321+
address: 'QmSource2'
322322
startBlock: 9562500
323323
mapping:
324324
apiVersion: 0.0.6
@@ -1708,60 +1708,6 @@ dataSources:
17081708
});
17091709
}
17101710

1711-
#[tokio::test]
1712-
async fn multiple_subgraph_ds_manifest_should_fail() {
1713-
let yaml = "
1714-
schema:
1715-
file:
1716-
/: /ipfs/Qmschema
1717-
dataSources:
1718-
- name: SubgraphSource1
1719-
kind: subgraph
1720-
entities:
1721-
- User
1722-
network: mainnet
1723-
source:
1724-
address: 'QmSource'
1725-
startBlock: 9562480
1726-
mapping:
1727-
apiVersion: 0.0.6
1728-
language: wasm/assemblyscript
1729-
entities:
1730-
- TestEntity
1731-
file:
1732-
/: /ipfs/Qmmapping
1733-
handlers:
1734-
- handler: handleEntity
1735-
entity: User
1736-
- name: SubgraphSource2
1737-
kind: subgraph
1738-
entities:
1739-
- Profile
1740-
network: mainnet
1741-
source:
1742-
address: 'QmSource2'
1743-
startBlock: 9562500
1744-
mapping:
1745-
apiVersion: 0.0.6
1746-
language: wasm/assemblyscript
1747-
entities:
1748-
- TestEntity
1749-
file:
1750-
/: /ipfs/Qmmapping
1751-
handlers:
1752-
- handler: handleProfile
1753-
entity: Profile
1754-
specVersion: 1.3.0
1755-
";
1756-
1757-
let result = try_resolve_manifest(yaml, SPEC_VERSION_1_3_0).await;
1758-
assert!(result.is_err());
1759-
let err = result.unwrap_err();
1760-
assert!(err
1761-
.to_string()
1762-
.contains("Cannot have more than one subgraph datasource"));
1763-
}
1764-
17651711
#[tokio::test]
17661712
async fn mixed_subgraph_and_onchain_ds_manifest_should_fail() {
17671713
let yaml = "

0 commit comments

Comments
 (0)