Fix purge-chain and print DB info on startup (#5840)

* purge-chain accepts --db option

* print DB info on startup

* Small refactoring

* Added back &self

* Add DatabaseParams for PurgeChain, ImportParams and ExportBlocks

* Don't force default value

* Remove unused fields

* Update client/cli/src/commands/export_blocks_cmd.rs

* Fix stuff

Co-authored-by: Cecile Tonglet <cecile@parity.io>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2020-04-30 14:53:04 +02:00
committed by GitHub
parent db2e916904
commit c3a6d8a881
10 changed files with 142 additions and 93 deletions
+33 -23
View File
@@ -16,20 +16,20 @@
//! Configuration trait for a CLI based on substrate
use crate::arg_enums::Database;
use crate::error::Result;
use crate::{
init_logger, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
init_logger, DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
};
use crate::arg_enums::Database;
use app_dirs::{AppDataType, AppInfo};
use names::{Generator, Name};
use sc_service::config::{
WasmExecutionMethod, Role, OffchainWorkerConfig,
Configuration, DatabaseConfig, ExtTransport, KeystoreConfig, NetworkConfiguration,
NodeKeyConfig, PrometheusConfig, PruningMode, TelemetryEndpoints, TransactionPoolOptions, TaskType
};
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_service::config::{
Configuration, DatabaseConfig, ExtTransport, KeystoreConfig, NetworkConfiguration,
NodeKeyConfig, OffchainWorkerConfig, PrometheusConfig, PruningMode, Role, TaskType,
TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
};
use sc_service::{ChainSpec, TracingReceiver};
use std::future::Future;
use std::net::SocketAddr;
@@ -75,8 +75,12 @@ pub trait CliConfiguration: Sized {
/// Get the NodeKeyParams for this object
fn node_key_params(&self) -> Option<&NodeKeyParams> {
self.network_params()
.map(|x| &x.node_key_params)
self.network_params().map(|x| &x.node_key_params)
}
/// Get the DatabaseParams for this object
fn database_params(&self) -> Option<&DatabaseParams> {
self.import_params().map(|x| &x.database_params)
}
/// Get the base path of the configuration (if any)
@@ -152,33 +156,39 @@ pub trait CliConfiguration: Sized {
/// Get the database cache size.
///
/// By default this is retrieved from `ImportParams` if it is available. Otherwise its `None`.
/// By default this is retrieved from `DatabaseParams` if it is available. Otherwise its `None`.
fn database_cache_size(&self) -> Result<Option<usize>> {
Ok(self.import_params()
Ok(self.database_params()
.map(|x| x.database_cache_size())
.unwrap_or(Default::default()))
}
/// Get the database backend variant.
///
/// By default this is retrieved from `ImportParams` if it is available. Otherwise its `None`.
/// By default this is retrieved from `DatabaseParams` if it is available. Otherwise its `None`.
fn database(&self) -> Result<Option<Database>> {
Ok(self.import_params().map(|x| x.database()))
Ok(self.database_params().and_then(|x| x.database()))
}
/// Get the database configuration.
///
/// By default this is retrieved from `SharedParams`
fn database_config(&self,
/// Get the database configuration object for the parameters provided
fn database_config(
&self,
base_path: &PathBuf,
cache_size: usize,
database: Database,
) -> Result<DatabaseConfig> {
Ok(self.shared_params().database_config(
base_path,
cache_size,
database,
))
Ok(match database {
Database::RocksDb => DatabaseConfig::RocksDb {
path: base_path.join("db"),
cache_size,
},
Database::SubDb => DatabaseConfig::SubDb {
path: base_path.join("subdb"),
},
Database::ParityDb => DatabaseConfig::ParityDb {
path: base_path.join("paritydb"),
},
})
}
/// Get the state cache size.
@@ -313,7 +323,7 @@ pub trait CliConfiguration: Sized {
fn offchain_worker(&self, role: &Role) -> Result<OffchainWorkerConfig> {
self.offchain_worker_params()
.map(|x| x.offchain_worker(role))
.unwrap_or_else(|| { Ok(OffchainWorkerConfig::default()) })
.unwrap_or_else(|| Ok(OffchainWorkerConfig::default()))
}
/// Returns `Ok(true)` if authoring should be forced