Skip to content

Commit 90f4e5e

Browse files
committed
Revert "fix: Allow grafts to add data sources (#3989)"
This reverts commit 3b3b458.
1 parent d74449c commit 90f4e5e

File tree

21 files changed

+104
-310
lines changed

21 files changed

+104
-310
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use graph::blockchain::Blockchain;
88
use graph::blockchain::NodeCapabilities;
99
use graph::blockchain::{BlockchainKind, TriggerFilter};
1010
use graph::components::subgraph::ProofOfIndexingVersion;
11-
use graph::data::subgraph::{UnresolvedSubgraphManifest, SPEC_VERSION_0_0_6};
11+
use graph::data::subgraph::SPEC_VERSION_0_0_6;
1212
use graph::prelude::{SubgraphInstanceManager as SubgraphInstanceManagerTrait, *};
1313
use graph::{blockchain::BlockchainMap, components::store::DeploymentLocator};
1414
use graph_runtime_wasm::module::ToAscPtr;
@@ -176,49 +176,47 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
176176
.writable(logger.clone(), deployment.id)
177177
.await?;
178178

179-
let raw_yaml = serde_yaml::to_string(&manifest).unwrap();
180-
let manifest = UnresolvedSubgraphManifest::parse(deployment.hash.cheap_clone(), manifest)?;
181-
182-
// Make sure the `raw_yaml` is present on both this subgraph and the graft base.
183-
self.subgraph_store
184-
.set_manifest_raw_yaml(&deployment.hash, raw_yaml)
185-
.await?;
186-
if let Some(graft) = &manifest.graft {
187-
let file_bytes = self
188-
.link_resolver
189-
.cat(&logger, &graft.base.to_ipfs_link())
190-
.await?;
191-
let yaml = String::from_utf8(file_bytes)?;
192-
self.subgraph_store
193-
.set_manifest_raw_yaml(&graft.base, yaml)
194-
.await?;
195-
}
196-
197-
info!(logger, "Resolve subgraph files using IPFS");
198-
199-
// Allow for infinite retries for subgraph definition files.
200-
let link_resolver = Arc::from(self.link_resolver.with_retries());
201-
let mut manifest = manifest
202-
.resolve(&link_resolver, &logger, ENV_VARS.max_spec_version.clone())
203-
.await?;
204-
205-
info!(logger, "Successfully resolved subgraph files using IPFS");
206-
207-
let manifest_idx_and_name: Vec<(u32, String)> = manifest.template_idx_and_name().collect();
208-
209179
// Start the subgraph deployment before reading dynamic data
210180
// sources; if the subgraph is a graft or a copy, starting it will
211181
// do the copying and dynamic data sources won't show up until after
212182
// that is done
213183
store.start_subgraph_deployment(&logger).await?;
214184

215-
// Dynamic data sources are loaded by appending them to the manifest.
216-
//
217-
// Refactor: Preferrably we'd avoid any mutation of the manifest.
218-
let (manifest, static_data_sources) = {
219-
let data_sources = load_dynamic_data_sources(store.clone(), logger.clone(), &manifest)
220-
.await
221-
.context("Failed to load dynamic data sources")?;
185+
let (manifest, manifest_idx_and_name, static_data_sources) = {
186+
info!(logger, "Resolve subgraph files using IPFS");
187+
188+
let mut manifest = SubgraphManifest::resolve_from_raw(
189+
deployment.hash.cheap_clone(),
190+
manifest,
191+
// Allow for infinite retries for subgraph definition files.
192+
&Arc::from(self.link_resolver.with_retries()),
193+
&logger,
194+
ENV_VARS.max_spec_version.clone(),
195+
)
196+
.await
197+
.context("Failed to resolve subgraph from IPFS")?;
198+
199+
// We cannot include static data sources in the map because a static data source and a
200+
// template may have the same name in the manifest.
201+
let ds_len = manifest.data_sources.len() as u32;
202+
let manifest_idx_and_name: Vec<(u32, String)> = manifest
203+
.templates
204+
.iter()
205+
.map(|t| t.name().to_owned())
206+
.enumerate()
207+
.map(|(idx, name)| (ds_len + idx as u32, name))
208+
.collect();
209+
210+
let data_sources = load_dynamic_data_sources(
211+
store.clone(),
212+
logger.clone(),
213+
&manifest,
214+
manifest_idx_and_name.clone(),
215+
)
216+
.await
217+
.context("Failed to load dynamic data sources")?;
218+
219+
info!(logger, "Successfully resolved subgraph files using IPFS");
222220

223221
let static_data_sources = manifest.data_sources.clone();
224222

@@ -231,7 +229,7 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
231229
manifest.data_sources.len()
232230
);
233231

234-
(manifest, static_data_sources)
232+
(manifest, manifest_idx_and_name, static_data_sources)
235233
};
236234

