Update CLI (#53)

* Initial commit

Forked at: 4a3ffe07e7
Parent branch: master

* Update substrate: more CLI improvement

* Update substrate and polkadot to cecton-cumulus-branch

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* Update Cargo.lock

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* Update Cargo.lock

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* Test running node and interrupts

* WIP

Forked at: 4a3ffe07e7
Parent branch: master

* Update Cargo.lock

* Update test/parachain/tests/running_the_node_and_interrupt.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Cecile Tonglet
2020-02-10 12:39:32 +01:00
committed by GitHub
parent 4a3ffe07e7
commit de4ab321f4
14 changed files with 1758 additions and 1655 deletions
+28 -39
View File
@@ -17,12 +17,11 @@
use crate::chain_spec;
use crate::cli::{Cli, PolkadotCli, Subcommand};
use std::{path::PathBuf, sync::Arc};
use futures::{future::Map, FutureExt};
use std::sync::Arc;
use parachain_runtime::Block;
use sc_cli::{error::{self, Result}, VersionInfo};
use sc_cli::{error, VersionInfo};
use sc_client::genesis;
use sc_service::{Configuration, Roles as ServiceRoles};
use sp_core::hexdisplay::HexDisplay;
@@ -34,14 +33,17 @@ use polkadot_service::ChainSpec as ChainSpecPolkadot;
use codec::Encode;
use log::info;
use structopt::StructOpt;
const DEFAULT_POLKADOT_RPC_HTTP: &'static str = "127.0.0.1:9934";
const DEFAULT_POLKADOT_RPC_WS: &'static str = "127.0.0.1:9945";
const DEFAULT_POLKADOT_GRAFANA_PORT: &'static str = "127.0.0.1:9956";
/// Parse command line arguments into service configuration.
pub fn run(version: VersionInfo) -> error::Result<()> {
let opt: Cli = sc_cli::from_args(&version);
let mut config = sc_service::Configuration::default();
config.impl_name = "cumulus-test-parachain-collator";
let mut config = sc_service::Configuration::new(&version);
let mut polkadot_config = Configuration::new(&version);
match opt.subcommand {
Some(Subcommand::Base(subcommand)) => sc_cli::run_subcommand(
@@ -78,7 +80,13 @@ pub fn run(version: VersionInfo) -> error::Result<()> {
Ok(())
},
None => {
sc_cli::init(&mut config, load_spec, &opt.run.shared_params, &version)?;
sc_cli::init(&opt.run.shared_params, &version)?;
sc_cli::load_spec(&mut config, &opt.run.shared_params, load_spec)?;
sc_cli::update_config_for_running_node(
&mut config,
opt.run,
&version,
)?;
info!("{}", version.name);
info!(" version {}", config.full_version());
@@ -91,43 +99,24 @@ pub fn run(version: VersionInfo) -> error::Result<()> {
// TODO
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
let mut polkadot_config = Configuration::default();
polkadot_config.impl_name = "cumulus-test-parachain-collator";
polkadot_config.config_dir = config.in_chain_config_dir("polkadot");
// TODO: parse_address is private
/*
let rpc_interface: &str = interface_str(opt.run.rpc_external, opt.run.unsafe_rpc_external, opt.run.validator)?;
config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9934), opt.run.rpc_port)?);
let ws_interface: &str = interface_str(opt.run.ws_external, opt.run.unsafe_ws_external, opt.run.validator)?;
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9945), opt.run.ws_port)?);
let grafana_interface: &str = if opt.run.grafana_external { "0.0.0.0" } else { "127.0.0.1" };
config.grafana_port = Some(
parse_address(&format!("{}:{}", grafana_interface, 9956), opt.run.grafana_port)?
);
*/
let polkadot_opt: PolkadotCli = sc_cli::from_iter(opt.relaychain_args, &version);
// TODO
polkadot_config.chain_spec = Some(sc_cli::load_spec(&polkadot_opt.run.shared_params, load_spec_polkadot)?);
// TODO: base_path is private
//polkadot_config.config_dir = Some(sc_cli::base_path(&polkadot_opt.run.shared_params, &version));
polkadot_config.impl_commit = version.commit;
polkadot_config.impl_version = version.version;
polkadot_config.rpc_http = Some(DEFAULT_POLKADOT_RPC_HTTP.parse().unwrap());
polkadot_config.rpc_ws = Some(DEFAULT_POLKADOT_RPC_WS.parse().unwrap());
polkadot_config.grafana_port = Some(DEFAULT_POLKADOT_GRAFANA_PORT.parse().unwrap());
// TODO
if let Some(ref config_dir) = polkadot_config.config_dir {
polkadot_config.database = sc_service::config::DatabaseConfig::Path {
cache_size: Default::default(),
path: config_dir.join("db"),
};
}
// TODO
polkadot_config.network.boot_nodes = polkadot_config.network.boot_nodes.clone();
polkadot_config.telemetry_endpoints = polkadot_config.expect_chain_spec().telemetry_endpoints().clone();
sc_cli::update_config_for_running_node(&mut polkadot_config, polkadot_opt.run);
sc_cli::load_spec(
&mut polkadot_config,
&polkadot_opt.run.shared_params,
load_spec_polkadot,
)?;
sc_cli::update_config_for_running_node(
&mut polkadot_config,
polkadot_opt.run,
&version,
)?;
match config.roles {
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"),
-1
View File
@@ -19,7 +19,6 @@
#![warn(missing_docs)]
#![warn(unused_extern_crates)]
use itertools::Itertools;
use polkadot_primitives::parachain::Id as ParaId;
mod chain_spec;
+82 -29
View File
@@ -23,7 +23,13 @@ use sc_network::construct_simple_protocol;
use sc_service::{AbstractService, Configuration};
use sp_consensus::{BlockImport, Environment, Proposer};
use sp_inherents::InherentDataProviders;
use sc_cli;
use sp_core::crypto::Pair;
use polkadot_collator::build_collator_service;
use polkadot_primitives::parachain::CollatorPair;
use polkadot_service::IsKusama;
use cumulus_collator::CollatorBuilder;
use futures::{future, task::Spawn, FutureExt, TryFutureExt};
@@ -76,40 +82,87 @@ macro_rules! new_full_start {
}};
}
/// Run the collator with the given `config`.
/// Run a collator node with the given parachain `Configuration` and relaychain `Configuration`
///
/// This function blocks until done.
pub fn run_collator<E: sc_service::ChainSpecExtension>(
config: Configuration<GenesisConfig, E>,
key: Arc<polkadot_primitives::parachain::CollatorPair>,
mut parachain_config: Configuration<GenesisConfig, E>,
key: Arc<CollatorPair>,
polkadot_config: polkadot_collator::Configuration,
) -> Result<(), sc_cli::error::Error> {
let (builder, inherent_data_providers) = new_full_start!(config);
inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();
) -> sc_cli::error::Result<()> {
let para_id = crate::PARA_ID;
let service = builder
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.build()?;
let proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
if polkadot_config.expect_chain_spec().is_kusama() {
sc_cli::run_service_until_exit(polkadot_config, |polkadot_config| {
parachain_config.task_executor = polkadot_config.task_executor.clone();
let block_import = service.client();
let (builder, inherent_data_providers) = new_full_start!(parachain_config);
inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();
let setup_parachain = SetupParachain {
service,
inherent_data_providers,
proposer_factory,
block_import,
};
let service = builder
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.build()?;
let proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
cumulus_collator::run_collator(
setup_parachain,
crate::PARA_ID,
key,
polkadot_config,
)
let block_import = service.client();
let setup_parachain = SetupParachain {
service,
inherent_data_providers,
proposer_factory,
block_import,
};
let builder = CollatorBuilder::new(setup_parachain);
build_collator_service(
polkadot_service::kusama_new_full(polkadot_config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
builder,
)
})
} else {
sc_cli::run_service_until_exit(polkadot_config, |polkadot_config| {
parachain_config.task_executor = polkadot_config.task_executor.clone();
let (builder, inherent_data_providers) = new_full_start!(parachain_config);
inherent_data_providers
.register_provider(sp_timestamp::InherentDataProvider)
.unwrap();
let service = builder
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
.build()?;
let proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
let block_import = service.client();
let setup_parachain = SetupParachain {
service,
inherent_data_providers,
proposer_factory,
block_import,
};
let builder = CollatorBuilder::new(setup_parachain);
build_collator_service(
polkadot_service::polkadot_new_full(polkadot_config, Some((key.public(), para_id)), None, false, 6000)?,
para_id,
key,
builder,
)
})
}
}
struct SetupParachain<S, PF, BI> {