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

Improve debug forking #3292

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ where
hash: DeploymentHash,
node_id: NodeId,
debug_fork: Option<DeploymentHash>,
start_block: Option<BlockPtr>,
) -> 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
Expand Down Expand Up @@ -302,6 +303,7 @@ where
self.chains.cheap_clone(),
name.clone(),
hash.cheap_clone(),
start_block,
raw,
node_id,
debug_fork,
Expand All @@ -318,6 +320,7 @@ where
self.chains.cheap_clone(),
name.clone(),
hash.cheap_clone(),
start_block,
raw,
node_id,
debug_fork,
Expand All @@ -334,6 +337,7 @@ where
self.chains.cheap_clone(),
name.clone(),
hash.cheap_clone(),
start_block,
raw,
node_id,
debug_fork,
Expand Down Expand Up @@ -510,6 +514,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, L: LinkResolve
chains: Arc<BlockchainMap>,
name: SubgraphName,
deployment: DeploymentHash,
start_block_ptr: Option<BlockPtr>,
raw: serde_yaml::Mapping,
node_id: NodeId,
debug_fork: Option<DeploymentHash>,
Expand Down Expand Up @@ -550,9 +555,14 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore, L: LinkResolve
return Err(SubgraphRegistrarError::NameNotFound(name.to_string()));
}

let (start_block, base_block) =
let (manifest_start_block, base_block) =
resolve_subgraph_chain_blocks(&manifest, chain, &logger.clone()).await?;

let start_block = match start_block_ptr {
Some(block) => Some(block),
None => manifest_start_block,
};

info!(
logger,
"Set subgraph start block";
Expand Down
1 change: 1 addition & 0 deletions graph/src/components/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static {
hash: DeploymentHash,
assignment_node_id: NodeId,
debug_fork: Option<DeploymentHash>,
start_block: Option<BlockPtr>,
) -> Result<(), SubgraphRegistrarError>;

async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>;
Expand Down
26 changes: 24 additions & 2 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,35 @@ 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"));
let start_block = opt
.start_block
.map(|block| {
let mut split = block.split(":");
(
// BlockHash
split.next().unwrap().to_owned(),
// BlockNumber
split.next().unwrap().parse::<i64>().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, None)
.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)),
Expand Down
1 change: 1 addition & 0 deletions node/src/manager/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub async fn run(
subgraph_hash.clone(),
node_id.clone(),
None,
None,
)
.await?;

Expand Down
15 changes: 15 additions & 0 deletions node/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ pub struct Opt {
help = "name and IPFS hash of the subgraph manifest"
)]
pub subgraph: Option<String>,

#[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<String>,

#[structopt(
long,
value_name = "URL",
Expand Down Expand Up @@ -196,6 +204,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<String>,

#[structopt(long, value_name = "URL", help = "Base URL for forking subgraphs")]
pub fork_base: Option<String>,
}
Expand Down
3 changes: 3 additions & 0 deletions server/json-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ impl<R: SubgraphRegistrar> JsonRpcServer<R> {
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
{
Expand Down