Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add history_blocks to manifest #5032

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(
.await
.map_err(SubgraphRegistrarError::ManifestValidationError)?;

let history_blocks = history_blocks.or(manifest.history_blocks());

let network_name = manifest.network_name();

let chain = chains
Expand Down
22 changes: 22 additions & 0 deletions graph/src/data/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,19 @@ pub struct BaseSubgraphManifest<C, S, D, T> {
pub templates: Vec<T>,
#[serde(skip_serializing, default)]
pub chain: PhantomData<C>,
pub indexer_hints: Option<IndexerHints>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IndexerHints {
pub prune: Option<PruneConfig>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PruneConfig {
pub history_blocks: Option<BlockNumber>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leoyvens how does this look? If we have ongoing pruning do we need to the prune hint to do the manual pruning?

indexingHints:
   prune:
    historyBlocks: 100

}

/// SubgraphManifest with IPFS links unresolved
Expand Down Expand Up @@ -674,6 +687,13 @@ impl<C: Blockchain> SubgraphManifest<C> {
.collect()
}

pub fn history_blocks(&self) -> Option<BlockNumber> {
self.indexer_hints
.as_ref()
.and_then(|h| h.prune.as_ref())
.and_then(|p| p.history_blocks)
}

pub fn api_versions(&self) -> impl Iterator<Item = semver::Version> + '_ {
self.templates
.iter()
Expand Down Expand Up @@ -788,6 +808,7 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
graft,
templates,
chain,
indexer_hints,
} = self;

if !(MIN_SPEC_VERSION..=max_spec_version.clone()).contains(&spec_version) {
Expand Down Expand Up @@ -884,6 +905,7 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
graft,
templates,
chain,
indexer_hints,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions store/test-store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub async fn create_subgraph(
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

create_subgraph_with_manifest(subgraph_id, schema, manifest, base).await
Expand Down Expand Up @@ -236,6 +237,7 @@ pub async fn create_test_subgraph_with_features(
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

let deployment_features = manifest.deployment_features();
Expand Down
52 changes: 52 additions & 0 deletions store/test-store/tests/chain/ethereum/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,58 @@ specVersion: 0.0.2
assert_eq!(12345, graft.block);
}

#[tokio::test]
async fn parse_indexer_hints() {
const YAML: &str = "
dataSources: []
schema:
file:
/: /ipfs/Qmschema
graft:
base: Qmbase
block: 12345
specVersion: 0.0.2
indexerHints:
prune:
historyBlocks: 100
";

let manifest = resolve_manifest(YAML, SPEC_VERSION_0_0_4).await;

assert_eq!("Qmmanifest", manifest.id.as_str());
assert_eq!(
manifest
.indexer_hints
.unwrap()
.prune
.unwrap()
.history_blocks
.unwrap(),
100
);
}

#[tokio::test]
async fn parse_indexer_hints_prune() {
const YAML: &str = "
dataSources: []
schema:
file:
/: /ipfs/Qmschema
graft:
base: Qmbase
block: 12345
specVersion: 0.0.2
indexerHints:
prune:
";

let manifest = resolve_manifest(YAML, SPEC_VERSION_0_0_4).await;

assert_eq!("Qmmanifest", manifest.id.as_str());
assert!(manifest.indexer_hints.unwrap().prune.is_some());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this test - what is this trying to ensure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i used that test to test out the indexer_hints parsing is working properly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its was removed already. merging

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment what the intent of the test was would have been fine, too - it was just a bit confusing.

}

#[test]
fn graft_failed_subgraph() {
const YAML: &str = "
Expand Down
1 change: 1 addition & 0 deletions store/test-store/tests/graph/entity_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

// Create SubgraphDeploymentEntity
Expand Down
1 change: 1 addition & 0 deletions store/test-store/tests/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ async fn setup(
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

insert_test_entities(store.subgraph_store().as_ref(), manifest, id_type).await
Expand Down
1 change: 1 addition & 0 deletions store/test-store/tests/postgres/graft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

// Create SubgraphDeploymentEntity
Expand Down
2 changes: 2 additions & 0 deletions store/test-store/tests/postgres/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

// Create SubgraphDeploymentEntity
Expand Down Expand Up @@ -1261,6 +1262,7 @@ fn entity_changes_are_fired_and_forwarded_to_subscriptions() {
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

let deployment =
Expand Down
1 change: 1 addition & 0 deletions store/test-store/tests/postgres/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fn create_subgraph() {
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};
let deployment = DeploymentCreate::new(String::new(), &manifest, None);
let node_id = NodeId::new("left").unwrap();
Expand Down
1 change: 1 addition & 0 deletions store/test-store/tests/postgres/writable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
graft: None,
templates: vec![],
chain: PhantomData,
indexer_hints: None,
};

// Create SubgraphDeploymentEntity
Expand Down
Loading