Skip to content

Commit

Permalink
json-rpc: Add history_blocks as parameter to create_subgraph_version (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas authored Apr 26, 2023
1 parent 357517f commit ce693d8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ where
debug_fork: Option<DeploymentHash>,
start_block_override: Option<BlockPtr>,
graft_block_override: Option<BlockPtr>,
history_blocks: Option<i32>,
) -> Result<DeploymentLocator, 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 @@ -311,6 +312,7 @@ where
debug_fork,
self.version_switching_mode,
&self.resolver,
history_blocks,
)
.await?
}
Expand All @@ -328,6 +330,7 @@ where
debug_fork,
self.version_switching_mode,
&self.resolver,
history_blocks,
)
.await?
}
Expand All @@ -345,6 +348,7 @@ where
debug_fork,
self.version_switching_mode,
&self.resolver,
history_blocks,
)
.await?
}
Expand All @@ -362,6 +366,7 @@ where
debug_fork,
self.version_switching_mode,
&self.resolver,
history_blocks,
)
.await?
}
Expand All @@ -379,6 +384,7 @@ where
debug_fork,
self.version_switching_mode,
&self.resolver,
history_blocks,
)
.await?
}
Expand Down Expand Up @@ -541,6 +547,7 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(
debug_fork: Option<DeploymentHash>,
version_switching_mode: SubgraphVersionSwitchingMode,
resolver: &Arc<dyn LinkResolver>,
history_blocks: Option<i32>,
) -> Result<DeploymentLocator, SubgraphRegistrarError> {
let raw_string = serde_yaml::to_string(&raw).unwrap();
let unvalidated = UnvalidatedSubgraphManifest::<C>::resolve(
Expand Down Expand Up @@ -626,10 +633,13 @@ async fn create_subgraph_version<C: Blockchain, S: SubgraphStore>(

// 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(
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 @@ -44,6 +44,7 @@ pub trait SubgraphRegistrar: Send + Sync + 'static {
debug_fork: Option<DeploymentHash>,
start_block_block: Option<BlockPtr>,
graft_block_override: Option<BlockPtr>,
history_blocks: Option<i32>,
) -> Result<DeploymentLocator, SubgraphRegistrarError>;

async fn remove_subgraph(&self, name: SubgraphName) -> Result<(), SubgraphRegistrarError>;
Expand Down
7 changes: 7 additions & 0 deletions graph/src/data/subgraph/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct DeploymentCreate {
pub graft_base: Option<DeploymentHash>,
pub graft_block: Option<BlockPtr>,
pub debug_fork: Option<DeploymentHash>,
pub history_blocks: Option<i32>,
}

impl DeploymentCreate {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ async fn main() {
debug_fork,
start_block,
None,
None,
)
.await
}
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 @@ -232,6 +232,7 @@ pub async fn run(
None,
None,
None,
None,
)
.await?;

Expand Down
2 changes: 2 additions & 0 deletions server/json-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl<R: SubgraphRegistrar> ServerState<R> {
// startBlock, we'll use the one from the manifest.
None,
None,
params.history_blocks,
)
.await
{
Expand Down Expand Up @@ -236,6 +237,7 @@ struct SubgraphDeployParams {
ipfs_hash: DeploymentHash,
node_id: Option<NodeId>,
debug_fork: Option<DeploymentHash>,
history_blocks: Option<i32>,
}

#[derive(Debug, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion store/postgres/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions store/postgres/src/subgraph_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,16 @@ impl SubgraphStoreInner {
)));
}

let history_blocks = deployment.manifest.history_blocks;

// Transmogrify the deployment into a new one
let deployment = DeploymentCreate {
manifest: deployment.manifest,
start_block: deployment.start_block.clone(),
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)?;
Expand Down
1 change: 1 addition & 0 deletions tests/src/fixture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ pub async fn setup<C: Blockchain>(
None,
None,
graft_block,
None,
)
.await
.expect("failed to create subgraph version");
Expand Down

0 comments on commit ce693d8

Please sign in to comment.