237235
let static_filters =

core/src/subgraph/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub async fn load_dynamic_data_sources<C: Blockchain>(
99
store: Arc<dyn WritableStore>,
1010
logger: Logger,
1111
manifest: &SubgraphManifest<C>,
12+
manifest_idx_and_name: Vec<(u32, String)>,
1213
) -> Result<Vec<DataSource<C>>, Error> {
13-
let manifest_idx_and_name = manifest.template_idx_and_name().collect();
1414
let start_time = Instant::now();
1515

1616
let mut data_sources: Vec<DataSource<C>> = vec![];

core/src/subgraph/registrar.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(
552552
version_switching_mode: SubgraphVersionSwitchingMode,
553553
resolver: &Arc<dyn LinkResolver>,
554554
) -> Result<DeploymentLocator, SubgraphRegistrarError> {
555-
let raw_string = serde_yaml::to_string(&raw).unwrap();
556555
let unvalidated = UnvalidatedSubgraphManifest::<C>::resolve(
557556
deployment,
558557
raw,
@@ -619,7 +618,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(
619618

620619
// Apply the subgraph versioning and deployment operations,
621620
// creating a new subgraph deployment if one doesn't exist.
622-
let deployment = DeploymentCreate::new(raw_string, &manifest, start_block)
621+
let deployment = DeploymentCreate::new(&manifest, start_block)
623622
.graft(base_block)
624623
.debug(debug_fork);
625624
deployment_store

graph/src/components/store/traits.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ pub trait SubgraphStore: Send + Sync + 'static {
152152

153153
/// Find the deployment locators for the subgraph with the given hash
154154
fn locators(&self, hash: &str) -> Result<Vec<DeploymentLocator>, StoreError>;
155-
156-
/// This migrates subgraphs that existed before the raw_yaml column was added.
157-
async fn set_manifest_raw_yaml(
158-
&self,
159-
hash: &DeploymentHash,
160-
raw_yaml: String,
161-
) -> Result<(), StoreError>;
162155
}
163156

164157
pub trait ReadStore: Send + Sync + 'static {

graph/src/data/subgraph/mod.rs

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ pub mod status;
1010

1111
pub use features::{SubgraphFeature, SubgraphFeatureValidationError};
1212

13+
use anyhow::ensure;
1314
use anyhow::{anyhow, Error};
1415
use futures03::{future::try_join3, stream::FuturesOrdered, TryStreamExt as _};
1516
use semver::Version;
1617
use serde::{de, ser};
1718
use serde_yaml;
18-
use slog::{info, Logger};
19+
use slog::{debug, info, Logger};
1920
use stable_hash::{FieldAddress, StableHash};
2021
use stable_hash_legacy::SequenceNumber;
2122
use std::{collections::BTreeSet, marker::PhantomData};
@@ -24,7 +25,6 @@ use wasmparser;
2425
use web3::types::Address;
2526

2627
use crate::{
27-
bail,
2828
blockchain::{BlockPtr, Blockchain, DataSource as _},
2929
components::{
3030
link_resolver::LinkResolver,
@@ -41,7 +41,6 @@ use crate::{
4141
offchain::OFFCHAIN_KINDS, DataSource, DataSourceTemplate, UnresolvedDataSource,
4242
UnresolvedDataSourceTemplate,
4343
},
44-
ensure,
4544
prelude::{r, CheapClone, ENV_VARS},
4645
};
4746

@@ -357,7 +356,7 @@ pub enum SubgraphManifestResolveError {
357356
#[error("subgraph is not valid YAML")]
358357
InvalidFormat,
359358
#[error("resolve error: {0}")]
360-
ResolveError(#[from] anyhow::Error),
359+
ResolveError(anyhow::Error),
361360
}
362361

363362
/// Data source contexts are conveniently represented as entities.
@@ -497,7 +496,7 @@ pub struct BaseSubgraphManifest<C, S, D, T> {
497496
}
498497

499498
/// SubgraphManifest with IPFS links unresolved
500-
pub type UnresolvedSubgraphManifest<C> = BaseSubgraphManifest<
499+
type UnresolvedSubgraphManifest<C> = BaseSubgraphManifest<
501500
C,
502501
UnresolvedSchema,
503502
UnresolvedDataSource<C>,
@@ -615,16 +614,35 @@ impl<C: Blockchain> SubgraphManifest<C> {
615614
/// Entry point for resolving a subgraph definition.
616615
pub async fn resolve_from_raw(
617616
id: DeploymentHash,
618-
raw: serde_yaml::Mapping,
617+
mut raw: serde_yaml::Mapping,
619618
resolver: &Arc<dyn LinkResolver>,
620619
logger: &Logger,
621620
max_spec_version: semver::Version,
622621
) -> Result<Self, SubgraphManifestResolveError> {
623-
let unresolved = UnresolvedSubgraphManifest::parse(id, raw)?;
622+
// Inject the IPFS hash as the ID of the subgraph into the definition.
623+
raw.insert("id".into(), id.to_string().into());
624+
625+
// Parse the YAML data into an UnresolvedSubgraphManifest
626+
let unresolved: UnresolvedSubgraphManifest<C> = serde_yaml::from_value(raw.into())?;
627+
628+
debug!(logger, "Features {:?}", unresolved.features);
624629

625630
let resolved = unresolved
626631
.resolve(resolver, logger, max_spec_version)
627-
.await?;
632+
.await
633+
.map_err(SubgraphManifestResolveError::ResolveError)?;
634+
635+
if (resolved.spec_version < SPEC_VERSION_0_0_7)
636+
&& resolved
637+
.data_sources
638+
.iter()
639+
.any(|ds| OFFCHAIN_KINDS.contains(&ds.kind()))
640+
{
641+
return Err(SubgraphManifestResolveError::ResolveError(anyhow!(
642+
"Offchain data sources not supported prior to {}",
643+
SPEC_VERSION_0_0_7
644+
)));
645+
}
628646

629647
Ok(resolved)
630648
}
@@ -667,37 +685,15 @@ impl<C: Blockchain> SubgraphManifest<C> {
667685
) -> Result<UnifiedMappingApiVersion, DifferentMappingApiVersions> {
668686
UnifiedMappingApiVersion::try_from_versions(self.api_versions())
669687
}
670-
671-
pub fn template_idx_and_name(&self) -> impl Iterator<Item = (u32, String)> + '_ {
672-
// We cannot include static data sources in the map because a static data source and a
673-
// template may have the same name in the manifest. Duplicated with
674-
// `UnresolvedSubgraphManifest::template_idx_and_name`.
675-
let ds_len = self.data_sources.len() as u32;
676-
self.templates
677-
.iter()
678-
.map(|t| t.name().to_owned())
679-
.enumerate()
680-
.map(move |(idx, name)| (ds_len + idx as u32, name))
681-
}
682688
}
683689

684690
impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
685-
pub fn parse(
686-
id: DeploymentHash,
687-
mut raw: serde_yaml::Mapping,
688-
) -> Result<Self, SubgraphManifestResolveError> {
689-
// Inject the IPFS hash as the ID of the subgraph into the definition.
690-
raw.insert("id".into(), id.to_string().into());
691-
692-
serde_yaml::from_value(raw.into()).map_err(Into::into)
693-
}
694-
695691
pub async fn resolve(
696692
self,
697693
resolver: &Arc<dyn LinkResolver>,
698694
logger: &Logger,
699695
max_spec_version: semver::Version,
700-
) -> Result<SubgraphManifest<C>, SubgraphManifestResolveError> {
696+
) -> Result<SubgraphManifest<C>, anyhow::Error> {
701697
let UnresolvedSubgraphManifest {
702698
id,
703699
spec_version,
@@ -718,14 +714,14 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
718714
max_spec_version,
719715
id,
720716
spec_version
721-
).into());
717+
));
722718
}
723719

724720
let ds_count = data_sources.len();
725721
if ds_count as u64 + templates.len() as u64 > u32::MAX as u64 {
726-
return Err(
727-
anyhow!("Subgraph has too many declared data sources and templates",).into(),
728-
);
722+
return Err(anyhow!(
723+
"Subgraph has too many declared data sources and templates",
724+
));
729725
}
730726

731727
let (schema, data_sources, templates) = try_join3(
@@ -758,17 +754,6 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
758754
);
759755
}
760756

