Skip to content

Commit

Permalink
node: fix graphman rewind to start block
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyasmohd committed Dec 28, 2024
1 parent 1d29605 commit 9682ca5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions node/src/manager/commands/rewind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use graph::anyhow::bail;
use graph::components::store::{BlockStore as _, ChainStore as _, DeploymentLocator};
use graph::env::ENV_VARS;
use graph::prelude::{anyhow, BlockNumber, BlockPtr};
use graph_store_postgres::command_support::catalog::{self as store_catalog};
use graph_store_postgres::{connection_pool::ConnectionPool, Store};
use graph_store_postgres::{BlockStore, NotificationSender};

Expand Down Expand Up @@ -78,8 +77,6 @@ pub async fn run(
if !start_block && (block_hash.is_none() || block_number.is_none()) {
bail!("--block-hash and --block-number must be specified when --start-block is not set");
}
let pconn = primary.get()?;
let mut conn = store_catalog::Connection::new(pconn);

let subgraph_store = store.subgraph_store();
let block_store = store.block_store();
Expand Down Expand Up @@ -126,12 +123,15 @@ pub async fn run(

println!("Checking if its safe to rewind deployments");
for (_, locator) in &locators {
let site = conn
.locate_site(locator.clone())?
.ok_or_else(|| anyhow!("failed to locate site for {locator}"))?;
let deployment_store = subgraph_store.for_site(&site)?;
let deployment_details = deployment_store.deployment_details_for_id(locator)?;
let block_number_to = block_ptr_to.as_ref().map(|b| b.number).unwrap_or(0);
let deployment_details = subgraph_store.load_deployment_by_id(locator.clone().into())?;
let mut block_number_to = block_ptr_to.as_ref().map(|b| b.number).unwrap_or(0);

if start_block {
block_number_to = match deployment_details.start_block {
Some(block) => block.number,
None => 0,
};
}

if block_number_to < deployment_details.earliest_block_number + ENV_VARS.reorg_threshold {
bail!(
Expand Down

0 comments on commit 9682ca5

Please sign in to comment.