diff --git a/node/src/manager/commands/rewind.rs b/node/src/manager/commands/rewind.rs index 339f2ec979a..d93966ad02b 100644 --- a/node/src/manager/commands/rewind.rs +++ b/node/src/manager/commands/rewind.rs @@ -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}; @@ -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(); @@ -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!(