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

Conversation

cecton
Copy link
Contributor

@cecton cecton commented Jan 22, 2021

Fixes #259

@cecton
Copy link
Contributor Author

cecton commented Jan 22, 2021

Tested and working:

[0] [07:55:34] ~/r/cumulus cecton-purge-relay > ./target/release/rococo-collator purge-chain --base-path /tmp/rococo
Are you sure to remove "/tmp/rococo/chains/local_testnet/db"? [y/N]: y
"/tmp/rococo/chains/local_testnet/db" removed.
[0] [07:55:43] ~/r/cumulus cecton-purge-relay > ./target/release/rococo-collator purge-relay-chain --base-path /tmp/rococo
Are you sure to remove "/tmp/rococo/polkadot/chains/westend_dev/db"? [y/N]: y
"/tmp/rococo/polkadot/chains/westend_dev/db" removed.

@bkchr
Copy link
Member

bkchr commented Jan 22, 2021

Commented on the issue

@cecton cecton marked this pull request as draft January 22, 2021 09:48
@cecton cecton marked this pull request as ready for review January 22, 2021 11:40
@cecton
Copy link
Contributor Author

cecton commented Jan 22, 2021

[0] [11:29:44] ~/r/cumulus cecton-purge-relay > ./target/debug/rococo-collator purge-chain --parachain
/home/cecile/.local/share/rococo-collator/chains/local_testnet/db
Are you sure to remove? [y/N]: ^C⏎
[130] [11:36:24] ~/r/cumulus cecton-purge-relay > ./target/debug/rococo-collator purge-chain
/home/cecile/.local/share/rococo-collator/chains/local_testnet/db
/home/cecile/.local/share/rococo-collator/polkadot/chains/westend_dev/db
Are you sure to remove? [y/N]: ^C⏎
[130] [11:36:30] ~/r/cumulus cecton-purge-relay > ./target/debug/rococo-collator purge-chain --relay
/home/cecile/.local/share/rococo-collator/polkadot/chains/westend_dev/db
Are you sure to remove? [y/N]: ^C⏎
[130] [11:36:34] ~/r/cumulus cecton-purge-relay > ./target/debug/rococo-collator purge-chain --relay --para
/home/cecile/.local/share/rococo-collator/chains/local_testnet/db
/home/cecile/.local/share/rococo-collator/polkadot/chains/westend_dev/db
Are you sure to remove? [y/N]: y
"/home/cecile/.local/share/rococo-collator/chains/local_testnet/db" did not exist.
"/home/cecile/.local/share/rococo-collator/polkadot/chains/westend_dev/db" did not exist.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move and also please write some tests for the command on its own.

rococo-parachains/src/command.rs Outdated Show resolved Hide resolved
rococo-parachains/src/cli.rs Outdated Show resolved Hide resolved
rococo-parachains/src/cli.rs Outdated Show resolved Hide resolved
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and please don't forget the tests 🙈 )

cli/src/lib.rs Show resolved Hide resolved
@cecton
Copy link
Contributor Author

cecton commented Jan 22, 2021