761-
if spec_version < SPEC_VERSION_0_0_7
762-
&& data_sources
763-
.iter()
764-
.any(|ds| OFFCHAIN_KINDS.contains(&ds.kind()))
765-
{
766-
bail!(
767-
"Offchain data sources not supported prior to {}",
768-
SPEC_VERSION_0_0_7
769-
);
770-
}
771-
772757
Ok(SubgraphManifest {
773758
id,
774759
spec_version,

graph/src/data/subgraph/schema.rs

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Entity types that contain the graph-node state.
22
3-
use anyhow::{anyhow, bail, Error};
3+
use anyhow::{anyhow, Error};
44
use hex;
55
use lazy_static::lazy_static;
66
use rand::rngs::OsRng;
@@ -110,12 +110,11 @@ pub struct DeploymentCreate {
110110

111111
impl DeploymentCreate {
112112
pub fn new(
113-
raw_manifest: String,
114113
source_manifest: &SubgraphManifest<impl Blockchain>,
115114
earliest_block: Option<BlockPtr>,
116115
) -> Self {
117116
Self {
118-
manifest: SubgraphManifestEntity::new(raw_manifest, source_manifest),
117+
manifest: SubgraphManifestEntity::from(source_manifest),
119118
earliest_block: earliest_block.cheap_clone(),
120119
graft_base: None,
121120
graft_block: None,
@@ -164,52 +163,18 @@ pub struct SubgraphManifestEntity {
164163
pub repository: Option<String>,
165164
pub features: Vec<String>,
166165
pub schema: String,
167-
pub raw_yaml: Option<String>,
168166
}
169167

170-
impl SubgraphManifestEntity {
171-
pub fn new(raw_yaml: String, manifest: &super::SubgraphManifest<impl Blockchain>) -> Self {
168+
impl<'a, C: Blockchain> From<&'a super::SubgraphManifest<C>> for SubgraphManifestEntity {
169+
fn from(manifest: &'a super::SubgraphManifest<C>) -> Self {
172170
Self {
173171
spec_version: manifest.spec_version.to_string(),
174172
description: manifest.description.clone(),
175173
repository: manifest.repository.clone(),
176174
features: manifest.features.iter().map(|f| f.to_string()).collect(),
177175
schema: manifest.schema.document.clone().to_string(),
178-
raw_yaml: Some(raw_yaml),
179176
}
180177
}
181-
182-
pub fn template_idx_and_name(&self) -> Result<Vec<(i32, String)>, Error> {
183-
#[derive(Debug, Deserialize)]
184-
struct MinimalDs {
185-
name: String,
186-
}
187-
#[derive(Debug, Deserialize)]
188-
#[serde(rename_all = "camelCase")]
189-
struct MinimalManifest {
190-
data_sources: Vec<MinimalDs>,
191-
#[serde(default)]
192-
templates: Vec<MinimalDs>,
193-
}
194-
195-
let raw_yaml = match &self.raw_yaml {
196-
Some(raw_yaml) => raw_yaml,
197-
None => bail!("raw_yaml not present"),
198-
};
199-
200-
let manifest: MinimalManifest = serde_yaml::from_str(raw_yaml)?;
201-
202-
let ds_len = manifest.data_sources.len() as i32;
203-
let template_idx_and_name = manifest
204-
.templates
205-
.iter()
206-
.map(|t| t.name.to_owned())
207-
.enumerate()
208-
.map(move |(idx, name)| (ds_len + idx as i32, name))
209-
.collect();
210-
211-
Ok(template_idx_and_name)
212-
}
213178
}
214179

215180
#[derive(Clone, Debug)]

graph/src/util/error.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,3 @@ macro_rules! ensure {
1717
}
1818
};
1919
}
20-
21-
// `bail!` from `anyhow`, but calling `from`.
22-
// For context see https://github.com/dtolnay/anyhow/issues/112#issuecomment-704549251.
23-
#[macro_export]
24-
macro_rules! bail {
25-
($($err:tt)*) => {
26-
return Err(anyhow::anyhow!($($err)*).into());
27-
};
28-
}

0 commit comments

Comments
 (0)