polkadot-service: Make native runtime configurable (#3189)

* polkadot-service: Make native runtime configurable

This pull requests adds support for configuring the native runtimes used
by polkadot-service. While this whole pr doesn't change that much for
polkadot, besides not having the light-node enabled for the default
polkadot binary. However, downstream projects (parachains) will have a
much better compile time. In cumulus for example the `cargo test --all
--release` is about 4m faster to compile.

* Fixes

* Fix

* Enable rococo-native

* Fix light client

* 🤦

* Fixes
This commit is contained in:
Bastian Köcher
2021-06-08 22:05:20 +02:00
committed by GitHub
parent 2abaca3a8c
commit f6cbe8e8d8
11 changed files with 711 additions and 421 deletions
+193 -163
View File
File diff suppressed because it is too large Load Diff
+4 -6
View File
@@ -12,11 +12,8 @@ edition = "2018"
readme = "README.md"
[dependencies]
cli = { package = "polkadot-cli", path = "cli" }
polkadot-cli = { path = "cli", features = [ "kusama-native", "westend-native", "rococo-native" ] }
color-eyre = "0.5.10"
thiserror = "1.0.23"
futures = "0.3.12"
service = { package = "polkadot-service", path = "node/service" }
parity-util-mem = { version = "*", default-features = false, features = ["jemalloc-global"] }
[dev-dependencies]
@@ -43,6 +40,7 @@ members = [
"xcm/xcm-builder",
"xcm/xcm-executor",
"xcm/pallet-xcm",
"node/client",
"node/collation-generation",
"node/core/approval-voting",
"node/core/av-store",
@@ -96,8 +94,8 @@ opt-level = 3
panic = "unwind"
[features]
runtime-benchmarks=["cli/runtime-benchmarks"]
try-runtime = ["cli/try-runtime"]
runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ]
try-runtime = [ "polkadot-cli/try-runtime" ]
# Configuration for building a .deb package - for use with `cargo-deb`
[package.metadata.deb]
+8 -1
View File
@@ -54,9 +54,16 @@ browser = [
"wasm-bindgen",
"wasm-bindgen-futures",
"browser-utils",
"service",
"service/light-node",
]
runtime-benchmarks = [ "service/runtime-benchmarks" ]
trie-memory-tracker = [ "sp-trie/memory-tracker" ]
full-node = [ "service/full-node" ]
try-runtime = [ "service/try-runtime" ]
# Configure the native runtimes to use. Polkadot is always enabled by default.
#
# Validators require the native runtime currently
kusama-native = [ "service/kusama-native" ]
westend-native = [ "service/westend-native" ]
rococo-native = [ "service/rococo-native" ]
+75 -32
View File
@@ -75,23 +75,44 @@ impl SubstrateCli for Cli {
} else { id };
Ok(match id {
"kusama" => Box::new(service::chain_spec::kusama_config()?),
#[cfg(feature = "kusama-native")]
"kusama-dev" => Box::new(service::chain_spec::kusama_development_config()?),
#[cfg(feature = "kusama-native")]
"kusama-local" => Box::new(service::chain_spec::kusama_local_testnet_config()?),
#[cfg(feature = "kusama-native")]
"kusama-staging" => Box::new(service::chain_spec::kusama_staging_testnet_config()?),
#[cfg(not(feature = "kusama-native"))]
name if name.starts_with("kusama-") =>
Err(format!("`{}` only supported with `kusama-native` feature enabled.", name))?,
"polkadot" => Box::new(service::chain_spec::polkadot_config()?),
"polkadot-dev" | "dev" => Box::new(service::chain_spec::polkadot_development_config()?),
"polkadot-local" => Box::new(service::chain_spec::polkadot_local_testnet_config()?),
"polkadot-staging" => Box::new(service::chain_spec::polkadot_staging_testnet_config()?),
"rococo" => Box::new(service::chain_spec::rococo_config()?),
#[cfg(feature = "rococo-native")]
"rococo-dev" => Box::new(service::chain_spec::rococo_development_config()?),
#[cfg(feature = "rococo-native")]
"rococo-local" => Box::new(service::chain_spec::rococo_local_testnet_config()?),
#[cfg(feature = "rococo-native")]
"rococo-staging" => Box::new(service::chain_spec::rococo_staging_testnet_config()?),
name if name.starts_with("rococo-") =>
Err(format!("`{}` only supported with `rococo-native` feature enabled.", name))?,
"westend" => Box::new(service::chain_spec::westend_config()?),
#[cfg(feature = "westend-native")]
"westend-dev" => Box::new(service::chain_spec::westend_development_config()?),
#[cfg(feature = "westend-native")]
"westend-local" => Box::new(service::chain_spec::westend_local_testnet_config()?),
#[cfg(feature = "westend-native")]
"westend-staging" => Box::new(service::chain_spec::westend_staging_testnet_config()?),
#[cfg(not(feature = "westend-native"))]
name if name.starts_with("westend-") =>
Err(format!("`{}` only supported with `westend-native` feature enabled.", name))?,
"wococo" => Box::new(service::chain_spec::wococo_config()?),
#[cfg(feature = "rococo-native")]
"wococo-dev" => Box::new(service::chain_spec::wococo_development_config()?),
#[cfg(not(feature = "rococo-native"))]
name if name.starts_with("wococo-") =>
Err(format!("`{}` only supported with `rococo-native` feature enabled.", name))?,
path => {
let path = std::path::PathBuf::from(path);
@@ -113,15 +134,25 @@ impl SubstrateCli for Cli {
}
fn native_runtime_version(spec: &Box<dyn service::ChainSpec>) -> &'static RuntimeVersion {
#[cfg(feature = "kusama-native")]
if spec.is_kusama() {
&service::kusama_runtime::VERSION
} else if spec.is_westend() {
&service::westend_runtime::VERSION
} else if spec.is_rococo() || spec.is_wococo() {
&service::rococo_runtime::VERSION
} else {
&service::polkadot_runtime::VERSION
return &service::kusama_runtime::VERSION
}
#[cfg(feature = "westend-native")]
if spec.is_westend() {
return &service::westend_runtime::VERSION
}
#[cfg(feature = "rococo-native")]
if spec.is_rococo() || spec.is_wococo() {
return &service::rococo_runtime::VERSION
}
#[cfg(not(all(feature = "rococo-native", feature = "westend-native", feature = "kusama-native")))]
let _ = spec;
&service::polkadot_runtime::VERSION
}
}
@@ -181,8 +212,11 @@ pub fn run() -> Result<()> {
runner.run_node_until_exit(move |config| async move {
let role = config.role.clone();
let task_manager = match role {
Role::Light => service::build_light(config).map(|(task_manager, _)| task_manager),
match role {
#[cfg(feature = "browser")]
Role::Light => service::build_light(config).map(|(task_manager, _)| task_manager).map_err(Into::into),
#[cfg(not(feature = "browser"))]
Role::Light => Err(Error::Other("Light client not enabled".into())),
_ => service::build_full(
config,
service::IsCollator::No,
@@ -190,9 +224,8 @@ pub fn run() -> Result<()> {
cli.run.no_beefy,
jaeger_agent,
None,
).map(|full| full.task_manager)
}?;
Ok::<_, Error>(task_manager)
).map(|full| full.task_manager).map_err(Into::into)
}
})
},
Some(Subcommand::BuildSpec(cmd)) => {
@@ -304,23 +337,28 @@ pub fn run() -> Result<()> {
set_default_ss58_version(chain_spec);
ensure_dev(chain_spec).map_err(Error::Other)?;
#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
Ok(runner.sync_run(|config| {
return Ok(runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
} else if chain_spec.is_westend() {
Ok(runner.sync_run(|config| {
}
#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return Ok(runner.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
} else {
// else we assume it is polkadot.
Ok(runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
}
// else we assume it is polkadot.
Ok(runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
},
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
#[cfg(feature = "try-runtime")]
@@ -337,29 +375,34 @@ pub fn run() -> Result<()> {
).map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
ensure_dev(chain_spec).map_err(Error::Other)?;
#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
runner.async_run(|config| {
return runner.async_run(|config| {
Ok((cmd.run::<
service::kusama_runtime::Block,
service::KusamaExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
} else if chain_spec.is_westend() {
runner.async_run(|config| {
}
#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return runner.async_run(|config| {
Ok((cmd.run::<
service::westend_runtime::Block,
service::WestendExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
} else {
// else we assume it is polkadot.
runner.async_run(|config| {
Ok((cmd.run::<
service::polkadot_runtime::Block,
service::PolkadotExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
}
// else we assume it is polkadot.
runner.async_run(|config| {
Ok((cmd.run::<
service::polkadot_runtime::Block,
service::PolkadotExecutor,
>(config).map_err(Error::SubstrateCli), task_manager))
})
}
}?;
Ok(())
+44
View File
@@ -0,0 +1,44 @@
[package]
name = "polkadot-client"
version = "0.9.3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-offchain = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
beefy-primitives = { git = "https://github.com/paritytech/grandpa-bridge-gadget", branch = "master" }
# Polkadot Runtimes
polkadot-runtime = { path = "../../runtime/polkadot" }
kusama-runtime = { path = "../../runtime/kusama", optional = true }
westend-runtime = { path = "../../runtime/westend", optional = true }
rococo-runtime = { path = "../../runtime/rococo", optional = true }
polkadot-primitives = { path = "../../primitives" }
[features]
kusama = [ "kusama-runtime" ]
rococo = [ "rococo-runtime" ]
westend = [ "westend-runtime" ]
@@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Polkadot Client meta trait
//! Polkadot Client
//!
//! Provides the [`AbstractClient`] trait that is a super trait that combines all the traits the client implements.
//! There is also the [`Client`] enum that combines all the different clients into one common structure.
use std::sync::Arc;
use beefy_primitives::ecdsa::AuthorityId as BeefyId;
@@ -26,14 +29,50 @@ use sp_runtime::{
use sc_client_api::{Backend as BackendT, BlockchainEvents, KeyIterator, AuxStore, UsageProvider};
use sp_storage::{StorageData, StorageKey, ChildInfo, PrefixedStorageKey};
use polkadot_primitives::v1::{Block, ParachainHost, AccountId, Nonce, Balance, Header, BlockNumber, Hash};
use consensus_common::BlockStatus;
use sp_consensus::BlockStatus;
use sc_executor::native_executor_instance;
pub type FullBackend = sc_service::TFullBackend<Block>;
pub type FullClient<RuntimeApi, Executor> = sc_service::TFullClient<Block, RuntimeApi, Executor>;
native_executor_instance!(
pub PolkadotExecutor,
polkadot_runtime::api::dispatch,
polkadot_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
#[cfg(feature = "kusama")]
native_executor_instance!(
pub KusamaExecutor,
kusama_runtime::api::dispatch,
kusama_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
#[cfg(feature = "westend")]
native_executor_instance!(
pub WestendExecutor,
westend_runtime::api::dispatch,
westend_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
#[cfg(feature = "rococo")]
native_executor_instance!(
pub RococoExecutor,
rococo_runtime::api::dispatch,
rococo_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
/// A set of APIs that polkadot-like runtimes must implement.
pub trait RuntimeApiCollection:
sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::ApiExt<Block>
+ sp_consensus_babe::BabeApi<Block>
+ grandpa_primitives::GrandpaApi<Block>
+ sp_finality_grandpa::GrandpaApi<Block>
+ ParachainHost<Block>
+ sp_block_builder::BlockBuilder<Block>
+ frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
@@ -53,7 +92,7 @@ where
Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::ApiExt<Block>
+ sp_consensus_babe::BabeApi<Block>
+ grandpa_primitives::GrandpaApi<Block>
+ sp_finality_grandpa::GrandpaApi<Block>
+ ParachainHost<Block>
+ sp_block_builder::BlockBuilder<Block>
+ frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
@@ -145,31 +184,47 @@ pub trait ClientHandle {
fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output;
}
macro_rules! with_client {
{
$self:ident,
$client:ident,
{
$( $code:tt )*
}
} => {
match $self {
Self::Polkadot($client) => { $( $code )* },
#[cfg(feature = "westend")]
Self::Westend($client) => { $( $code )* },
#[cfg(feature = "kusama")]
Self::Kusama($client) => { $( $code )* },
#[cfg(feature = "rococo")]
Self::Rococo($client) => { $( $code )* },
}
}
}
/// A client instance of Polkadot.
///
/// See [`ExecuteWithClient`] for more information.
#[derive(Clone)]
pub enum Client {
Polkadot(Arc<crate::FullClient<polkadot_runtime::RuntimeApi, crate::PolkadotExecutor>>),
Westend(Arc<crate::FullClient<westend_runtime::RuntimeApi, crate::WestendExecutor>>),
Kusama(Arc<crate::FullClient<kusama_runtime::RuntimeApi, crate::KusamaExecutor>>),
Rococo(Arc<crate::FullClient<rococo_runtime::RuntimeApi, crate::RococoExecutor>>),
Polkadot(Arc<FullClient<polkadot_runtime::RuntimeApi, PolkadotExecutor>>),
#[cfg(feature = "westend")]
Westend(Arc<FullClient<westend_runtime::RuntimeApi, WestendExecutor>>),
#[cfg(feature = "kusama")]
Kusama(Arc<FullClient<kusama_runtime::RuntimeApi, KusamaExecutor>>),
#[cfg(feature = "rococo")]
Rococo(Arc<FullClient<rococo_runtime::RuntimeApi, RococoExecutor>>),
}
impl ClientHandle for Client {
fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output {
match self {
Self::Polkadot(client) => {
T::execute_with_client::<_, _, crate::FullBackend>(t, client.clone())
},
Self::Westend(client) => {
T::execute_with_client::<_, _, crate::FullBackend>(t, client.clone())
},
Self::Kusama(client) => {
T::execute_with_client::<_, _, crate::FullBackend>(t, client.clone())
},
Self::Rococo(client) => {
T::execute_with_client::<_, _, crate::FullBackend>(t, client.clone())
with_client! {
self,
client,
{
T::execute_with_client::<_, _, FullBackend>(t, client.clone())
}
}
}
@@ -177,11 +232,12 @@ impl ClientHandle for Client {
impl UsageProvider<Block> for Client {
fn usage_info(&self) -> sc_client_api::ClientInfo<Block> {
match self {
Self::Polkadot(client) => client.usage_info(),
Self::Westend(client) => client.usage_info(),
Self::Kusama(client) => client.usage_info(),
Self::Rococo(client) => client.usage_info(),
with_client! {
self,
client,
{
client.usage_info()
}
}
}
}
@@ -191,29 +247,32 @@ impl sc_client_api::BlockBackend<Block> for Client {
&self,
id: &BlockId<Block>
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
match self {
Self::Polkadot(client) => client.block_body(id),
Self::Westend(client) => client.block_body(id),
Self::Kusama(client) => client.block_body(id),
Self::Rococo(client) => client.block_body(id),
with_client! {
self,
client,
{
client.block_body(id)
}
}
}
fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>> {
match self {
Self::Polkadot(client) => client.block(id),
Self::Westend(client) => client.block(id),
Self::Kusama(client) => client.block(id),
Self::Rococo(client) => client.block(id),
with_client! {
self,
client,
{
client.block(id)
}
}
}
fn block_status(&self, id: &BlockId<Block>) -> sp_blockchain::Result<BlockStatus> {
match self {
Self::Polkadot(client) => client.block_status(id),
Self::Westend(client) => client.block_status(id),
Self::Kusama(client) => client.block_status(id),
Self::Rococo(client) => client.block_status(id),
with_client! {
self,
client,
{
client.block_status(id)
}
}
}
@@ -221,11 +280,12 @@ impl sc_client_api::BlockBackend<Block> for Client {
&self,
id: &BlockId<Block>
) -> sp_blockchain::Result<Option<Justifications>> {
match self {
Self::Polkadot(client) => client.justifications(id),
Self::Westend(client) => client.justifications(id),
Self::Kusama(client) => client.justifications(id),
Self::Rococo(client) => client.justifications(id),
with_client! {
self,
client,
{
client.justifications(id)
}
}
}
@@ -233,11 +293,12 @@ impl sc_client_api::BlockBackend<Block> for Client {
&self,
number: NumberFor<Block>
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
match self {
Self::Polkadot(client) => client.block_hash(number),
Self::Westend(client) => client.block_hash(number),
Self::Kusama(client) => client.block_hash(number),
Self::Rococo(client) => client.block_hash(number),
with_client! {
self,
client,
{
client.block_hash(number)
}
}
}
@@ -245,11 +306,12 @@ impl sc_client_api::BlockBackend<Block> for Client {
&self,
id: &<Block as BlockT>::Hash
) -> sp_blockchain::Result<Option<Vec<u8>>> {
match self {
Self::Polkadot(client) => client.indexed_transaction(id),
Self::Westend(client) => client.indexed_transaction(id),
Self::Kusama(client) => client.indexed_transaction(id),
Self::Rococo(client) => client.indexed_transaction(id),
with_client! {
self,
client,
{
client.indexed_transaction(id)
}
}
}
@@ -257,11 +319,12 @@ impl sc_client_api::BlockBackend<Block> for Client {
&self,
id: &BlockId<Block>
) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> {
match self {
Self::Polkadot(client) => client.block_indexed_body(id),
Self::Westend(client) => client.block_indexed_body(id),
Self::Kusama(client) => client.block_indexed_body(id),
Self::Rococo(client) => client.block_indexed_body(id),
with_client! {
self,
client,
{
client.block_indexed_body(id)
}
}
}
}
@@ -272,11 +335,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
id: &BlockId<Block>,
key: &StorageKey,
) -> sp_blockchain::Result<Option<StorageData>> {
match self {
Self::Polkadot(client) => client.storage(id, key),
Self::Westend(client) => client.storage(id, key),
Self::Kusama(client) => client.storage(id, key),
Self::Rococo(client) => client.storage(id, key),
with_client! {
self,
client,
{
client.storage(id, key)
}
}
}
@@ -285,11 +349,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
id: &BlockId<Block>,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<StorageKey>> {
match self {
Self::Polkadot(client) => client.storage_keys(id, key_prefix),
Self::Westend(client) => client.storage_keys(id, key_prefix),
Self::Kusama(client) => client.storage_keys(id, key_prefix),
Self::Rococo(client) => client.storage_keys(id, key_prefix),
with_client! {
self,
client,
{
client.storage_keys(id, key_prefix)
}
}
}
@@ -298,11 +363,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
id: &BlockId<Block>,
key: &StorageKey,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
match self {
Self::Polkadot(client) => client.storage_hash(id, key),
Self::Westend(client) => client.storage_hash(id, key),
Self::Kusama(client) => client.storage_hash(id, key),
Self::Rococo(client) => client.storage_hash(id, key),
with_client! {
self,
client,
{
client.storage_hash(id, key)
}
}
}
@@ -311,11 +377,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
id: &BlockId<Block>,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<(StorageKey, StorageData)>> {
match self {
Self::Polkadot(client) => client.storage_pairs(id, key_prefix),
Self::Westend(client) => client.storage_pairs(id, key_prefix),
Self::Kusama(client) => client.storage_pairs(id, key_prefix),
Self::Rococo(client) => client.storage_pairs(id, key_prefix),
with_client! {
self,
client,
{
client.storage_pairs(id, key_prefix)
}
}
}
@@ -325,11 +392,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
prefix: Option<&'a StorageKey>,
start_key: Option<&StorageKey>,
) -> sp_blockchain::Result<KeyIterator<'a, <crate::FullBackend as sc_client_api::Backend<Block>>::State, Block>> {
match self {
Self::Polkadot(client) => client.storage_keys_iter(id, prefix, start_key),
Self::Westend(client) => client.storage_keys_iter(id, prefix, start_key),
Self::Kusama(client) => client.storage_keys_iter(id, prefix, start_key),
Self::Rococo(client) => client.storage_keys_iter(id, prefix, start_key),
with_client! {
self,
client,
{
client.storage_keys_iter(id, prefix, start_key)
}
}
}
@@ -339,11 +407,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<StorageData>> {
match self {
Self::Polkadot(client) => client.child_storage(id, child_info, key),
Self::Westend(client) => client.child_storage(id, child_info, key),
Self::Kusama(client) => client.child_storage(id, child_info, key),
Self::Rococo(client) => client.child_storage(id, child_info, key),
with_client! {
self,
client,
{
client.child_storage(id, child_info, key)
}
}
}
@@ -353,11 +422,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
child_info: &ChildInfo,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<StorageKey>> {
match self {
Self::Polkadot(client) => client.child_storage_keys(id, child_info, key_prefix),
Self::Westend(client) => client.child_storage_keys(id, child_info, key_prefix),
Self::Kusama(client) => client.child_storage_keys(id, child_info, key_prefix),
Self::Rococo(client) => client.child_storage_keys(id, child_info, key_prefix),
with_client! {
self,
client,
{
client.child_storage_keys(id, child_info, key_prefix)
}
}
}
@@ -367,11 +437,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
match self {
Self::Polkadot(client) => client.child_storage_hash(id, child_info, key),
Self::Westend(client) => client.child_storage_hash(id, child_info, key),
Self::Kusama(client) => client.child_storage_hash(id, child_info, key),
Self::Rococo(client) => client.child_storage_hash(id, child_info, key),
with_client! {
self,
client,
{
client.child_storage_hash(id, child_info, key)
}
}
}
@@ -380,11 +451,12 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
first: NumberFor<Block>,
last: BlockId<Block>,
) -> sp_blockchain::Result<Option<(NumberFor<Block>, BlockId<Block>)>> {
match self {
Self::Polkadot(client) => client.max_key_changes_range(first, last),
Self::Westend(client) => client.max_key_changes_range(first, last),
Self::Kusama(client) => client.max_key_changes_range(first, last),
Self::Rococo(client) => client.max_key_changes_range(first, last),
with_client! {
self,
client,
{
client.max_key_changes_range(first, last)
}
}
}
@@ -395,58 +467,64 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
storage_key: Option<&PrefixedStorageKey>,
key: &StorageKey,
) -> sp_blockchain::Result<Vec<(NumberFor<Block>, u32)>> {
match self {
Self::Polkadot(client) => client.key_changes(first, last, storage_key, key),
Self::Westend(client) => client.key_changes(first, last, storage_key, key),
Self::Kusama(client) => client.key_changes(first, last, storage_key, key),
Self::Rococo(client) => client.key_changes(first, last, storage_key, key),
with_client! {
self,
client,
{
client.key_changes(first, last, storage_key, key)
}
}
}
}
impl sp_blockchain::HeaderBackend<Block> for Client {
fn header(&self, id: BlockId<Block>) -> sp_blockchain::Result<Option<Header>> {
match self {
Self::Polkadot(client) => client.header(&id),
Self::Westend(client) => client.header(&id),
Self::Kusama(client) => client.header(&id),
Self::Rococo(client) => client.header(&id),
with_client! {
self,
client,
{
client.header(&id)
}
}
}
fn info(&self) -> sp_blockchain::Info<Block> {
match self {
Self::Polkadot(client) => client.info(),
Self::Westend(client) => client.info(),
Self::Kusama(client) => client.info(),
Self::Rococo(client) => client.info(),
with_client! {
self,
client,
{
client.info()
}
}
}
fn status(&self, id: BlockId<Block>) -> sp_blockchain::Result<sp_blockchain::BlockStatus> {
match self {
Self::Polkadot(client) => client.status(id),
Self::Westend(client) => client.status(id),
Self::Kusama(client) => client.status(id),
Self::Rococo(client) => client.status(id),
with_client! {
self,
client,
{
client.status(id)
}
}
}
fn number(&self, hash: Hash) -> sp_blockchain::Result<Option<BlockNumber>> {
match self {
Self::Polkadot(client) => client.number(hash),
Self::Westend(client) => client.number(hash),
Self::Kusama(client) => client.number(hash),
Self::Rococo(client) => client.number(hash),
with_client! {
self,
client,
{
client.number(hash)
}
}
}
fn hash(&self, number: BlockNumber) -> sp_blockchain::Result<Option<Hash>> {
match self {
Self::Polkadot(client) => client.hash(number),
Self::Westend(client) => client.hash(number),
Self::Kusama(client) => client.hash(number),
Self::Rococo(client) => client.hash(number),
with_client! {
self,
client,
{
client.hash(number)
}
}
}
}
+18 -5
View File
@@ -56,7 +56,6 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
# Substrate Other
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -72,6 +71,7 @@ kvdb-rocksdb = { version = "0.11.0", optional = true }
# Polkadot
polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" }
polkadot-overseer = { path = "../overseer" }
polkadot-client = { path = "../client" }
polkadot-parachain = { path = "../../parachain" }
polkadot-primitives = { path = "../../primitives" }
polkadot-node-primitives = { path = "../primitives" }
@@ -82,9 +82,9 @@ polkadot-runtime-parachains = { path = "../../runtime/parachains" }
# Polkadot Runtimes
polkadot-runtime = { path = "../../runtime/polkadot" }
kusama-runtime = { path = "../../runtime/kusama" }
westend-runtime = { path = "../../runtime/westend" }
rococo-runtime = { path = "../../runtime/rococo" }
kusama-runtime = { path = "../../runtime/kusama", optional = true }
westend-runtime = { path = "../../runtime/westend", optional = true }
rococo-runtime = { path = "../../runtime/rococo", optional = true }
# Polkadot Subsystems
polkadot-availability-bitfield-distribution = { path = "../network/bitfield-distribution", optional = true }
@@ -111,7 +111,11 @@ env_logger = "0.8.2"
[features]
default = ["db", "full-node"]
db = ["service/db"]
db = [
"service/db"
]
full-node = [
"polkadot-node-core-av-store",
"polkadot-node-core-approval-voting",
@@ -134,6 +138,15 @@ full-node = [
"kvdb-rocksdb"
]
light-node = []
# Configure the native runtimes to use. Polkadot is always enabled by default.
#
# Validators require the native runtime currently
kusama-native = [ "kusama-runtime", "polkadot-client/kusama" ]
westend-native = [ "westend-runtime", "polkadot-client/westend" ]
rococo-native = [ "rococo-runtime", "polkadot-client/rococo" ]
runtime-benchmarks = [
"polkadot-runtime/runtime-benchmarks",
"kusama-runtime/runtime-benchmarks",
+79 -12
View File
@@ -16,33 +16,40 @@
//! Polkadot chain configurations.
use rococo::constants::size::MAX_CODE_SIZE;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use beefy_primitives::ecdsa::AuthorityId as BeefyId;
use grandpa::AuthorityId as GrandpaId;
use hex_literal::hex;
#[cfg(feature = "kusama-native")]
use kusama_runtime as kusama;
#[cfg(feature = "kusama-native")]
use kusama_runtime::constants::currency::UNITS as KSM;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_staking::Forcing;
use polkadot::constants::currency::UNITS as DOT;
use polkadot_node_primitives::MAX_POV_SIZE;
use polkadot_primitives::v1::{AccountId, AccountPublic, AssignmentId, ValidatorId, BlockNumber};
use polkadot_primitives::v1::{AccountId, AccountPublic, AssignmentId, ValidatorId};
use polkadot_runtime as polkadot;
#[cfg(feature = "rococo-native")]
use rococo_runtime as rococo;
#[cfg(feature = "rococo-native")]
use rococo_runtime::constants::currency::UNITS as ROC;
use sc_chain_spec::{ChainSpecExtension, ChainType};
use serde::{Deserialize, Serialize};
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::{traits::IdentifyAccount, Perbill};
use telemetry::TelemetryEndpoints;
#[cfg(feature = "westend-native")]
use westend_runtime as westend;
#[cfg(feature = "westend-native")]
use westend_runtime::constants::currency::UNITS as WND;
const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
#[cfg(feature = "kusama-native")]
const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
#[cfg(feature = "westend-native")]
const WESTEND_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
#[cfg(feature = "rococo-native")]
const ROCOCO_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
const DEFAULT_PROTOCOL_ID: &str = "dot";
@@ -63,16 +70,35 @@ pub struct Extensions {
pub type PolkadotChainSpec = service::GenericChainSpec<polkadot::GenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the kusama runtime.
#[cfg(feature = "kusama-native")]
pub type KusamaChainSpec = service::GenericChainSpec<kusama::GenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the kusama runtime.
// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime.
#[cfg(not(feature = "kusama-native"))]
pub type KusamaChainSpec = PolkadotChainSpec;
/// The `ChainSpec` parameterized for the westend runtime.
#[cfg(feature = "westend-native")]
pub type WestendChainSpec = service::GenericChainSpec<westend::GenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the westend runtime.
// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime.
#[cfg(not(feature = "westend-native"))]
pub type WestendChainSpec = PolkadotChainSpec;
/// The `ChainSpec` parameterized for the rococo runtime.
#[cfg(feature = "rococo-native")]
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
/// The `ChainSpec` parameterized for the rococo runtime.
// This actually uses the polkadot chain spec, but that is fine when we don't have the native runtime.
#[cfg(not(feature = "rococo-native"))]
pub type RococoChainSpec = PolkadotChainSpec;
/// Extension for the Rococo genesis config to support a custom changes to the genesis state.
#[derive(serde::Serialize, serde::Deserialize)]
#[cfg(feature = "rococo-native")]
pub struct RococoGenesisExt {
/// The runtime genesis config.
runtime_genesis_config: rococo::GenesisConfig,
@@ -82,6 +108,7 @@ pub struct RococoGenesisExt {
session_length_in_blocks: Option<u32>,
}
#[cfg(feature = "rococo-native")]
impl sp_runtime::BuildStorage for RococoGenesisExt {
fn assimilate_storage(
&self,
@@ -104,21 +131,27 @@ pub fn kusama_config() -> Result<KusamaChainSpec, String> {
KusamaChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..])
}
pub fn westend_config() -> Result<PolkadotChainSpec, String> {
PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/westend.json")[..])
pub fn westend_config() -> Result<WestendChainSpec, String> {
WestendChainSpec::from_json_bytes(&include_bytes!("../res/westend.json")[..])
}
pub fn rococo_config() -> Result<PolkadotChainSpec, String> {
PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/rococo.json")[..])
pub fn rococo_config() -> Result<RococoChainSpec, String> {
RococoChainSpec::from_json_bytes(&include_bytes!("../res/rococo.json")[..])
}
/// This is a temporary testnet that uses the same runtime as rococo.
pub fn wococo_config() -> Result<PolkadotChainSpec, String> {
PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/wococo.json")[..])
pub fn wococo_config() -> Result<RococoChainSpec, String> {
RococoChainSpec::from_json_bytes(&include_bytes!("../res/wococo.json")[..])
}
/// The default parachains host configuration.
fn default_parachains_host_configuration() -> polkadot_runtime_parachains::configuration::HostConfiguration<BlockNumber> {
#[cfg(any(feature = "rococo-native", feature = "kusama-native", feature = "westend-native"))]
fn default_parachains_host_configuration() ->
polkadot_runtime_parachains::configuration::HostConfiguration<polkadot_primitives::v1::BlockNumber>
{
use polkadot_node_primitives::MAX_POV_SIZE;
use polkadot_primitives::v1::MAX_CODE_SIZE;
polkadot_runtime_parachains::configuration::HostConfiguration {
validation_upgrade_frequency: 1u32,
validation_upgrade_delay: 1,
@@ -179,6 +212,7 @@ fn polkadot_session_keys(
}
}
#[cfg(feature = "kusama-native")]
fn kusama_session_keys(
babe: BabeId,
grandpa: GrandpaId,
@@ -197,6 +231,7 @@ fn kusama_session_keys(
}
}
#[cfg(feature = "westend-native")]
fn westend_session_keys(
babe: BabeId,
grandpa: GrandpaId,
@@ -215,6 +250,7 @@ fn westend_session_keys(
}
}
#[cfg(feature = "rococo-native")]
fn rococo_session_keys(
babe: BabeId,
grandpa: GrandpaId,
@@ -331,7 +367,11 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Gene
}
}
#[cfg(feature = "westend-native")]
fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::GenesisConfig {
use hex_literal::hex;
use sp_core::crypto::UncheckedInto;
// subkey inspect "$SECRET"
let endowed_accounts = vec![
// 5DaVh5WRfazkGaKhx1jUu6hjz7EmRe4dtW6PKeVLim84KLe8
@@ -492,7 +532,11 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Genesi
}
}
#[cfg(feature = "kusama-native")]
fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisConfig {
use hex_literal::hex;
use sp_core::crypto::UncheckedInto;
// subkey inspect "$SECRET"
let endowed_accounts = vec![
// 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz
@@ -698,7 +742,11 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
}
}
#[cfg(feature = "rococo-native")]
fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::GenesisConfig {
use hex_literal::hex;
use sp_core::crypto::UncheckedInto;
// subkey inspect "$SECRET"
let endowed_accounts = vec![
// 5FeyRQmjtdHoPH56ASFW76AJEP1yaQC1K9aEMvJTF9nzt9S9
@@ -967,6 +1015,7 @@ pub fn polkadot_staging_testnet_config() -> Result<PolkadotChainSpec, String> {
}
/// Staging testnet config.
#[cfg(feature = "kusama-native")]
pub fn kusama_staging_testnet_config() -> Result<KusamaChainSpec, String> {
let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?;
let boot_nodes = vec![];
@@ -988,6 +1037,7 @@ pub fn kusama_staging_testnet_config() -> Result<KusamaChainSpec, String> {
}
/// Westend staging testnet config.
#[cfg(feature = "westend-native")]
pub fn westend_staging_testnet_config() -> Result<WestendChainSpec, String> {
let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?;
let boot_nodes = vec![];
@@ -1009,6 +1059,7 @@ pub fn westend_staging_testnet_config() -> Result<WestendChainSpec, String> {
}
/// Rococo staging testnet config.
#[cfg(feature = "rococo-native")]
pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?;
let boot_nodes = vec![];
@@ -1208,6 +1259,7 @@ pub fn polkadot_testnet_genesis(
}
/// Helper function to create kusama GenesisConfig for testing
#[cfg(feature = "kusama-native")]
pub fn kusama_testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(
@@ -1311,6 +1363,7 @@ pub fn kusama_testnet_genesis(
}
/// Helper function to create westend GenesisConfig for testing
#[cfg(feature = "westend-native")]
pub fn westend_testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(
@@ -1398,6 +1451,7 @@ pub fn westend_testnet_genesis(
}
/// Helper function to create rococo GenesisConfig for testing
#[cfg(feature = "rococo-native")]
pub fn rococo_testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(
@@ -1485,6 +1539,7 @@ fn polkadot_development_config_genesis(wasm_binary: &[u8]) -> polkadot::GenesisC
)
}
#[cfg(feature = "kusama-native")]
fn kusama_development_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisConfig {
kusama_testnet_genesis(
wasm_binary,
@@ -1494,6 +1549,7 @@ fn kusama_development_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisConfi
)
}
#[cfg(feature = "westend-native")]
fn westend_development_config_genesis(wasm_binary: &[u8]) -> westend::GenesisConfig {
westend_testnet_genesis(
wasm_binary,
@@ -1503,6 +1559,7 @@ fn westend_development_config_genesis(wasm_binary: &[u8]) -> westend::GenesisCon
)
}
#[cfg(feature = "rococo-native")]
fn rococo_development_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::GenesisConfig {
rococo_testnet_genesis(
wasm_binary,
@@ -1530,6 +1587,7 @@ pub fn polkadot_development_config() -> Result<PolkadotChainSpec, String> {
}
/// Kusama development config (single validator Alice)
#[cfg(feature = "kusama-native")]
pub fn kusama_development_config() -> Result<KusamaChainSpec, String> {
let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?;
@@ -1547,6 +1605,7 @@ pub fn kusama_development_config() -> Result<KusamaChainSpec, String> {
}
/// Westend development config (single validator Alice)
#[cfg(feature = "westend-native")]
pub fn westend_development_config() -> Result<WestendChainSpec, String> {
let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?;
@@ -1564,6 +1623,7 @@ pub fn westend_development_config() -> Result<WestendChainSpec, String> {
}
/// Rococo development config (single validator Alice)
#[cfg(feature = "rococo-native")]
pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?;
@@ -1585,6 +1645,7 @@ pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
}
/// Wococo development config (single validator Alice)
#[cfg(feature = "rococo-native")]
pub fn wococo_development_config() -> Result<RococoChainSpec, String> {
const WOCOCO_DEV_PROTOCOL_ID: &str = "woco";
let wasm_binary = rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?;
@@ -1635,6 +1696,7 @@ pub fn polkadot_local_testnet_config() -> Result<PolkadotChainSpec, String> {
))
}
#[cfg(feature = "kusama-native")]
fn kusama_local_testnet_genesis(wasm_binary: &[u8]) -> kusama::GenesisConfig {
kusama_testnet_genesis(
wasm_binary,
@@ -1648,6 +1710,7 @@ fn kusama_local_testnet_genesis(wasm_binary: &[u8]) -> kusama::GenesisConfig {
}
/// Kusama local testnet config (multivalidator Alice + Bob)
#[cfg(feature = "kusama-native")]
pub fn kusama_local_testnet_config() -> Result<KusamaChainSpec, String> {
let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?;
@@ -1664,6 +1727,7 @@ pub fn kusama_local_testnet_config() -> Result<KusamaChainSpec, String> {
))
}
#[cfg(feature = "westend-native")]
fn westend_local_testnet_genesis(wasm_binary: &[u8]) -> westend::GenesisConfig {
westend_testnet_genesis(
wasm_binary,
@@ -1677,6 +1741,7 @@ fn westend_local_testnet_genesis(wasm_binary: &[u8]) -> westend::GenesisConfig {
}
/// Westend local testnet config (multivalidator Alice + Bob)
#[cfg(feature = "westend-native")]
pub fn westend_local_testnet_config() -> Result<WestendChainSpec, String> {
let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?;
@@ -1693,6 +1758,7 @@ pub fn westend_local_testnet_config() -> Result<WestendChainSpec, String> {
))
}
#[cfg(feature = "rococo-native")]
fn rococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::GenesisConfig {
rococo_testnet_genesis(
wasm_binary,
@@ -1706,6 +1772,7 @@ fn rococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::GenesisCo
}
/// Rococo local testnet config (multivalidator Alice + Bob)
#[cfg(feature = "rococo-native")]
pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?;
+75 -65
View File
@@ -20,7 +20,6 @@
pub mod chain_spec;
mod grandpa_support;
mod client;
mod parachains_db;
#[cfg(feature = "full-node")]
@@ -53,11 +52,22 @@ use std::sync::Arc;
use std::time::Duration;
use prometheus_endpoint::Registry;
use sc_executor::native_executor_instance;
use service::RpcHandlers;
use telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};
pub use self::client::{AbstractClient, Client, ClientHandle, ExecuteWithClient, RuntimeApiCollection};
#[cfg(feature = "rococo-native")]
pub use polkadot_client::RococoExecutor;
#[cfg(feature = "westend-native")]
pub use polkadot_client::WestendExecutor;
#[cfg(feature = "kusama-native")]
pub use polkadot_client::KusamaExecutor;
pub use polkadot_client::{
PolkadotExecutor, FullBackend, FullClient, AbstractClient, Client, ClientHandle, ExecuteWithClient,
RuntimeApiCollection,
};
pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec, RococoChainSpec};
pub use consensus_common::{Proposal, SelectChain, BlockImport, block_validation::Chain};
pub use polkadot_primitives::v1::{Block, BlockId, CollatorPair, Hash, Id as ParaId};
@@ -73,42 +83,17 @@ pub use service::config::{DatabaseConfig, PrometheusConfig};
pub use sp_api::{ApiRef, Core as CoreApi, ConstructRuntimeApi, ProvideRuntimeApi, StateBackend};
pub use sp_runtime::traits::{DigestFor, HashFor, NumberFor, Block as BlockT, self as runtime_traits, BlakeTwo256};
#[cfg(feature = "kusama-native")]
pub use kusama_runtime;
pub use polkadot_runtime;
#[cfg(feature = "rococo-native")]
pub use rococo_runtime;
#[cfg(feature = "westend-native")]
pub use westend_runtime;
/// The maximum number of active leaves we forward to the [`Overseer`] on startup.
const MAX_ACTIVE_LEAVES: usize = 4;
native_executor_instance!(
pub PolkadotExecutor,
polkadot_runtime::api::dispatch,
polkadot_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
native_executor_instance!(
pub KusamaExecutor,
kusama_runtime::api::dispatch,
kusama_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
native_executor_instance!(
pub WestendExecutor,
westend_runtime::api::dispatch,
westend_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
native_executor_instance!(
pub RococoExecutor,
rococo_runtime::api::dispatch,
rococo_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
@@ -209,17 +194,17 @@ fn jaeger_launch_collector_with_agent(spawner: impl SpawnNamed, config: &Configu
Ok(())
}
pub type FullBackend = service::TFullBackend<Block>;
#[cfg(feature = "full-node")]
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
pub type FullClient<RuntimeApi, Executor> = service::TFullClient<Block, RuntimeApi, Executor>;
#[cfg(feature = "full-node")]
type FullGrandpaBlockImport<RuntimeApi, Executor> = grandpa::GrandpaBlockImport<
FullBackend, Block, FullClient<RuntimeApi, Executor>, FullSelectChain
>;
#[cfg(feature = "light-node")]
type LightBackend = service::TLightBackendWithHash<Block, sp_runtime::traits::BlakeTwo256>;
#[cfg(feature = "light-node")]
type LightClient<RuntimeApi, Executor> =
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;
@@ -975,7 +960,7 @@ pub fn new_full<RuntimeApi, Executor>(
min_block_delta: if chain_spec.is_wococo() { 4 } else { 8 },
prometheus_registry: prometheus_registry.clone(),
};
let gadget = beefy_gadget::start_beefy_gadget::<_, beefy_primitives::ecdsa::AuthorityPair, _, _, _>(
beefy_params
);
@@ -1069,6 +1054,7 @@ pub fn new_full<RuntimeApi, Executor>(
}
/// Builds a new service for a light client.
#[cfg(feature = "light-node")]
fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
TaskManager,
RpcHandlers,
@@ -1239,39 +1225,56 @@ pub fn new_chain_ops(
>
{
config.keystore = service::config::KeystoreConfig::InMemory;
#[cfg(feature = "rococo-native")]
if config.chain_spec.is_rococo() || config.chain_spec.is_wococo() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<rococo_runtime::RuntimeApi, RococoExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Rococo(client)), backend, import_queue, task_manager))
} else if config.chain_spec.is_kusama() {
return Ok((Arc::new(Client::Rococo(client)), backend, import_queue, task_manager))
}
#[cfg(feature = "kusama-native")]
if config.chain_spec.is_kusama() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<kusama_runtime::RuntimeApi, KusamaExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Kusama(client)), backend, import_queue, task_manager))
} else if config.chain_spec.is_westend() {
return Ok((Arc::new(Client::Kusama(client)), backend, import_queue, task_manager))
}
#[cfg(feature = "westend-native")]
if config.chain_spec.is_westend() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<westend_runtime::RuntimeApi, WestendExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Westend(client)), backend, import_queue, task_manager))
} else {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager))
return Ok((Arc::new(Client::Westend(client)), backend, import_queue, task_manager))
}
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager))
}
/// Build a new light node.
#[cfg(feature = "light-node")]
pub fn build_light(config: Configuration) -> Result<(
TaskManager,
RpcHandlers,
), Error> {
#[cfg(feature = "rococo-native")]
if config.chain_spec.is_rococo() || config.chain_spec.is_wococo() {
new_light::<rococo_runtime::RuntimeApi, RococoExecutor>(config)
} else if config.chain_spec.is_kusama() {
new_light::<kusama_runtime::RuntimeApi, KusamaExecutor>(config)
} else if config.chain_spec.is_westend() {
new_light::<westend_runtime::RuntimeApi, WestendExecutor>(config)
} else {
new_light::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config)
return new_light::<rococo_runtime::RuntimeApi, RococoExecutor>(config)
}
#[cfg(feature = "kusama-native")]
if config.chain_spec.is_kusama() {
return new_light::<kusama_runtime::RuntimeApi, KusamaExecutor>(config)
}
#[cfg(feature = "westend-native")]
if config.chain_spec.is_westend() {
return new_light::<westend_runtime::RuntimeApi, WestendExecutor>(config)
}
new_light::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config)
}
#[cfg(feature = "full-node")]
@@ -1283,8 +1286,9 @@ pub fn build_full(
jaeger_agent: Option<std::net::SocketAddr>,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<NewFull<Client>, Error> {
#[cfg(feature = "rococo-native")]
if config.chain_spec.is_rococo() || config.chain_spec.is_wococo() {
new_full::<rococo_runtime::RuntimeApi, RococoExecutor>(
return new_full::<rococo_runtime::RuntimeApi, RococoExecutor>(
config,
is_collator,
grandpa_pause,
@@ -1293,8 +1297,11 @@ pub fn build_full(
telemetry_worker_handle,
None,
).map(|full| full.with_client(Client::Rococo))
} else if config.chain_spec.is_kusama() {
new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
}
#[cfg(feature = "kusama-native")]
if config.chain_spec.is_kusama() {
return new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
config,
is_collator,
grandpa_pause,
@@ -1303,8 +1310,11 @@ pub fn build_full(
telemetry_worker_handle,
None,
).map(|full| full.with_client(Client::Kusama))
} else if config.chain_spec.is_westend() {
new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
}
#[cfg(feature = "westend-native")]
if config.chain_spec.is_westend() {
return new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
config,
is_collator,
grandpa_pause,
@@ -1313,15 +1323,15 @@ pub fn build_full(
telemetry_worker_handle,
None,
).map(|full| full.with_client(Client::Westend))
} else {
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
is_collator,
grandpa_pause,
disable_beefy,
jaeger_agent,
telemetry_worker_handle,
None,
).map(|full| full.with_client(Client::Polkadot))
}
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
is_collator,
grandpa_pause,
disable_beefy,
jaeger_agent,
telemetry_worker_handle,
None,
).map(|full| full.with_client(Client::Polkadot))
}
@@ -23,7 +23,7 @@ structopt = "0.3.21"
test-parachain-adder = { path = ".." }
polkadot-primitives = { path = "../../../../primitives" }
polkadot-cli = { path = "../../../../cli" }
polkadot-service = { path = "../../../../node/service" }
polkadot-service = { path = "../../../../node/service", features = [ "rococo-native" ] }
polkadot-node-primitives = { path = "../../../../node/primitives" }
polkadot-node-subsystem = { path = "../../../../node/subsystem" }
+1 -1
View File
@@ -22,6 +22,6 @@ use color_eyre::eyre;
fn main() -> eyre::Result<()> {
color_eyre::install()?;
cli::run()?;
polkadot_cli::run()?;
Ok(())
}