(and please don't forget the tests see_no_evil )

I'm on it. You're too fast

@bkchr
Copy link
Member

bkchr commented Jan 22, 2021

(and please don't forget the tests see_no_evil )

I'm on it. You're too fast

Sorry :P

@cecton
Copy link
Contributor Author

cecton commented Jan 22, 2021

There is an issue with the --dev flag. There is one for the para chain, one for the relay chain. For some reasons (limitation in structopt or maybe clap) I have problems to retrieve the parameters after -- for the purge-chain subcommand... and that is a big problem to solve.

The other problem with this is that it is also impacting the --chain. The only way I see right now would be to add parameters --relay-dev and --relay-chain to the cumulus purge-chain command.

Meanwhile I have a few questions:

  • Are we sure we need to support polkadot args in the purge-chain command?
  • Do I need to use the --dev flag at all in the tests? Before it was required to avoid connecting the outside world I think but now when I look at the example in the README and we don't use --dev at all anywhere.

One other (very far fetched) alternative would be to give a big thought about moving away from structopt and changing completely sc-cli's API to use clap directly. It's less declarative but this is actually a good thing in term of flexibility. We might be able to achieve more with less complexity.

@bkchr
Copy link
Member

bkchr commented Jan 25, 2021

There is an issue with the --dev flag. There is one for the para chain, one for the relay chain. For some reasons (limitation in structopt or maybe clap) I have problems to retrieve the parameters after -- for the purge-chain subcommand... and that is a big problem to solve.

The other problem with this is that it is also impacting the --chain. The only way I see right now would be to add parameters --relay-dev and --relay-chain to the cumulus purge-chain command.

--dev is just a shortcut for --chain something. So, IMHO we could omit this here because it doesn't make any sense.

Meanwhile I have a few questions:

* Are we sure we need to support polkadot args in the purge-chain command?

* Do I need to use the `--dev` flag at all in the tests? Before it was required to avoid connecting the outside world I think but now when I look at the example in the README and we don't use --dev at all anywhere.

You should make yourself familiar what this command is doing. From the perspective of cumulus the --dev never worked, but we could probably make it work. As explained above, the --dev is just a shortcut for --chain bla and you can use that in your tests.

One other (very far fetched) alternative would be to give a big thought about moving away from structopt and changing completely sc-cli's API to use clap directly. It's less declarative but this is actually a good thing in term of flexibility. We might be able to achieve more with less complexity.

We used clap before and it was horrible :P Yeah, it is more flexible, but you also loose all your shit when you try to modify something or to add a new parameter. So, no switch.

@cecton cecton marked this pull request as draft January 29, 2021 09:05
@cecton
Copy link
Contributor Author

cecton commented Jan 29, 2021

As explained above, the --dev is just a shortcut for --chain bla and you can use that in your tests.

I know that very well but my problem is still there. I will try to explain better:

When you run cumulus you can give a --chain to the relay chain and another one to the para chain. It works because of how things are parse in the command line.

Unfortunately, because of limitations with structopt, I can't parse the arguments after -- when using the purge command. Because of that, the test fails because the process is first started with one chain (dev) but the purge command (ran later on during the test) is using another chain (westend-dev).

What I can do to circumvent this issue:

  1. Add a new parameter --relay-chain to the purge command
  2. Store the chain name in a file in the base path of the para chain (so it can locate the directory)

(I'm mostly using the parameter --dev in the test to avoid the nodes to connect to anything.)

@cecton
Copy link
Contributor Author

cecton commented Jan 29, 2021

Add a new parameter --relay-chain to the purge command

Wait, there is already a parameter --relay-chain. I meant a parameter --relay-chain-chain <chain-file> (probably with a better name lol)

@cecton
Copy link
Contributor Author

cecton commented Jan 29, 2021

Wait, there is already a parameter --relay-chain. I meant a parameter --relay-chain-chain <chain-file> (probably with a better name lol)

Or maybe just make --relaychain takes an optional path argument to the chain file

@cecton cecton marked this pull request as ready for review January 29, 2021 11:58
@cecton
Copy link
Contributor Author

cecton commented Jan 29, 2021

Ok I get it, the relay chain is actually found from the parachain's extension. So I just fixed the test. @bkchr this is ready for review then

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. Some last nitpicks, otherwise looks good.

cli/src/lib.rs Outdated Show resolved Hide resolved
cli/src/lib.rs Outdated Show resolved Hide resolved
cli/src/lib.rs Outdated
.iter()
.map(|x| {
x.path().ok_or_else(|| {
sc_cli::Error::Input("Cannot purge custom database implementation".into())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a hint which on this is, would be nice :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 670b674

cli/src/lib.rs Outdated Show resolved Hide resolved
@@ -15,50 +15,63 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, fs, path::PathBuf, process::Command, thread, time::Duration};
use std::{convert::TryInto, process::Command, thread, time::Duration};

mod common;

#[test]
#[cfg(unix)]
fn purge_chain_works() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be really nice to have these tests part of the /tests/ "parachain". But this can be done in a later pr.


let base_path = "purge_chain_test";
let base_path = tempfile::tempdir().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cecton I'm curious why you did this after you already gave us the --tmp flag in paritytech/substrate#6221

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I get it. So you can check the directory later on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subcommand to purge embedded relay chain
3 participants