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

json-rpc: Add history_blocks as parameter to create_subgraph_version #4564

Merged
merged 1 commit into from
Apr 26, 2023
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 @@ -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 @@ -1049,6 +1049,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 @@ -1088,7 +1089,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 @@ -621,13 +621,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