Skip to content

Commit

Permalink
node: Add graphman rewind
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Apr 20, 2021
1 parent 5454d2d commit 94e6d49
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions node/src/bin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ pub enum Command {
/// The id of the deployment to unassign
id: String,
},
Rewind {
id: String,
block_hash: String,
block_number: i32,
},
/// Check and interrogate the configuration
///
/// Print information about a configuration file without
Expand Down Expand Up @@ -321,6 +326,14 @@ async fn main() {
let store = make_store();
commands::assign::reassign(store, id, node)
}
Rewind {
id,
block_hash,
block_number,
} => {
let store = make_store();
commands::rewind::run(store, id, block_hash, block_number)
}
Listen(cmd) => {
use ListenCommand::*;
match cmd {
Expand Down
1 change: 1 addition & 0 deletions node/src/manager/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pub mod config;
pub mod info;
pub mod listen;
pub mod remove;
pub mod rewind;
pub mod txn_speed;
pub mod unused_deployments;
20 changes: 20 additions & 0 deletions node/src/manager/commands/rewind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::convert::TryFrom;
use std::sync::Arc;

use graph::prelude::{anyhow, BlockNumber, EthereumBlockPointer, SubgraphDeploymentId};
use graph_store_postgres::SubgraphStore;

pub fn run(
store: Arc<SubgraphStore>,
id: String,
block_hash: String,
block_number: BlockNumber,
) -> Result<(), anyhow::Error> {
let id =
SubgraphDeploymentId::new(id).map_err(|id| anyhow!("illegal deployment id `{}`", id))?;
let block_ptr_to = EthereumBlockPointer::try_from((block_hash.as_str(), block_number as i64))
.map_err(|e| anyhow!("error converting to block pointer: {}", e))?;

store.rewind(id, block_ptr_to)?;
Ok(())
}

0 comments on commit 94e6d49

Please sign in to comment.