Skip to content

Commit 9682ca5

Browse files
committed
node: fix graphman rewind to start block
1 parent 1d29605 commit 9682ca5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

node/src/manager/commands/rewind.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use graph::anyhow::bail;
99
use graph::components::store::{BlockStore as _, ChainStore as _, DeploymentLocator};
1010
use graph::env::ENV_VARS;
1111
use graph::prelude::{anyhow, BlockNumber, BlockPtr};
12-
use graph_store_postgres::command_support::catalog::{self as store_catalog};
1312
use graph_store_postgres::{connection_pool::ConnectionPool, Store};
1413
use graph_store_postgres::{BlockStore, NotificationSender};
1514

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

8481
let subgraph_store = store.subgraph_store();
8582
let block_store = store.block_store();
@@ -126,12 +123,15 @@ pub async fn run(
126123

127124
println!("Checking if its safe to rewind deployments");
128125
for (_, locator) in &locators {
129-
let site = conn
130-
.locate_site(locator.clone())?
131-
.ok_or_else(|| anyhow!("failed to locate site for {locator}"))?;
132-
let deployment_store = subgraph_store.for_site(&site)?;
133-
let deployment_details = deployment_store.deployment_details_for_id(locator)?;
134-
let block_number_to = block_ptr_to.as_ref().map(|b| b.number).unwrap_or(0);
126+
let deployment_details = subgraph_store.load_deployment_by_id(locator.clone().into())?;
127+
let mut block_number_to = block_ptr_to.as_ref().map(|b| b.number).unwrap_or(0);
128+
129+
if start_block {
130+
block_number_to = match deployment_details.start_block {
131+
Some(block) => block.number,
132+
None => 0,
133+
};
134+
}
135135

136136
if block_number_to < deployment_details.earliest_block_number + ENV_VARS.reorg_threshold {
137137
bail!(

0 commit comments

Comments
 (0)