This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Add a command to purge the relay chain only #306
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
30b881a
Add a command to purge the relay chain only
cecton 137a2b0
WIP
cecton 552676b
Update rococo-parachains/src/cli.rs
cecton 358c18c
Move cli stuff to its own crate
cecton f60c5df
Copyright dates
cecton 087c098
Test not working for some reason...
cecton f97cd63
WIP
cecton d5179ff
Revert "WIP"
cecton c288c7b
Fix test to use provided relay chain
cecton db85797
Merge commit b5f6580da1df1895b0b0984ac855a1a2a69ccc26 (conflicts)
cecton 53d759e
Merge commit 0d086ae354fba5839ba7e6fec238094cb98cdd7a (no conflict)
cecton adc96eb
Merge commit cb00749f24a45408a6f77ce8600660749d17003c (no conflict)
cecton b9f3c66
Merge commit 6438d328b8ac09f43d19df65a2cf8e31a524d78f (conflicts)
cecton 060b186
Apply suggestions from code review
cecton 670b674
Add hint about which database could not be purged
cecton a258791
Merge commit e065c5776b5424cb945136a970f7183638ded614 (no conflict)
cecton 6d27365
Merge The Great Refactor fbacfe7937361c6d93c1354bc99290f390c61eaa (co…
cecton e1090da
Merge commit ec08d11d39fc439fabf85e3da9987ce2d0aafa03 (no conflict)
cecton ff2a80f
Merge commit 4820fa16b14513a58d25593487a90bc10a84efc2 (conflicts)
cecton 5cf0be0
Merge commit f511757069a12812e59d829184a54d46c2f983ba (no conflict)
cecton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| [workspace] | ||
| members = [ | ||
| "cli", | ||
| "client/consensus/common", | ||
| "client/consensus/relay-chain", | ||
| "client/network", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "cumulus-cli" | ||
| version = "0.1.0" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| 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" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // 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) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.