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

Getting configuration from commands #4643

Merged
merged 10 commits into from
Jan 16, 2020

Conversation

cecton
Copy link
Contributor

@cecton cecton commented Jan 16, 2020

This PR adds a public function .into_configuration() on ParseAndPrepare that generates a Configuration.

The use case is for cumulus and other projects that would want to parse multiple command line arguments separately in order to start multiple nodes.

Related paritytech/cumulus#34

Note: there is also a new extra argument default_base_path that allows the caller to define the config_dir before the Configuration gets created. This default_base_path can be overwritten by the argument --base-path (as proved in the test I added).

@cecton cecton added the J0-enhancement An additional feature request. label Jan 16, 2020
@cecton cecton self-assigned this Jan 16, 2020
@parity-cla-bot
Copy link

It looks like @cecton signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks ok, but I wonder if having a builder pattern here wouldn't make things simpler. Right now it seems we make it simpler by introducing yet another method (into_configuration). Do all other functions need to be public then?

All these create_config_with_* and fill_* functions are quite confusing to me. Without looking at the code I really have no idea which one should I use for my sub-command.

@@ -1003,7 +1118,7 @@ where
S: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
{
let spec = load_spec(cli, spec_factory)?;
let base_path = base_path(cli, version);
let base_path = base_path(cli, version, default_base_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could delegate to create_build_spec_config to avoid duplication

@@ -295,6 +300,78 @@ impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> where CC: GetSharedParams {
}
}

impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> {
/// Convert ParseAndPrepare to Configuration
pub fn into_configuration<C, G, E, S>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should existing node/cli and node-template/cli be using that function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(answered on #4643 (comment) )

@cecton
Copy link
Contributor Author

cecton commented Jan 16, 2020

Looks ok, but I wonder if having a builder pattern here wouldn't make things simpler. Right now it seems we make it simpler by introducing yet another method (into_configuration). Do all other functions need to be public then?

All these create_config_with_* and fill_* functions are quite confusing to me. Without looking at the code I really have no idea which one should I use for my sub-command.

I don't think create_config_with_* and fill_* should be public anymore (@bkchr correct me if I'm wrong). There should be only 2 ways that should make sense and serve different purposes:

  1. using the parse_and_prepare()
  2. using the into_configuration()

The 1. is normally used for the 1st node as it also sets up the logger of the app. While the 2. can be used for extra nodes.

Should existing node/cli and node-template/cli be using that function?

I think no. Otherwise it would skip the logger setup (and the panic handler and some other things).

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks good then, would be even better to figure out if we can unpublish the low-level functions (I guess it will require a corresponding PR for polkadot).

@cecton
Copy link
Contributor Author

cecton commented Jan 16, 2020

@tomusdrw I'm not sure if it's used in polkadot actually. I just grepped the code and I couldn't find anything. Are you sure?

@gavofyork gavofyork added A8-looksgood and removed J0-enhancement An additional feature request. labels Jan 16, 2020
@gavofyork gavofyork merged commit 3fa5f09 into master Jan 16, 2020
@gavofyork gavofyork deleted the cecton-getting-configuration-from-cmd branch January 16, 2020 12:57
@tomusdrw
Copy link
Contributor

@cecton nope, just assumed it is. If it's not then even better :)

cecton added a commit that referenced this pull request Jan 27, 2020
* Expose a method that allows converting RunCmd to Configuration

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP
cecton added a commit that referenced this pull request Jan 30, 2020
It changes the way we extended the CLI functionalities of substrate to allow more flexibility. (If this was not clear, here is another version: it changes the `sc_cli` API to allow more flexibility).

This touches a few important things:
 - the startup of the async task with tokei:
    This was in node and node-template and I moved it to substrate. The idea is to have 1 time the code that handles unix signals (SIGTERM and SIGINT) properly. It is however possible to make this more generic to wait for a future instead and provide only a helper for the basic handling of SIGTERM and SIGINT.
 - increased the version of structopt and tokei
 - no more use of structopt internal's API
 - less use of generics

Related to #4643 and paritytech/cumulus#42: the implementation of "into_configuration" and "get_config" are similar but with better flexibility so it is now possible in cumulus to have the command-line arguments only of the run command for polkadot if we want

Related to paritytech/cumulus#24 and paritytech/cumulus#34 : it will now be possible to make a configuration struct for polkadot with some overrides of the default parameters much more easily.
cecton added a commit that referenced this pull request Jan 31, 2020
* Expose a method that allows converting RunCmd to Configuration

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP
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.

4 participants