From ce693d8893e9fa7cd5b17bdeffcae5a100b6cdb9 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Wed, 26 Apr 2023 16:14:25 +0100 Subject: [PATCH] json-rpc: Add history_blocks as parameter to create_subgraph_version (#4564) --- core/src/subgraph/registrar.rs | 12 +++++++++++- graph/src/components/subgraph/registrar.rs | 1 + graph/src/data/subgraph/schema.rs | 7 +++++++ node/src/main.rs | 1 + node/src/manager/commands/run.rs | 1 + server/json-rpc/src/lib.rs | 2 ++ store/postgres/src/deployment.rs | 3 ++- store/postgres/src/subgraph_store.rs | 3 +++ tests/src/fixture/mod.rs | 1 + 9 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/src/subgraph/registrar.rs b/core/src/subgraph/registrar.rs index b8d0f408e23..7f706fcd622 100644 --- a/core/src/subgraph/registrar.rs +++ b/core/src/subgraph/registrar.rs @@ -269,6 +269,7 @@ where debug_fork: Option, start_block_override: Option, graft_block_override: Option, + history_blocks: Option, ) -> Result { // We don't have a location for the subgraph yet; that will be // assigned when we deploy for real. For logging purposes, make up a @@ -311,6 +312,7 @@ where debug_fork, self.version_switching_mode, &self.resolver, + history_blocks, ) .await? } @@ -328,6 +330,7 @@ where debug_fork, self.version_switching_mode, &self.resolver, + history_blocks, ) .await? } @@ -345,6 +348,7 @@ where debug_fork, self.version_switching_mode, &self.resolver, + history_blocks, ) .await? } @@ -362,6 +366,7 @@ where debug_fork, self.version_switching_mode, &self.resolver, + history_blocks, ) .await? } @@ -379,6 +384,7 @@ where debug_fork, self.version_switching_mode, &self.resolver, + history_blocks, ) .await? } @@ -541,6 +547,7 @@ async fn create_subgraph_version( debug_fork: Option, version_switching_mode: SubgraphVersionSwitchingMode, resolver: &Arc, + history_blocks: Option, ) -> Result { let raw_string = serde_yaml::to_string(&raw).unwrap(); let unvalidated = UnvalidatedSubgraphManifest::::resolve( @@ -626,10 +633,13 @@ async fn create_subgraph_version( // Apply the subgraph versioning and deployment operations, // creating a new subgraph deployment if one doesn't exist. - let deployment = DeploymentCreate::new(raw_string, &manifest, start_block) + let mut deployment = DeploymentCreate::new(raw_string, &manifest, start_block) .graft(base_block) .debug(debug_fork) .entities_with_causality_region(needs_causality_region); + if let Some(history_blocks) = history_blocks { + deployment = deployment.with_history_blocks(history_blocks); + } deployment_store .create_subgraph_deployment( diff --git a/graph/src/components/subgraph/registrar.rs b/graph/src/components/subgraph/registrar.rs index cfb2c2ffa2c..8da173cd70d 100644 --- a/graph/src/components/subgraph/registrar.rs +++ b/graph/src/components/subgraph/registrar.rs @@ -44,6 +44,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static { debug_fork: Option, start_block_block: Option, graft_block_override: Option, + history_blocks: Option, ) -> Result; async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>; diff --git a/graph/src/data/subgraph/schema.rs b/graph/src/data/subgraph/schema.rs index 185f8227a4f..9f617a6b761 100644 --- a/graph/src/data/subgraph/schema.rs +++ b/graph/src/data/subgraph/schema.rs @@ -108,6 +108,7 @@ pub struct DeploymentCreate { pub graft_base: Option, pub graft_block: Option, pub debug_fork: Option, + pub history_blocks: Option, } impl DeploymentCreate { @@ -122,9 +123,15 @@ impl DeploymentCreate { graft_base: None, graft_block: None, debug_fork: None, + history_blocks: None, } } + pub fn with_history_blocks(mut self, blocks: i32) -> Self { + self.history_blocks = Some(blocks); + self + } + pub fn graft(mut self, base: Option<(DeploymentHash, BlockPtr)>) -> Self { if let Some((subgraph, ptr)) = base { self.graft_base = Some(subgraph); diff --git a/node/src/main.rs b/node/src/main.rs index 9c38192f5ba..aad0c9f26e6 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -546,6 +546,7 @@ async fn main() { debug_fork, start_block, None, + None, ) .await } diff --git a/node/src/manager/commands/run.rs b/node/src/manager/commands/run.rs index fec254b1123..856484d082f 100644 --- a/node/src/manager/commands/run.rs +++ b/node/src/manager/commands/run.rs @@ -232,6 +232,7 @@ pub async fn run( None, None, None, + None, ) .await?; diff --git a/server/json-rpc/src/lib.rs b/server/json-rpc/src/lib.rs index c720905345e..0779a30b73d 100644 --- a/server/json-rpc/src/lib.rs +++ b/server/json-rpc/src/lib.rs @@ -123,6 +123,7 @@ impl ServerState { // startBlock, we'll use the one from the manifest. None, None, + params.history_blocks, ) .await { @@ -236,6 +237,7 @@ struct SubgraphDeployParams { ipfs_hash: DeploymentHash, node_id: Option, debug_fork: Option, + history_blocks: Option, } #[derive(Debug, Deserialize)] diff --git a/store/postgres/src/deployment.rs b/store/postgres/src/deployment.rs index 03f8b16eb0c..8f38c24410f 100644 --- a/store/postgres/src/deployment.rs +++ b/store/postgres/src/deployment.rs @@ -1050,6 +1050,7 @@ pub fn create_deployment( graft_base, graft_block, debug_fork, + history_blocks: history_blocks_override, } = deployment; let earliest_block_number = start_block.as_ref().map(|ptr| ptr.number).unwrap_or(0); let entities_with_causality_region = Vec::from_iter(entities_with_causality_region.into_iter()); @@ -1089,7 +1090,7 @@ pub fn create_deployment( m::start_block_number.eq(start_block.as_ref().map(|ptr| ptr.number)), m::raw_yaml.eq(raw_yaml), m::entities_with_causality_region.eq(entities_with_causality_region), - m::history_blocks.eq(history_blocks), + m::history_blocks.eq(history_blocks_override.unwrap_or(history_blocks)), ); if exists && replace { diff --git a/store/postgres/src/subgraph_store.rs b/store/postgres/src/subgraph_store.rs index 7ae6c7ef71c..0529b1c9954 100644 --- a/store/postgres/src/subgraph_store.rs +++ b/store/postgres/src/subgraph_store.rs @@ -622,6 +622,8 @@ impl SubgraphStoreInner { ))); } + let history_blocks = deployment.manifest.history_blocks; + // Transmogrify the deployment into a new one let deployment = DeploymentCreate { manifest: deployment.manifest, @@ -629,6 +631,7 @@ impl SubgraphStoreInner { graft_base: Some(src.deployment.clone()), graft_block: Some(block), debug_fork: deployment.debug_fork, + history_blocks: Some(history_blocks), }; let graft_base = self.layout(&src.deployment)?; diff --git a/tests/src/fixture/mod.rs b/tests/src/fixture/mod.rs index 7a803c3d341..e31d02dbf9d 100644 --- a/tests/src/fixture/mod.rs +++ b/tests/src/fixture/mod.rs @@ -422,6 +422,7 @@ pub async fn setup( None, None, graft_block, + None, ) .await .expect("failed to create subgraph version");