From 615f92563d552a54b1afd51d1e08a4ae59326258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Pace?= Date: Sat, 26 Feb 2022 07:57:29 -0300 Subject: [PATCH 1/2] node: Add --debug-fork opt --- node/src/main.rs | 6 +++++- node/src/opt.rs | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/node/src/main.rs b/node/src/main.rs index e1d04bc44c6..43263f5c538 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -421,13 +421,17 @@ async fn main() { .expect("Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'"); let subgraph_id = DeploymentHash::new(hash).expect("Subgraph hash must be a valid IPFS hash"); + let debug_fork = opt + .debug_fork + .map(DeploymentHash::new) + .map(|h| h.expect("Debug fork hash must be a valid IPFS hash")); graph::spawn( async move { subgraph_registrar.create_subgraph(name.clone()).await?; subgraph_registrar // TODO: Add support for `debug_fork` parameter - .create_subgraph_version(name, subgraph_id, node_id, None) + .create_subgraph_version(name, subgraph_id, node_id, debug_fork) .await } .map_err(|e| panic!("Failed to deploy subgraph from `--subgraph` flag: {}", e)), diff --git a/node/src/opt.rs b/node/src/opt.rs index 39c0d47f525..e55bc7fa0bb 100644 --- a/node/src/opt.rs +++ b/node/src/opt.rs @@ -196,6 +196,13 @@ pub struct Opt { )] pub unsafe_config: bool, + #[structopt( + long, + value_name = "IPFS_HASH", + help = "IPFS hash of the subgraph manifest that you want to fork" + )] + pub debug_fork: Option, + #[structopt(long, value_name = "URL", help = "Base URL for forking subgraphs")] pub fork_base: Option, } From f9b5c322e829ddf11450b716b87e51e1e309152d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Pace?= Date: Sat, 26 Feb 2022 08:19:44 -0300 Subject: [PATCH 2/2] node: Add --start-block opt --- core/src/subgraph/registrar.rs | 12 +++++++++++- graph/src/components/subgraph/registrar.rs | 1 + node/src/main.rs | 22 ++++++++++++++++++++-- node/src/manager/commands/run.rs | 1 + node/src/opt.rs | 8 ++++++++ server/json-rpc/src/lib.rs | 3 +++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/core/src/subgraph/registrar.rs b/core/src/subgraph/registrar.rs index a00e14aa654..8bc3f7de634 100644 --- a/core/src/subgraph/registrar.rs +++ b/core/src/subgraph/registrar.rs @@ -267,6 +267,7 @@ where hash: DeploymentHash, node_id: NodeId, debug_fork: Option, + start_block: Option, ) -> Result<(), SubgraphRegistrarError> { // 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 @@ -302,6 +303,7 @@ where self.chains.cheap_clone(), name.clone(), hash.cheap_clone(), + start_block, raw, node_id, debug_fork, @@ -318,6 +320,7 @@ where self.chains.cheap_clone(), name.clone(), hash.cheap_clone(), + start_block, raw, node_id, debug_fork, @@ -334,6 +337,7 @@ where self.chains.cheap_clone(), name.clone(), hash.cheap_clone(), + start_block, raw, node_id, debug_fork, @@ -510,6 +514,7 @@ async fn create_subgraph_version, name: SubgraphName, deployment: DeploymentHash, + start_block_ptr: Option, raw: serde_yaml::Mapping, node_id: NodeId, debug_fork: Option, @@ -550,9 +555,14 @@ async fn create_subgraph_version Some(block), + None => manifest_start_block, + }; + info!( logger, "Set subgraph start block"; diff --git a/graph/src/components/subgraph/registrar.rs b/graph/src/components/subgraph/registrar.rs index dbd118a1723..9ab99c2c6cd 100644 --- a/graph/src/components/subgraph/registrar.rs +++ b/graph/src/components/subgraph/registrar.rs @@ -32,6 +32,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static { hash: DeploymentHash, assignment_node_id: NodeId, debug_fork: Option, + start_block: Option, ) -> Result<(), SubgraphRegistrarError>; async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>; diff --git a/node/src/main.rs b/node/src/main.rs index 43263f5c538..86cb1961856 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -425,13 +425,31 @@ async fn main() { .debug_fork .map(DeploymentHash::new) .map(|h| h.expect("Debug fork hash must be a valid IPFS hash")); + let start_block = opt + .start_block + .map(|block| { + let mut split = block.split(":"); + ( + // BlockHash + split.next().unwrap().to_owned(), + // BlockNumber + split.next().unwrap().parse::().unwrap(), + ) + }) + .map(|(hash, number)| BlockPtr::try_from((hash.as_str(), number))) + .map(Result::unwrap); graph::spawn( async move { subgraph_registrar.create_subgraph(name.clone()).await?; subgraph_registrar - // TODO: Add support for `debug_fork` parameter - .create_subgraph_version(name, subgraph_id, node_id, debug_fork) + .create_subgraph_version( + name, + subgraph_id, + node_id, + debug_fork, + start_block, + ) .await } .map_err(|e| panic!("Failed to deploy subgraph from `--subgraph` flag: {}", e)), diff --git a/node/src/manager/commands/run.rs b/node/src/manager/commands/run.rs index eed0bd199e7..57b36246504 100644 --- a/node/src/manager/commands/run.rs +++ b/node/src/manager/commands/run.rs @@ -180,6 +180,7 @@ pub async fn run( subgraph_hash.clone(), node_id.clone(), None, + None, ) .await?; diff --git a/node/src/opt.rs b/node/src/opt.rs index e55bc7fa0bb..362eb19561d 100644 --- a/node/src/opt.rs +++ b/node/src/opt.rs @@ -34,6 +34,14 @@ pub struct Opt { help = "name and IPFS hash of the subgraph manifest" )] pub subgraph: Option, + + #[structopt( + long, + value_name = "BLOCK_HASH:BLOCK_NUMBER", + help = "block hash and number that the subgraph passed will start indexing at" + )] + pub start_block: Option, + #[structopt( long, value_name = "URL", diff --git a/server/json-rpc/src/lib.rs b/server/json-rpc/src/lib.rs index dd743d64f76..def9599dbd8 100644 --- a/server/json-rpc/src/lib.rs +++ b/server/json-rpc/src/lib.rs @@ -98,6 +98,9 @@ impl JsonRpcServer { params.ipfs_hash.clone(), node_id, params.debug_fork.clone(), + // Here it doesn't make sense to receive another + // startBlock, we'll use the one from the manifest. + None, ) .await {