CLI API refactoring and improvement (#4692)

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 https://github.com/paritytech/cumulus/pull/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 https://github.com/paritytech/cumulus/issues/24 and https://github.com/paritytech/cumulus/issues/34 : it will now be possible to make a configuration struct for polkadot with some overrides of the default parameters much more easily.
This commit is contained in:
Cecile Tonglet
2020-01-30 11:40:08 +01:00
committed by GitHub
parent 506f9c29d9
commit 605f643eed
28 changed files with 2041 additions and 2234 deletions
+22 -23
View File
@@ -133,11 +133,11 @@ fn node_config<G, E: Clone> (
index: usize,
spec: &ChainSpec<G, E>,
role: Roles,
tasks_executor: Box<dyn Fn(Pin<Box<dyn futures::Future<Output = ()> + Send>>) + Send>,
task_executor: Box<dyn Fn(Pin<Box<dyn futures::Future<Output = ()> + Send>>) + Send>,
key_seed: Option<String>,
base_port: u16,
root: &TempDir,
) -> Configuration<(), G, E>
) -> Configuration<G, E>
{
let root = root.path().join(format!("node-{}", index));
@@ -175,7 +175,7 @@ fn node_config<G, E: Clone> (
impl_version: "0.1",
impl_commit: "",
roles: role,
tasks_executor: Some(tasks_executor),
task_executor: Some(task_executor),
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path {
@@ -190,8 +190,7 @@ fn node_config<G, E: Clone> (
state_cache_size: 16777216,
state_cache_child_ratio: None,
pruning: Default::default(),
chain_spec: (*spec).clone(),
custom: Default::default(),
chain_spec: Some((*spec).clone()),
name: format!("Node {}", index),
wasm_method: sc_service::config::WasmExecutionMethod::Interpreted,
execution_strategies: Default::default(),
@@ -221,11 +220,11 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
fn new(
temp: &TempDir,
spec: ChainSpec<G, E>,
full: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>>,
light: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<L, Error>>,
full: impl Iterator<Item = impl FnOnce(Configuration<G, E>) -> Result<(F, U), Error>>,
light: impl Iterator<Item = impl FnOnce(Configuration<G, E>) -> Result<L, Error>>,
authorities: impl Iterator<Item = (
String,
impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>
impl FnOnce(Configuration<G, E>) -> Result<(F, U), Error>
)>,
base_port: u16
) -> TestNet<G, E, F, L, U> {
@@ -248,14 +247,14 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
fn insert_nodes(
&mut self,
temp: &TempDir,
full: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>>,
light: impl Iterator<Item = impl FnOnce(Configuration<(), G, E>) -> Result<L, Error>>,
authorities: impl Iterator<Item = (String, impl FnOnce(Configuration<(), G, E>) -> Result<(F, U), Error>)>
full: impl Iterator<Item = impl FnOnce(Configuration<G, E>) -> Result<(F, U), Error>>,
light: impl Iterator<Item = impl FnOnce(Configuration<G, E>) -> Result<L, Error>>,
authorities: impl Iterator<Item = (String, impl FnOnce(Configuration<G, E>) -> Result<(F, U), Error>)>
) {
let executor = self.runtime.executor();
for (key, authority) in authorities {
let tasks_executor = {
let task_executor = {
let executor = executor.clone();
Box::new(move |fut: Pin<Box<dyn futures::Future<Output = ()> + Send>>| executor.spawn(fut.unit_error().compat()))
};
@@ -263,7 +262,7 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
self.nodes,
&self.chain_spec,
Roles::AUTHORITY,
tasks_executor,
task_executor,
Some(key),
self.base_port,
&temp,
@@ -279,11 +278,11 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
}
for full in full {
let tasks_executor = {
let task_executor = {
let executor = executor.clone();
Box::new(move |fut: Pin<Box<dyn futures::Future<Output = ()> + Send>>| executor.spawn(fut.unit_error().compat()))
};
let node_config = node_config(self.nodes, &self.chain_spec, Roles::FULL, tasks_executor, None, self.base_port, &temp);
let node_config = node_config(self.nodes, &self.chain_spec, Roles::FULL, task_executor, None, self.base_port, &temp);
let addr = node_config.network.listen_addresses.iter().next().unwrap().clone();
let (service, user_data) = full(node_config).expect("Error creating test node service");
let service = SyncService::from(service);
@@ -295,11 +294,11 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where
}
for light in light {
let tasks_executor = {
let task_executor = {
let executor = executor.clone();
Box::new(move |fut: Pin<Box<dyn futures::Future<Output = ()> + Send>>| executor.spawn(fut.unit_error().compat()))
};
let node_config = node_config(self.nodes, &self.chain_spec, Roles::LIGHT, tasks_executor, None, self.base_port, &temp);
let node_config = node_config(self.nodes, &self.chain_spec, Roles::LIGHT, task_executor, None, self.base_port, &temp);
let addr = node_config.network.listen_addresses.iter().next().unwrap().clone();
let service = SyncService::from(light(node_config).expect("Error creating test node service"));
@@ -321,9 +320,9 @@ pub fn connectivity<G, E, Fb, F, Lb, L>(
light_builder: Lb,
) where
E: Clone,
Fb: Fn(Configuration<(), G, E>) -> Result<F, Error>,
Fb: Fn(Configuration<G, E>) -> Result<F, Error>,
F: AbstractService,
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
Lb: Fn(Configuration<G, E>) -> Result<L, Error>,
L: AbstractService,
{
const NUM_FULL_NODES: usize = 5;
@@ -420,9 +419,9 @@ pub fn sync<G, E, Fb, F, Lb, L, B, ExF, U>(
mut make_block_and_import: B,
mut extrinsic_factory: ExF
) where
Fb: Fn(Configuration<(), G, E>) -> Result<(F, U), Error>,
Fb: Fn(Configuration<G, E>) -> Result<(F, U), Error>,
F: AbstractService,
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
Lb: Fn(Configuration<G, E>) -> Result<L, Error>,
L: AbstractService,
B: FnMut(&F, &mut U),
ExF: FnMut(&F, &U) -> <F::Block as BlockT>::Extrinsic,
@@ -489,9 +488,9 @@ pub fn consensus<G, E, Fb, F, Lb, L>(
light_builder: Lb,
authorities: impl IntoIterator<Item = String>
) where
Fb: Fn(Configuration<(), G, E>) -> Result<F, Error>,
Fb: Fn(Configuration<G, E>) -> Result<F, Error>,
F: AbstractService,
Lb: Fn(Configuration<(), G, E>) -> Result<L, Error>,
Lb: Fn(Configuration<G, E>) -> Result<L, Error>,
L: AbstractService,
E: Clone,
{