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:
Arkadiy Paronyan
2020-03-12 00:00:10 +01:00
committed by GitHub
parent d2345e8d5c
commit dc0bf210fb
38 changed files with 354 additions and 335 deletions
@@ -12,7 +12,7 @@ use sp_runtime::traits::{Verify, IdentifyAccount};
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::ChainSpec<GenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
/// The chain specification option. This is expected to come in from the CLI and
/// is little more than one of a number of alternatives which can easily be converted
@@ -142,9 +142,9 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
}
}
pub fn load_spec(id: &str) -> Result<Option<ChainSpec>, String> {
pub fn load_spec(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match Alternative::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
Some(spec) => Box::new(spec.load()?),
None => Box::new(ChainSpec::from_json_file(std::path::PathBuf::from(id))?),
})
}
@@ -4,7 +4,7 @@ use std::sync::Arc;
use std::time::Duration;
use sc_client::LongestChain;
use sc_client_api::ExecutorProvider;
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
use node_template_runtime::{self, opaque::Block, RuntimeApi};
use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
use sp_inherents::InherentDataProviders;
use sc_executor::native_executor_instance;
@@ -69,7 +69,7 @@ macro_rules! new_full_start {
}
/// Builds a new service for a full client.
pub fn new_full(config: Configuration<GenesisConfig>)
pub fn new_full(config: Configuration)
-> Result<impl AbstractService, ServiceError>
{
let is_authority = config.roles.is_authority();
@@ -181,7 +181,7 @@ pub fn new_full(config: Configuration<GenesisConfig>)
}
/// Builds a new service for a light client.
pub fn new_light(config: Configuration<GenesisConfig>)
pub fn new_light(config: Configuration)
-> Result<impl AbstractService, ServiceError>
{
let inherent_data_providers = InherentDataProviders::new();
+1 -1
View File
@@ -56,7 +56,7 @@ pub struct Extensions {
}
/// Specialized `ChainSpec`.
pub type ChainSpec = sc_service::ChainSpec<
pub type ChainSpec = sc_service::GenericChainSpec<
GenesisConfig,
Extensions,
>;
+3 -3
View File
@@ -46,7 +46,7 @@ where
cmd.update_config(&mut config, load_spec, &version)?;
let client = sc_service::new_full_client::<
node_runtime::Block, node_runtime::RuntimeApi, node_executor::Executor, _, _,
node_runtime::Block, node_runtime::RuntimeApi, node_executor::Executor,
>(&config)?;
let inspect = node_inspect::Inspector::<node_runtime::Block>::new(client);
@@ -56,7 +56,7 @@ where
cmd.init(&version)?;
cmd.update_config(&mut config, load_spec, &version)?;
cmd.run::<_, _, node_runtime::Block, node_executor::Executor>(config)
cmd.run::<node_runtime::Block, node_executor::Executor>(config)
},
Some(Subcommand::Factory(cli_args)) => {
cli_args.shared_params.init(&version)?;
@@ -108,7 +108,7 @@ where
subcommand.update_config(&mut config, load_spec, &version)?;
subcommand.run(
config,
|config: service::NodeConfiguration| Ok(new_full_start!(config).0),
|config: sc_service::Configuration| Ok(new_full_start!(config).0),
)
},
}
+3 -3
View File
@@ -83,9 +83,9 @@ impl ChainSpec {
}
}
fn load_spec(id: &str) -> Result<Option<chain_spec::ChainSpec>, String> {
fn load_spec(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
Some(spec) => Box::new(spec.load()?),
None => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(id))?),
})
}
+3 -6
View File
@@ -25,7 +25,7 @@ use sc_client::{self, LongestChain};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};
use node_executor;
use node_primitives::Block;
use node_runtime::{GenesisConfig, RuntimeApi};
use node_runtime::RuntimeApi;
use sc_service::{
AbstractService, ServiceBuilder, config::Configuration, error::{Error as ServiceError},
};
@@ -270,11 +270,8 @@ type ConcreteTransactionPool = sc_transaction_pool::BasicPool<
ConcreteBlock
>;
/// A specialized configuration object for setting up the node..
pub type NodeConfiguration = Configuration<GenesisConfig, crate::chain_spec::Extensions>;
/// Builds a new service for a full client.
pub fn new_full(config: NodeConfiguration)
pub fn new_full(config: Configuration)
-> Result<
Service<
ConcreteBlock,
@@ -296,7 +293,7 @@ pub fn new_full(config: NodeConfiguration)
}
/// Builds a new service for a light client.
pub fn new_light(config: NodeConfiguration)
pub fn new_light(config: Configuration)
-> Result<impl AbstractService, ServiceError> {
type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
let inherent_data_providers = InherentDataProviders::new();
+4 -7
View File
@@ -31,15 +31,12 @@ impl InspectCmd {
}
/// Parse CLI arguments and initialize given config.
pub fn update_config<G, E>(
pub fn update_config(
&self,
mut config: &mut sc_service::config::Configuration<G, E>,
spec_factory: impl FnOnce(&str) -> Result<Option<sc_service::ChainSpec<G, E>>, String>,
mut config: &mut sc_service::config::Configuration,
spec_factory: impl FnOnce(&str) -> Result<Box<dyn sc_service::ChainSpec>, String>,
version: &sc_cli::VersionInfo,
) -> sc_cli::Result<()> where
G: sc_service::RuntimeGenesis,
E: sc_service::ChainSpecExtension,
{
) -> sc_cli::Result<()> {
self.shared_params.update_config(config, spec_factory, version)?;
// make sure to configure keystore
@@ -128,7 +128,7 @@ fn generate_chain_spec(
Default::default(),
);
chain_spec.to_json(false).map_err(|err| err.to_string())
chain_spec.as_json(false).map_err(|err| err.to_string())
}
fn generate_authority_keys_and_store(