mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 22:01:04 +00:00
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:
@@ -23,13 +23,13 @@ pub use sc_executor::WasmExecutionMethod;
|
||||
|
||||
use std::{future::Future, path::{PathBuf, Path}, pin::Pin, net::SocketAddr, sync::Arc};
|
||||
pub use sc_transaction_pool::txpool::Options as TransactionPoolOptions;
|
||||
use sc_chain_spec::{ChainSpec, RuntimeGenesis, Extension, NoExtension};
|
||||
use sc_chain_spec::{ChainSpec, NoExtension};
|
||||
use sp_core::crypto::Protected;
|
||||
use target_info::Target;
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
|
||||
/// Service configuration.
|
||||
pub struct Configuration<C, G, E = NoExtension> {
|
||||
pub struct Configuration<G, E = NoExtension> {
|
||||
/// Implementation name
|
||||
pub impl_name: &'static str,
|
||||
/// Implementation version
|
||||
@@ -39,7 +39,7 @@ pub struct Configuration<C, G, E = NoExtension> {
|
||||
/// Node roles.
|
||||
pub roles: Roles,
|
||||
/// How to spawn background tasks. Mandatory, otherwise creating a `Service` will error.
|
||||
pub tasks_executor: Option<Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send>>,
|
||||
pub task_executor: Option<Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send>>,
|
||||
/// Extrinsic pool configuration.
|
||||
pub transaction_pool: TransactionPoolOptions,
|
||||
/// Network configuration.
|
||||
@@ -57,9 +57,7 @@ pub struct Configuration<C, G, E = NoExtension> {
|
||||
/// Pruning settings.
|
||||
pub pruning: PruningMode,
|
||||
/// Chain configuration.
|
||||
pub chain_spec: ChainSpec<G, E>,
|
||||
/// Custom configuration.
|
||||
pub custom: C,
|
||||
pub chain_spec: Option<ChainSpec<G, E>>,
|
||||
/// Node name.
|
||||
pub name: String,
|
||||
/// Wasm execution method.
|
||||
@@ -146,22 +144,18 @@ pub enum DatabaseConfig {
|
||||
Custom(Arc<dyn KeyValueDB>),
|
||||
}
|
||||
|
||||
impl<C, G, E> Configuration<C, G, E> where
|
||||
C: Default,
|
||||
G: RuntimeGenesis,
|
||||
E: Extension,
|
||||
{
|
||||
/// Create a default config for given chain spec and path to configuration dir
|
||||
pub fn default_with_spec_and_base_path(chain_spec: ChainSpec<G, E>, config_dir: Option<PathBuf>) -> Self {
|
||||
let mut configuration = Configuration {
|
||||
impl<G, E> Default for Configuration<G, E> {
|
||||
/// Create a default config
|
||||
fn default() -> Self {
|
||||
let configuration = Configuration {
|
||||
impl_name: "parity-substrate",
|
||||
impl_version: "0.0.0",
|
||||
impl_commit: "",
|
||||
chain_spec,
|
||||
config_dir: config_dir.clone(),
|
||||
chain_spec: None,
|
||||
config_dir: None,
|
||||
name: Default::default(),
|
||||
roles: Roles::FULL,
|
||||
tasks_executor: None,
|
||||
task_executor: None,
|
||||
transaction_pool: Default::default(),
|
||||
network: Default::default(),
|
||||
keystore: KeystoreConfig::None,
|
||||
@@ -171,7 +165,6 @@ impl<C, G, E> Configuration<C, G, E> where
|
||||
},
|
||||
state_cache_size: Default::default(),
|
||||
state_cache_child_ratio: Default::default(),
|
||||
custom: Default::default(),
|
||||
pruning: PruningMode::default(),
|
||||
wasm_method: WasmExecutionMethod::Interpreted,
|
||||
execution_strategies: Default::default(),
|
||||
@@ -191,16 +184,13 @@ impl<C, G, E> Configuration<C, G, E> where
|
||||
tracing_targets: Default::default(),
|
||||
tracing_receiver: Default::default(),
|
||||
};
|
||||
configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec();
|
||||
|
||||
configuration.telemetry_endpoints = configuration.chain_spec.telemetry_endpoints().clone();
|
||||
|
||||
configuration
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<C, G, E> Configuration<C, G, E> {
|
||||
impl<G, E> Configuration<G, E> {
|
||||
/// Returns full version string of this configuration.
|
||||
pub fn full_version(&self) -> String {
|
||||
full_version_from_strs(self.impl_version, self.impl_commit)
|
||||
@@ -216,11 +206,20 @@ impl<C, G, E> Configuration<C, G, E> {
|
||||
pub fn in_chain_config_dir(&self, sub: &str) -> Option<PathBuf> {
|
||||
self.config_dir.clone().map(|mut path| {
|
||||
path.push("chains");
|
||||
path.push(self.chain_spec.id());
|
||||
path.push(self.expect_chain_spec().id());
|
||||
path.push(sub);
|
||||
path
|
||||
})
|
||||
}
|
||||
|
||||
/// Return a reference to the `ChainSpec` of this `Configuration`.
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// This method panic if the `chain_spec` is `None`
|
||||
pub fn expect_chain_spec(&self) -> &ChainSpec<G, E> {
|
||||
self.chain_spec.as_ref().expect("chain_spec must be specified")
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns platform info
|
||||
|
||||
Reference in New Issue
Block a user