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

Conversation

@cecton
Copy link
Contributor

@cecton cecton commented Jun 2, 2020

Companion PR: paritytech/polkadot#1213

Following up of this idea:

🤔 I wonder if it would be useful to add a commandline parameter "--tmp" that would create a random temporary directory for the base path automatically for you so you can copy-paste the same command 3 times if you want to run 3 nodes; and when the node exits, it would delete that temporary directory automatically.

So for a demo you dont need to give the --base-path if you need to run multiple nodes and you don't need to purge at all

Some people liked it

cc @JoshOrndorff @apopiak

Note: there were many Clone on the structopt. I think it was used in the original implementation before I refactored sc-cli but it is not needed anymore so I removed them.

@cecton cecton added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jun 2, 2020
@cecton cecton self-assigned this Jun 2, 2020
@parity-cla-bot
Copy link

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

Many thanks,

Parity Technologies CLA Bot

@cecton cecton changed the title Add a feature to create automatically a random temporary directory for base path Add a feature to create automatically a random temporary directory for base path & remove Clone Jun 3, 2020
@cecton cecton marked this pull request as ready for review June 3, 2020 07:44
pub tmp: bool,

#[structopt(skip)]
temp_base_path: RefCell<Option<TempDir>>,
Copy link
Member

Choose a reason for hiding this comment

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

Nope. This is a really bad hack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What part you don't like exactly? (so I can find another way)

Copy link
Member

Choose a reason for hiding this comment

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

Not having the temp base path as parameter here.

We could create some custom type that we return in base_path

Copy link
Contributor Author

@cecton cecton Jun 4, 2020

Choose a reason for hiding this comment

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

Ok done! Now the TempDir is hold in the configuration object instead of the SubstrateCli object, then it's move to the service and dropped with it. Also the core of the feature itself has moved from sc-cli to sc-service.


/// Run a temporary node.
///
/// A random temporary directory will be created to store the configuration and will be deleted
Copy link
Member

Choose a reason for hiding this comment

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

"random temporary" => "temporary"

Please also make the user aware that this is the "base-path" and what will be part of this path. Database, node key etc.

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 55ed555

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.

Already looks much better, the only problem is now that run_service_until_exit will drop the base path before everything has stopped. This could lead to errors on stopping the node.

}

fn base_path(&self) -> $crate::Result<::std::option::Option<::std::path::PathBuf>> {
fn base_path(&self) -> $crate::Result<::std::option::Option<::sc_service::config::BasePath>> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn base_path(&self) -> $crate::Result<::std::option::Option<::sc_service::config::BasePath>> {
fn base_path(&self) -> $crate::Result<::std::option::Option<sc_service::config::BasePath>> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think these are all wrong. sc-cli should probably make a hidden re-export of sc_service and the macro should get it from there.

Copy link
Member

Choose a reason for hiding this comment

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

Yes that is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make another PR for that for the sake of having isolated commits per change

keystore: sc_keystore::KeyStorePtr,
marker: PhantomData<TBl>,
prometheus_registry: Option<prometheus_endpoint::Registry>,
_base_path: Option<BasePath>,
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment why we need this here.

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

))
}

/// Create a base path based on an existing path on disk.
Copy link
Member

Choose a reason for hiding this comment

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

I think we create it if it does not exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not explicitly. We create only the network_config_dir which is a subdirectory. We could explicitly create the directories. Though this doc sentence actually meant "create a BasePath struct".

Copy link
Member

Choose a reason for hiding this comment

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

Than please write it. I did not understand it like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right. Done in cb140b6

cecton and others added 5 commits June 5, 2020 05:51
Co-authored-by: Bastian Köcher <[email protected]>
Forked at: 342caad
Parent branch: origin/master
@cecton
Copy link
Contributor Author

cecton commented Jun 5, 2020

the only problem is now that run_service_until_exit will drop the base path before everything has stopped. This could lead to errors on stopping the node.

Fair point! 😓

Already looks much better

To be honest I kinda disagree. When I see that more things need to be handled in this run_service_until_exit I feel like we are doing something wrong. We should be removing things from there, not adding.

I wonder if we should remove the Future impl of Service and replace it with a function that takes &self so things in the service will not be dropped prematurely because we are awaiting for the completion of the service.

@bkchr
Copy link
Member

bkchr commented Jun 5, 2020

Yeah, the situation with dropping the service is shit. That is right ;)

cecton added 4 commits June 8, 2020 09:28
Parent branch: origin/master
Forked at: 342caad
Parent branch: origin/master
Forked at: 342caad
Parent branch: origin/master
Forked at: 342caad
@bkchr bkchr merged commit a684e83 into master Jun 10, 2020
@bkchr bkchr deleted the cecton-tmp-base-path branch June 10, 2020 11:13
@bkchr bkchr added B0-silent Changes should not be mentioned in any release notes B1-clientnoteworthy labels Jun 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants