Skip to content
Snippets Groups Projects
Commit e53a932f authored by Cecile Tonglet's avatar Cecile Tonglet Committed by GitHub
Browse files

Add a command to purge the relay chain only (#306)


* Add a command to purge the relay chain only

* WIP

* Update rococo-parachains/src/cli.rs

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>

* Move cli stuff to its own crate

* Copyright dates

* Test not working for some reason...

* WIP

* Revert "WIP"

This reverts commit f97cd63742c7df822e4a6e52a29db5e0f56b7bfa.

* Fix test to use provided relay chain

* Apply suggestions from code review

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>

* Add hint about which database could not be purged

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
parent fb649f19
No related merge requests found
Showing
with 155 additions and 15 deletions
......@@ -1112,6 +1112,15 @@ dependencies = [
"rand 0.7.3",
]
[[package]]
name = "cumulus-cli"
version = "0.1.0"
dependencies = [
"sc-cli",
"sc-service",
"structopt",
]
[[package]]
name = "cumulus-client-collator"
version = "0.1.0"
......@@ -7077,6 +7086,7 @@ name = "rococo-collator"
version = "0.1.0"
dependencies = [
"assert_cmd",
"cumulus-cli",
"cumulus-client-collator",
"cumulus-client-consensus-relay-chain",
"cumulus-client-network",
......@@ -7133,6 +7143,7 @@ dependencies = [
"substrate-build-script-utils",
"substrate-test-client",
"substrate-test-runtime-client",
"tempfile",
"tokio 0.2.24",
"trie-root 0.15.2",
]
......
[workspace]
members = [
"cli",
"client/consensus/common",
"client/consensus/relay-chain",
"client/network",
......
[package]
name = "cumulus-cli"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
structopt = "0.3.3"
# Substrate dependencies
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! Cumulus CLI library.
#![warn(missing_docs)]
use sc_cli;
use std::{
fs,
io::{self, Write},
};
use structopt::StructOpt;
/// The `purge-chain` command used to remove the whole chain: the parachain and the relaychain.
#[derive(Debug, StructOpt)]
pub struct PurgeChainCmd {
/// The base struct of the purge-chain command.
#[structopt(flatten)]
pub base: sc_cli::PurgeChainCmd,
/// Only delete the para chain database
#[structopt(long, aliases = &["para"])]
pub parachain: bool,
/// Only delete the relay chain database
#[structopt(long, aliases = &["relay"])]
pub relaychain: bool,
}
impl PurgeChainCmd {
/// Run the purge command
pub fn run(
&self,
para_config: sc_service::Configuration,
relay_config: sc_service::Configuration,
) -> sc_cli::Result<()> {
let databases = match (self.parachain, self.relaychain) {
(true, true) | (false, false) => vec![
("parachain", para_config.database),
("relaychain", relay_config.database),
],
(true, false) => vec![("parachain", para_config.database)],
(false, true) => vec![("relaychain", relay_config.database)],
};
let db_paths = databases
.iter()
.map(|(chain_label, database)| {
database.path().ok_or_else(|| sc_cli::Error::Input(format!(
"Cannot purge custom database implementation of: {}",
chain_label,
)))
})
.collect::<sc_cli::Result<Vec<_>>>()?;
if !self.base.yes {
for db_path in &db_paths {
println!("{}", db_path.display());
}
print!("Are you sure to remove? [y/N]: ");
io::stdout().flush().expect("failed to flush stdout");
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let input = input.trim();
match input.chars().nth(0) {
Some('y') | Some('Y') => {}
_ => {
println!("Aborted");
return Ok(());
}
}
}
for db_path in &db_paths {
match fs::remove_dir_all(&db_path) {
Ok(_) => {
println!("{:?} removed.", &db_path);
}
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
eprintln!("{:?} did not exist.", &db_path);
}
Err(err) => return Err(err.into()),
}
}
Ok(())
}
}
impl sc_cli::CliConfiguration for PurgeChainCmd {
fn shared_params(&self) -> &sc_cli::SharedParams {
&self.base.shared_params
}
fn database_params(&self) -> Option<&sc_cli::DatabaseParams> {
Some(&self.base.database_params)
}
}
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2020 Parity Technologies (UK) Ltd.
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Substrate is free software: you can redistribute it and/or modify
......
......@@ -56,6 +56,7 @@ sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "maste
jsonrpc-core = "15.1.0"
# Cumulus dependencies
cumulus-cli = { path = "../cli" }
cumulus-client-consensus-relay-chain = { path = "../client/consensus/relay-chain" }
cumulus-client-collator = { path = "../client/collator" }
cumulus-client-service = { path = "../client/service" }
......@@ -76,6 +77,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
assert_cmd = "0.12"
nix = "0.17"
rand = "0.7.3"
tempfile = "3.2.0"
tokio = { version = "0.2.13", features = ["macros"] }
# Polkadot dependencies
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Substrate is free software: you can redistribute it and/or modify
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment