mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 11:41:04 +00:00
CLI improvements & fixes (#4812)
These are a few changes I missed during the refactoring.
1. Initialization issue and boilerplate
Most importantly: part of the `Configuration` initialization was done in `sc_cli::init`. This means the user can not benefit from this initialization boilerplate if they have multiple `Configuration` since `sc_cli::init` can only be called once.
2. Boilerplate for `VersionInfo` and `Configuration`
I'm also answering to the critic of @bkchr on the initialization using version: https://github.com/paritytech/substrate/pull/4692/files/bea809d4c14a2ede953227ac885e3b3f9771c548#r372047238 This will allow initializing a `Configuration` and provide the version by default.
3. Loading the `chain_spec` explicitly
In the past it was done automatically but in some cases we want to delay this. I moved the code to `Configuration.load_spec()` so it can be called later on. `chain_spec` can also be written directly to the `Configuration` without using this `load_spec` helper.
4. [deleted]
5. Fixing issue that prevents the user to override the port
In the refactoring I introduced a bug by mistake that could potentially prevent the CLI user to override the ports if defaults where provided for these ports (only on cumulus).
6. Change task_executor from Box to Arc
This is useful for cumulus where we have 2 nodes with 2 separate Configuration that need to spawn tasks to the same runtime.
7. Renamed TasksExecutorRequired to TaskExecutor
For consistency.
This is related to https://github.com/paritytech/cumulus/issues/24
This is the continuation (and hopefully the end of) #4692
This commit is contained in:
@@ -196,7 +196,7 @@ fn new_full_parts<TBl, TRtApi, TExecDisp, TGen, TCSExt>(
|
||||
state_cache_child_ratio:
|
||||
config.state_cache_child_ratio.map(|v| (v, 100)),
|
||||
pruning: config.pruning.clone(),
|
||||
source: match &config.database {
|
||||
source: match config.expect_database() {
|
||||
DatabaseConfig::Path { path, cache_size } =>
|
||||
sc_client_db::DatabaseSettingsSrc::Path {
|
||||
path: path.clone(),
|
||||
@@ -307,7 +307,7 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
|
||||
state_cache_child_ratio:
|
||||
config.state_cache_child_ratio.map(|v| (v, 100)),
|
||||
pruning: config.pruning.clone(),
|
||||
source: match &config.database {
|
||||
source: match config.expect_database() {
|
||||
DatabaseConfig::Path { path, cache_size } =>
|
||||
sc_client_db::DatabaseSettingsSrc::Path {
|
||||
path: path.clone(),
|
||||
@@ -1187,7 +1187,7 @@ ServiceBuilder<
|
||||
task_executor: if let Some(exec) = config.task_executor {
|
||||
exec
|
||||
} else {
|
||||
return Err(Error::TasksExecutorRequired);
|
||||
return Err(Error::TaskExecutorRequired);
|
||||
},
|
||||
rpc_handlers,
|
||||
_rpc: rpc,
|
||||
|
||||
@@ -28,6 +28,27 @@ use sp_core::crypto::Protected;
|
||||
use target_info::Target;
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
|
||||
/// Executable version. Used to pass version information from the root crate.
|
||||
#[derive(Clone)]
|
||||
pub struct VersionInfo {
|
||||
/// Implementation name.
|
||||
pub name: &'static str,
|
||||
/// Implementation version.
|
||||
pub version: &'static str,
|
||||
/// SCM Commit hash.
|
||||
pub commit: &'static str,
|
||||
/// Executable file name.
|
||||
pub executable_name: &'static str,
|
||||
/// Executable file description.
|
||||
pub description: &'static str,
|
||||
/// Executable file author.
|
||||
pub author: &'static str,
|
||||
/// Support URL.
|
||||
pub support_url: &'static str,
|
||||
/// Copyright starting year (x-current year)
|
||||
pub copyright_start_year: i32,
|
||||
}
|
||||
|
||||
/// Service configuration.
|
||||
pub struct Configuration<G, E = NoExtension> {
|
||||
/// Implementation name
|
||||
@@ -39,7 +60,7 @@ pub struct Configuration<G, E = NoExtension> {
|
||||
/// Node roles.
|
||||
pub roles: Roles,
|
||||
/// How to spawn background tasks. Mandatory, otherwise creating a `Service` will error.
|
||||
pub task_executor: Option<Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send>>,
|
||||
pub task_executor: Option<Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>>,
|
||||
/// Extrinsic pool configuration.
|
||||
pub transaction_pool: TransactionPoolOptions,
|
||||
/// Network configuration.
|
||||
@@ -49,7 +70,7 @@ pub struct Configuration<G, E = NoExtension> {
|
||||
/// Configuration for the keystore.
|
||||
pub keystore: KeystoreConfig,
|
||||
/// Configuration for the database.
|
||||
pub database: DatabaseConfig,
|
||||
pub database: Option<DatabaseConfig>,
|
||||
/// Size of internal state cache in Bytes
|
||||
pub state_cache_size: usize,
|
||||
/// Size in percent of cache size dedicated to child tries
|
||||
@@ -147,7 +168,7 @@ pub enum DatabaseConfig {
|
||||
impl<G, E> Default for Configuration<G, E> {
|
||||
/// Create a default config
|
||||
fn default() -> Self {
|
||||
let configuration = Configuration {
|
||||
Configuration {
|
||||
impl_name: "parity-substrate",
|
||||
impl_version: "0.0.0",
|
||||
impl_commit: "",
|
||||
@@ -159,10 +180,7 @@ impl<G, E> Default for Configuration<G, E> {
|
||||
transaction_pool: Default::default(),
|
||||
network: Default::default(),
|
||||
keystore: KeystoreConfig::None,
|
||||
database: DatabaseConfig::Path {
|
||||
path: Default::default(),
|
||||
cache_size: Default::default(),
|
||||
},
|
||||
database: None,
|
||||
state_cache_size: Default::default(),
|
||||
state_cache_child_ratio: Default::default(),
|
||||
pruning: PruningMode::default(),
|
||||
@@ -183,14 +201,21 @@ impl<G, E> Default for Configuration<G, E> {
|
||||
dev_key_seed: None,
|
||||
tracing_targets: Default::default(),
|
||||
tracing_receiver: Default::default(),
|
||||
};
|
||||
|
||||
configuration
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<G, E> Configuration<G, E> {
|
||||
/// Create a default config using `VersionInfo`
|
||||
pub fn new(version: &VersionInfo) -> Self {
|
||||
let mut config = Configuration::default();
|
||||
config.impl_name = version.name;
|
||||
config.impl_version = version.version;
|
||||
config.impl_commit = version.commit;
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
/// Returns full version string of this configuration.
|
||||
pub fn full_version(&self) -> String {
|
||||
full_version_from_strs(self.impl_version, self.impl_commit)
|
||||
@@ -220,6 +245,15 @@ impl<G, E> Configuration<G, E> {
|
||||
pub fn expect_chain_spec(&self) -> &ChainSpec<G, E> {
|
||||
self.chain_spec.as_ref().expect("chain_spec must be specified")
|
||||
}
|
||||
|
||||
/// Return a reference to the `DatabaseConfig` of this `Configuration`.
|
||||
///
|
||||
/// ### Panics
|
||||
///
|
||||
/// This method panic if the `database` is `None`
|
||||
pub fn expect_database(&self) -> &DatabaseConfig {
|
||||
self.database.as_ref().expect("database must be specified")
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns platform info
|
||||
|
||||
@@ -42,7 +42,7 @@ pub enum Error {
|
||||
SelectChainRequired,
|
||||
/// Tasks executor is missing.
|
||||
#[display(fmt="Tasks executor hasn't been provided.")]
|
||||
TasksExecutorRequired,
|
||||
TaskExecutorRequired,
|
||||
/// Other error.
|
||||
Other(String),
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ pub struct Service<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> {
|
||||
/// Receiver for futures that must be spawned as background tasks.
|
||||
to_spawn_rx: mpsc::UnboundedReceiver<(Pin<Box<dyn Future<Output = ()> + Send>>, Cow<'static, str>)>,
|
||||
/// How to spawn background tasks.
|
||||
task_executor: Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send>,
|
||||
task_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
|
||||
rpc_handlers: sc_rpc_server::RpcHandler<sc_rpc::Metadata>,
|
||||
_rpc: Box<dyn std::any::Any + Send + Sync>,
|
||||
_telemetry: Option<sc_telemetry::Telemetry>,
|
||||
|
||||
Reference in New Issue
Block a user