mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 22:47:56 +00:00
ChainSpec trait (#5185)
* ChainSpec trait * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Added docs * Fixed build * Fixed build Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
use structopt::StructOpt;
|
||||
use log::info;
|
||||
use sc_network::config::build_multiaddr;
|
||||
use sc_service::{Configuration, ChainSpecExtension, RuntimeGenesis, ChainSpec};
|
||||
use sc_service::{Configuration, ChainSpec};
|
||||
|
||||
use crate::error;
|
||||
use crate::VersionInfo;
|
||||
@@ -49,16 +49,12 @@ pub struct BuildSpecCmd {
|
||||
|
||||
impl BuildSpecCmd {
|
||||
/// Run the build-spec command
|
||||
pub fn run<G, E>(
|
||||
pub fn run(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
{
|
||||
config: Configuration,
|
||||
) -> error::Result<()> {
|
||||
info!("Building chain spec");
|
||||
let mut spec = config.expect_chain_spec().clone();
|
||||
let mut spec = config.chain_spec.expect("`chain_spec` is set to `Some` in `update_config`");
|
||||
let raw_output = self.raw;
|
||||
|
||||
if spec.boot_nodes().is_empty() && !self.disable_default_bootnode {
|
||||
@@ -72,7 +68,7 @@ impl BuildSpecCmd {
|
||||
spec.add_boot_node(addr)
|
||||
}
|
||||
|
||||
let json = sc_service::chain_ops::build_spec(spec, raw_output)?;
|
||||
let json = sc_service::chain_ops::build_spec(&*spec, raw_output)?;
|
||||
|
||||
print!("{}", json);
|
||||
|
||||
@@ -80,15 +76,13 @@ impl BuildSpecCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, Roles, ChainSpec,
|
||||
Configuration, ServiceBuilderCommand, Roles, ChainSpec,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use sp_runtime::generic::BlockId;
|
||||
@@ -53,15 +53,13 @@ pub struct CheckBlockCmd {
|
||||
|
||||
impl CheckBlockCmd {
|
||||
/// Run the check-block command
|
||||
pub fn run<G, E, B, BC, BB>(
|
||||
pub fn run<B, BC, BB>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
builder: B,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: FnOnce(Configuration<G, E>) -> Result<BC, sc_service::error::Error>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
|
||||
BC: ServiceBuilderCommand<Block = BB> + Unpin,
|
||||
BB: sp_runtime::traits::Block + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
@@ -86,15 +84,13 @@ impl CheckBlockCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
self.import_params.update_config(&mut config, Roles::FULL, self.shared_params.dev)?;
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::fmt::Debug;
|
||||
use log::info;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, ChainSpec,
|
||||
Configuration, ServiceBuilderCommand, ChainSpec,
|
||||
config::DatabaseConfig, Roles,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
@@ -65,15 +65,13 @@ pub struct ExportBlocksCmd {
|
||||
|
||||
impl ExportBlocksCmd {
|
||||
/// Run the export-blocks command
|
||||
pub fn run<G, E, B, BC, BB>(
|
||||
pub fn run<B, BC, BB>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
builder: B,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: FnOnce(Configuration<G, E>) -> Result<BC, sc_service::error::Error>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
|
||||
BC: ServiceBuilderCommand<Block = BB> + Unpin,
|
||||
BB: sp_runtime::traits::Block + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
@@ -98,15 +96,13 @@ impl ExportBlocksCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
self.pruning_params.update_config(&mut config, Roles::FULL, true)?;
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, ChainSpec, Roles,
|
||||
Configuration, ServiceBuilderCommand, ChainSpec, Roles,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
|
||||
@@ -59,15 +59,13 @@ impl<T: Read + Seek> ReadPlusSeek for T {}
|
||||
|
||||
impl ImportBlocksCmd {
|
||||
/// Run the import-blocks command
|
||||
pub fn run<G, E, B, BC, BB>(
|
||||
pub fn run<B, BC, BB>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
builder: B,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: FnOnce(Configuration<G, E>) -> Result<BC, sc_service::error::Error>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
|
||||
BC: ServiceBuilderCommand<Block = BB> + Unpin,
|
||||
BB: sp_runtime::traits::Block + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
@@ -88,15 +86,13 @@ impl ImportBlocksCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
self.import_params.update_config(&mut config, Roles::FULL, self.shared_params.dev)?;
|
||||
|
||||
@@ -25,9 +25,7 @@ mod purge_chain_cmd;
|
||||
use std::fmt::Debug;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, ChainSpec,
|
||||
};
|
||||
use sc_service::{ Configuration, ServiceBuilderCommand, ChainSpec };
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
|
||||
use crate::error;
|
||||
@@ -87,15 +85,13 @@ impl Subcommand {
|
||||
}
|
||||
|
||||
/// Run any `CoreParams` command
|
||||
pub fn run<G, E, B, BC, BB>(
|
||||
pub fn run<B, BC, BB>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
builder: B,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: FnOnce(Configuration<G, E>) -> Result<BC, sc_service::error::Error>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
|
||||
BC: ServiceBuilderCommand<Block = BB> + Unpin,
|
||||
BB: sp_runtime::traits::Block + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
@@ -112,15 +108,13 @@ impl Subcommand {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
match self {
|
||||
Subcommand::BuildSpec(cmd) => cmd.update_config(&mut config, spec_factory, version),
|
||||
|
||||
@@ -18,10 +18,7 @@ use std::fmt::Debug;
|
||||
use std::io::{Write, self};
|
||||
use std::fs;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ChainSpec,
|
||||
config::{DatabaseConfig},
|
||||
};
|
||||
use sc_service::{ Configuration, ChainSpec, config::{DatabaseConfig} };
|
||||
|
||||
use crate::error;
|
||||
use crate::VersionInfo;
|
||||
@@ -41,14 +38,10 @@ pub struct PurgeChainCmd {
|
||||
|
||||
impl PurgeChainCmd {
|
||||
/// Run the purge command
|
||||
pub fn run<G, E>(
|
||||
pub fn run(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
{
|
||||
config: Configuration,
|
||||
) -> error::Result<()> {
|
||||
let db_path = match config.expect_database() {
|
||||
DatabaseConfig::Path { path, .. } => path,
|
||||
_ => {
|
||||
@@ -88,15 +81,13 @@ impl PurgeChainCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
config.use_in_memory_keystore()?;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::fmt::Debug;
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis, ServiceBuilderCommand, ChainSpec, Roles,
|
||||
Configuration, ServiceBuilderCommand, ChainSpec, Roles,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
|
||||
@@ -43,15 +43,13 @@ pub struct RevertCmd {
|
||||
|
||||
impl RevertCmd {
|
||||
/// Run the revert command
|
||||
pub fn run<G, E, B, BC, BB>(
|
||||
pub fn run<B, BC, BB>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
builder: B,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: FnOnce(Configuration<G, E>) -> Result<BC, sc_service::error::Error>,
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
B: FnOnce(Configuration) -> Result<BC, sc_service::error::Error>,
|
||||
BC: ServiceBuilderCommand<Block = BB> + Unpin,
|
||||
BB: sp_runtime::traits::Block + Debug,
|
||||
<<<BB as BlockT>::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug,
|
||||
@@ -64,15 +62,13 @@ impl RevertCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
self.pruning_params.update_config(&mut config, Roles::FULL, true)?;
|
||||
|
||||
@@ -23,7 +23,7 @@ use names::{Generator, Name};
|
||||
use regex::Regex;
|
||||
use chrono::prelude::*;
|
||||
use sc_service::{
|
||||
AbstractService, Configuration, ChainSpecExtension, RuntimeGenesis, ChainSpec, Roles,
|
||||
AbstractService, Configuration, ChainSpec, Roles,
|
||||
config::{KeystoreConfig, PrometheusConfig},
|
||||
};
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
@@ -291,16 +291,14 @@ impl RunCmd {
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters of `RunCmd` and `VersionInfo`
|
||||
pub fn update_config<G, E, F>(
|
||||
pub fn update_config<F>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
|
||||
@@ -447,18 +445,16 @@ impl RunCmd {
|
||||
}
|
||||
|
||||
/// Run the command that runs the node
|
||||
pub fn run<G, E, FNL, FNF, SL, SF>(
|
||||
pub fn run<FNL, FNF, SL, SF>(
|
||||
self,
|
||||
config: Configuration<G, E>,
|
||||
config: Configuration,
|
||||
new_light: FNL,
|
||||
new_full: FNF,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
FNL: FnOnce(Configuration<G, E>) -> Result<SL, sc_service::error::Error>,
|
||||
FNF: FnOnce(Configuration<G, E>) -> Result<SF, sc_service::error::Error>,
|
||||
FNL: FnOnce(Configuration) -> Result<SL, sc_service::error::Error>,
|
||||
FNF: FnOnce(Configuration) -> Result<SF, sc_service::error::Error>,
|
||||
SL: AbstractService + Unpin,
|
||||
SF: AbstractService + Unpin,
|
||||
{
|
||||
@@ -625,7 +621,7 @@ fn parse_cors(s: &str) -> Result<Cors, Box<dyn std::error::Error>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sc_service::config::DatabaseConfig;
|
||||
use sc_service::{GenericChainSpec, config::DatabaseConfig};
|
||||
|
||||
const TEST_VERSION_INFO: &'static VersionInfo = &VersionInfo {
|
||||
name: "node-test",
|
||||
@@ -655,7 +651,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn keystore_path_is_generated_correctly() {
|
||||
let chain_spec = ChainSpec::from_genesis(
|
||||
let chain_spec = GenericChainSpec::from_genesis(
|
||||
"test",
|
||||
"test-id",
|
||||
|| (),
|
||||
@@ -673,9 +669,9 @@ mod tests {
|
||||
|
||||
let mut config = Configuration::default();
|
||||
config.config_dir = Some(PathBuf::from("/test/path"));
|
||||
config.chain_spec = Some(chain_spec.clone());
|
||||
config.chain_spec = Some(Box::new(chain_spec.clone()));
|
||||
let chain_spec = chain_spec.clone();
|
||||
cli.update_config(&mut config, move |_| Ok(Some(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
cli.update_config(&mut config, move |_| Ok(Box::new(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
|
||||
let expected_path = match keystore_path {
|
||||
Some(path) => PathBuf::from(path),
|
||||
@@ -688,7 +684,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ensure_load_spec_provide_defaults() {
|
||||
let chain_spec = ChainSpec::from_genesis(
|
||||
let chain_spec = GenericChainSpec::from_genesis(
|
||||
"test",
|
||||
"test-id",
|
||||
|| (),
|
||||
@@ -703,7 +699,7 @@ mod tests {
|
||||
let cli = RunCmd::from_iter(args);
|
||||
|
||||
let mut config = Configuration::from_version(TEST_VERSION_INFO);
|
||||
cli.update_config(&mut config, |_| Ok(Some(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
cli.update_config(&mut config, |_| Ok(Box::new(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
|
||||
assert!(config.chain_spec.is_some());
|
||||
assert!(!config.network.boot_nodes.is_empty());
|
||||
@@ -712,7 +708,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ensure_update_config_for_running_node_provides_defaults() {
|
||||
let chain_spec = ChainSpec::from_genesis(
|
||||
let chain_spec = GenericChainSpec::from_genesis(
|
||||
"test",
|
||||
"test-id",
|
||||
|| (),
|
||||
@@ -728,7 +724,7 @@ mod tests {
|
||||
|
||||
let mut config = Configuration::from_version(TEST_VERSION_INFO);
|
||||
cli.init(&TEST_VERSION_INFO).unwrap();
|
||||
cli.update_config(&mut config, |_| Ok(Some(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
cli.update_config(&mut config, |_| Ok(Box::new(chain_spec)), TEST_VERSION_INFO).unwrap();
|
||||
|
||||
assert!(config.config_dir.is_some());
|
||||
assert!(config.database.is_some());
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis, config::DatabaseConfig};
|
||||
use sc_service::{Configuration, config::DatabaseConfig};
|
||||
|
||||
use crate::error;
|
||||
use crate::arg_enums::{
|
||||
@@ -79,15 +79,12 @@ pub struct ImportParams {
|
||||
|
||||
impl ImportParams {
|
||||
/// Put block import CLI params into `config` object.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
role: sc_service::Roles,
|
||||
is_dev: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
|
||||
if let Some(DatabaseConfig::Path { ref mut cache_size, .. }) = config.database {
|
||||
|
||||
@@ -21,7 +21,7 @@ use structopt::StructOpt;
|
||||
use sc_network::{
|
||||
config::{NonReservedPeerMode, TransportConfig}, multiaddr::Protocol,
|
||||
};
|
||||
use sc_service::{Configuration, RuntimeGenesis};
|
||||
use sc_service::Configuration;
|
||||
|
||||
use crate::error;
|
||||
use crate::params::node_key_params::NodeKeyParams;
|
||||
@@ -101,16 +101,13 @@ pub struct NetworkConfigurationParams {
|
||||
|
||||
impl NetworkConfigurationParams {
|
||||
/// Fill the given `NetworkConfiguration` by looking at the cli parameters.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
config_path: PathBuf,
|
||||
client_id: String,
|
||||
is_dev: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
config.network.boot_nodes.extend(self.bootnodes.clone());
|
||||
config.network.config_path = Some(config_path.clone());
|
||||
config.network.net_config_path = Some(config_path.clone());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis};
|
||||
use sc_service::Configuration;
|
||||
use sc_network::config::NodeKeyConfig;
|
||||
use sp_core::H256;
|
||||
|
||||
@@ -93,14 +93,11 @@ pub struct NodeKeyParams {
|
||||
impl NodeKeyParams {
|
||||
/// Create a `NodeKeyConfig` from the given `NodeKeyParams` in the context
|
||||
/// of an optional network config storage directory.
|
||||
pub fn update_config<'a, G, E>(
|
||||
pub fn update_config<'a>(
|
||||
&self,
|
||||
mut config: &'a mut Configuration<G, E>,
|
||||
mut config: &'a mut Configuration,
|
||||
net_config_path: Option<&PathBuf>,
|
||||
) -> error::Result<&'a NodeKeyConfig>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<&'a NodeKeyConfig> {
|
||||
config.network.node_key = match self.node_key_type {
|
||||
NodeKeyType::Ed25519 => {
|
||||
let secret = if let Some(node_key) = self.node_key.as_ref() {
|
||||
@@ -146,7 +143,7 @@ mod tests {
|
||||
fn test_node_key_config_input() {
|
||||
fn secret_input(net_config_dir: Option<&PathBuf>) -> error::Result<()> {
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
let sk = match node_key_type {
|
||||
NodeKeyType::Ed25519 => ed25519::SecretKey::generate().as_ref().to_vec()
|
||||
@@ -173,7 +170,7 @@ mod tests {
|
||||
fn test_node_key_config_file() {
|
||||
fn secret_file(net_config_dir: Option<&PathBuf>) -> error::Result<()> {
|
||||
NodeKeyType::variants().iter().try_for_each(|t| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let node_key_type = NodeKeyType::from_str(t).unwrap();
|
||||
let tmp = tempfile::Builder::new().prefix("alice").tempdir()?;
|
||||
let file = tmp.path().join(format!("{}_mysecret", t)).to_path_buf();
|
||||
@@ -212,7 +209,7 @@ mod tests {
|
||||
|
||||
fn no_config_dir() -> error::Result<()> {
|
||||
with_def_params(|params| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let typ = params.node_key_type;
|
||||
params.update_config(&mut config, None)
|
||||
.and_then(|c| match c {
|
||||
@@ -225,7 +222,7 @@ mod tests {
|
||||
|
||||
fn some_config_dir(net_config_dir: &PathBuf) -> error::Result<()> {
|
||||
with_def_params(|params| {
|
||||
let mut config = Configuration::<(), ()>::default();
|
||||
let mut config = Configuration::default();
|
||||
let dir = PathBuf::from(net_config_dir.clone());
|
||||
let typ = params.node_key_type;
|
||||
params.update_config(&mut config, Some(net_config_dir))
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use structopt::StructOpt;
|
||||
use sc_service::{Configuration, RuntimeGenesis, PruningMode};
|
||||
use sc_service::{Configuration, PruningMode};
|
||||
|
||||
use crate::error;
|
||||
|
||||
@@ -33,15 +33,12 @@ pub struct PruningParams {
|
||||
|
||||
impl PruningParams {
|
||||
/// Put block pruning CLI params into `config` object.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
mut config: &mut Configuration,
|
||||
role: sc_service::Roles,
|
||||
unsafe_pruning: bool,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
{
|
||||
) -> error::Result<()> {
|
||||
// by default we disable pruning if the node is an authority (i.e.
|
||||
// `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
|
||||
// node is an authority and pruning is enabled explicitly, then we error
|
||||
|
||||
@@ -18,8 +18,7 @@ use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use app_dirs::{AppInfo, AppDataType};
|
||||
use sc_service::{
|
||||
Configuration, ChainSpecExtension, RuntimeGenesis,
|
||||
config::DatabaseConfig, ChainSpec,
|
||||
Configuration, config::DatabaseConfig, ChainSpec,
|
||||
};
|
||||
|
||||
use crate::VersionInfo;
|
||||
@@ -50,25 +49,19 @@ pub struct SharedParams {
|
||||
|
||||
impl SharedParams {
|
||||
/// Load spec to `Configuration` from `SharedParams` and spec factory.
|
||||
pub fn update_config<'a, G, E, F>(
|
||||
pub fn update_config<'a, F>(
|
||||
&self,
|
||||
mut config: &'a mut Configuration<G, E>,
|
||||
mut config: &'a mut Configuration,
|
||||
spec_factory: F,
|
||||
version: &VersionInfo,
|
||||
) -> error::Result<&'a ChainSpec<G, E>> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
F: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
) -> error::Result<&'a dyn ChainSpec> where
|
||||
F: FnOnce(&str) -> Result<Box<dyn ChainSpec>, String>,
|
||||
{
|
||||
let chain_key = match self.chain {
|
||||
Some(ref chain) => chain.clone(),
|
||||
None => if self.dev { "dev".into() } else { "".into() }
|
||||
};
|
||||
let spec = match spec_factory(&chain_key)? {
|
||||
Some(spec) => spec,
|
||||
None => ChainSpec::from_json_file(PathBuf::from(chain_key))?
|
||||
};
|
||||
|
||||
let spec = spec_factory(&chain_key)?;
|
||||
config.network.boot_nodes = spec.boot_nodes().to_vec();
|
||||
config.telemetry_endpoints = spec.telemetry_endpoints().clone();
|
||||
|
||||
@@ -87,7 +80,7 @@ impl SharedParams {
|
||||
});
|
||||
}
|
||||
|
||||
Ok(config.chain_spec.as_ref().unwrap())
|
||||
Ok(config.expect_chain_spec())
|
||||
}
|
||||
|
||||
/// Initialize substrate. This must be done only once.
|
||||
|
||||
@@ -31,9 +31,9 @@ pub struct TransactionPoolParams {
|
||||
|
||||
impl TransactionPoolParams {
|
||||
/// Fill the given `PoolConfiguration` by looking at the cli parameters.
|
||||
pub fn update_config<G, E>(
|
||||
pub fn update_config(
|
||||
&self,
|
||||
config: &mut Configuration<G, E>,
|
||||
config: &mut Configuration,
|
||||
) -> error::Result<()> {
|
||||
// ready queue
|
||||
config.transaction_pool.ready.count = self.pool_limit;
|
||||
|
||||
@@ -79,12 +79,12 @@ fn build_runtime() -> Result<tokio::runtime::Runtime, std::io::Error> {
|
||||
|
||||
/// A helper function that runs a future with tokio and stops if the process receives the signal
|
||||
/// SIGTERM or SIGINT
|
||||
pub fn run_until_exit<FUT, ERR, G, E, F>(
|
||||
mut config: Configuration<G, E>,
|
||||
pub fn run_until_exit<FUT, ERR, F>(
|
||||
mut config: Configuration,
|
||||
future_builder: F,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
F: FnOnce(Configuration<G, E>) -> error::Result<FUT>,
|
||||
F: FnOnce(Configuration) -> error::Result<FUT>,
|
||||
FUT: Future<Output = Result<(), ERR>> + future::Future,
|
||||
ERR: 'static + std::error::Error,
|
||||
{
|
||||
@@ -106,12 +106,12 @@ where
|
||||
|
||||
/// A helper function that runs an `AbstractService` with tokio and stops if the process receives
|
||||
/// the signal SIGTERM or SIGINT
|
||||
pub fn run_service_until_exit<T, G, E, F>(
|
||||
mut config: Configuration<G, E>,
|
||||
pub fn run_service_until_exit<T, F>(
|
||||
mut config: Configuration,
|
||||
service_builder: F,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
F: FnOnce(Configuration<G, E>) -> Result<T, sc_service::error::Error>,
|
||||
F: FnOnce(Configuration) -> Result<T, sc_service::error::Error>,
|
||||
T: AbstractService + Unpin,
|
||||
{
|
||||
let mut runtime = build_runtime()?;
|
||||
|
||||
Reference in New Issue
Block a user