Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a command to purge the relay chain only #306

Merged
merged 20 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions rococo-parachains/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use std::path::PathBuf;

use crate::chain_spec;
use sc_cli;
use std::path::PathBuf;
use structopt::StructOpt;

/// Sub-commands supported by the collator.
Expand Down Expand Up @@ -48,6 +48,9 @@ pub enum Subcommand {
/// Remove the whole chain.
PurgeChain(sc_cli::PurgeChainCmd),

/// Remove only the relay chain.
PurgeRelayChain(sc_cli::PurgeChainCmd),

/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),
}
Expand Down Expand Up @@ -143,12 +146,14 @@ pub struct RelayChainCli {
}

impl RelayChainCli {
/// Create a new instance of `Self`.
/// Parse the relay chain CLI parameters using the para chain `Configuration`.
pub fn new<'a>(
base_path: Option<PathBuf>,
chain_id: Option<String>,
para_config: &sc_service::Configuration,
relay_chain_args: impl Iterator<Item = &'a String>,
) -> Self {
let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot"));
Self {
base_path,
chain_id,
Expand Down
29 changes: 24 additions & 5 deletions rococo-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.database))
}
Some(Subcommand::PurgeRelayChain(cmd)) => {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| {
let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name().to_string()]
.iter()
.chain(cli.relaychain_args.iter()),
);

let polkadot_config = SubstrateCli::create_configuration(
&polkadot_cli,
&polkadot_cli,
config.task_executor.clone(),
None,
).map_err(|err| format!("Relay chain argument error: {}", err))?;
cecton marked this conversation as resolved.
Show resolved Hide resolved

cmd.run(polkadot_config.database)
})
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
Expand Down Expand Up @@ -268,13 +289,11 @@ pub fn run() -> Result<()> {
// TODO
let key = sp_core::Pair::generate().0;

let extension = chain_spec::Extensions::try_get(&*config.chain_spec);
let relay_chain_id = extension.map(|e| e.relay_chain.clone());
let para_id = extension.map(|e| e.para_id);
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id);

let polkadot_cli = RelayChainCli::new(
config.base_path.as_ref().map(|x| x.path().join("polkadot")),
relay_chain_id,
&config,
[RelayChainCli::executable_name().to_string()]
.iter()
.chain(cli.relaychain_args.iter()),
Expand Down