Revert chain command (#393)

* Revert chain command

* BLOCKS -> NUM

* Fixed warning
This commit is contained in:
Arkadiy Paronyan
2018-07-24 15:54:34 +02:00
committed by Gav Wood
parent 526de11fe8
commit f8a85231f1
2 changed files with 41 additions and 1 deletions
+17
View File
@@ -178,3 +178,20 @@ subcommands:
long: max-heap-pages
value_name: COUNT
help: The maximum number of 64KB pages to ever allocate for Wasm execution. Don't alter this unless you know what you're doing.
- revert:
about: Revert chain to the previous state
args:
- NUM:
index: 1
help: Number of blocks to revert. Default is 256.
- chain:
long: chain
value_name: CHAIN_SPEC
help: Specify the chain specification.
takes_value: true
- base-path:
long: base-path
short: d
value_name: PATH
help: Specify custom base path.
takes_value: true
+24 -1
View File
@@ -223,6 +223,10 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
return import_blocks(matches, worker.exit_only());
}
if let Some(matches) = matches.subcommand_matches("revert") {
return revert_chain(matches);
}
let (spec, is_global) = load_spec(&matches)?;
let mut config = service::Configuration::default_with_spec(spec);
@@ -248,7 +252,7 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
config.pruning = match matches.value_of("pruning") {
Some("archive") => PruningMode::ArchiveAll,
None => PruningMode::keep_blocks(256),
None => PruningMode::default(),
Some(s) => PruningMode::keep_blocks(s.parse()
.map_err(|_| error::ErrorKind::Input("Invalid pruning mode specified".to_owned()))?),
};
@@ -495,6 +499,25 @@ fn import_blocks<E>(matches: &clap::ArgMatches, exit: E) -> error::Result<()>
Ok(())
}
fn revert_chain(matches: &clap::ArgMatches) -> error::Result<()> {
let (spec, _) = load_spec(&matches)?;
let base_path = base_path(matches);
let mut config = service::Configuration::default_with_spec(spec);
config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into();
let client = service::new_client(config)?;
let blocks = match matches.value_of("NUM") {
Some(v) => v.parse().map_err(|_| "Invalid block count specified")?,
None => 256,
};
let reverted = client.revert(blocks)?;
let info = client.info()?.chain;
info!("Reverted {} blocks. Best: #{} ({})", reverted, info.best_number, info.best_hash);
Ok(())
}
fn run_until_exit<C, W>(
runtime: &mut Runtime,
service: service::Service<C>,