mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Support both polkadot and kusama runtimes (#704)
* Allow both polkadot and kusama runtimes * Allow both polkadot and kusama runtimes * Make `collator` build * Removed kusama runtime * Introduced common runtime * Updated for latest substrate * Updated CI targets * Updated CI version check * Removed unused dependency * Pulled latests substrate * Pulled latest substrate * Fixed version * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * NEW_HEADS_IDENTIFIER moved to primitives * Updated CI check script * Fixed script * Set epoch duration for polkadot * ci: check_runtime for both runtimes Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: gabriel klawitter <gabreal@users.noreply.github.com>
This commit is contained in:
committed by
Gavin Wood
parent
9a9bbd1c2d
commit
a00d74d825
@@ -15,13 +15,14 @@ hex-literal = "0.2.1"
|
||||
av_store = { package = "polkadot-availability-store", path = "../availability-store" }
|
||||
consensus = { package = "polkadot-validation", path = "../validation" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
polkadot-executor = { path = "../executor" }
|
||||
polkadot-runtime = { path = "../runtime/polkadot" }
|
||||
kusama-runtime = { path = "../runtime/kusama" }
|
||||
polkadot-network = { path = "../network" }
|
||||
polkadot-rpc = { path = "../rpc" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
client = { package = "sc-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
client-api = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
@@ -34,16 +35,22 @@ grandpa_primitives = { package = "sp-finality-grandpa", git = "https://github.co
|
||||
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
service = { package = "sc-service", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
telemetry = { package = "sc-telemetry", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
txpool = { package = "sc-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
txpool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
pallet-babe = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
pallet-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
im-online = { package = "pallet-im-online", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
im-online = { package = "pallet-im-online", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
authority-discovery = { package = "sc-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
authority-discovery-primitives = { package = "sp-authority-discovery", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
babe = { package = "sc-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
system_rpc_runtime_api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
codec = { package = "parity-scale-codec", version = "1.1.0" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
sp-offchain = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
|
||||
[features]
|
||||
default = ["rocksdb"]
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
|
||||
use primitives::{Pair, Public, crypto::UncheckedInto, sr25519};
|
||||
use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId};
|
||||
use polkadot_runtime::{
|
||||
AuthorityDiscoveryConfig, GenesisConfig, CouncilConfig, DemocracyConfig, SystemConfig,
|
||||
SessionConfig, StakingConfig, BalancesConfig, SessionKeys, TechnicalCommitteeConfig,
|
||||
IndicesConfig, StakerStatus, WASM_BINARY, ClaimsConfig, ParachainsConfig, RegistrarConfig
|
||||
};
|
||||
use polkadot_runtime as polkadot;
|
||||
use polkadot_runtime::constants::currency::DOTS;
|
||||
use sp_runtime::{traits::IdentifyAccount, Perbill};
|
||||
use telemetry::TelemetryEndpoints;
|
||||
@@ -36,8 +32,11 @@ use pallet_staking::Forcing;
|
||||
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
|
||||
const DEFAULT_PROTOCOL_ID: &str = "dot";
|
||||
|
||||
/// Specialised `ChainSpec`.
|
||||
pub type ChainSpec = ::service::ChainSpec<GenesisConfig>;
|
||||
/// The `ChainSpec`.
|
||||
///
|
||||
/// We use the same `ChainSpec` type for Polkadot and Kusama. As Kusama
|
||||
/// is only loaded from a file, the `GenesisConfig` type is not used.
|
||||
pub type ChainSpec = service::ChainSpec<polkadot::GenesisConfig>;
|
||||
|
||||
pub fn kusama_config() -> Result<ChainSpec, String> {
|
||||
ChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..])
|
||||
@@ -49,11 +48,11 @@ fn session_keys(
|
||||
im_online: ImOnlineId,
|
||||
parachain_validator: ValidatorId,
|
||||
authority_discovery: AuthorityDiscoveryId
|
||||
) -> SessionKeys {
|
||||
SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery }
|
||||
) -> polkadot::SessionKeys {
|
||||
polkadot::SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery }
|
||||
}
|
||||
|
||||
fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
fn staging_testnet_config_genesis() -> polkadot::GenesisConfig {
|
||||
// subkey inspect "$SECRET"
|
||||
let endowed_accounts = vec![
|
||||
// 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz
|
||||
@@ -138,45 +137,48 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
const ENDOWMENT: u128 = 1_000_000 * DOTS;
|
||||
const STASH: u128 = 100 * DOTS;
|
||||
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
code: WASM_BINARY.to_vec(),
|
||||
polkadot::GenesisConfig {
|
||||
system: Some(polkadot::SystemConfig {
|
||||
code: polkadot::WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
balances: Some(BalancesConfig {
|
||||
balances: Some(polkadot::BalancesConfig {
|
||||
balances: endowed_accounts.iter()
|
||||
.map(|k: &AccountId| (k.clone(), ENDOWMENT))
|
||||
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
|
||||
.collect(),
|
||||
vesting: vec![],
|
||||
}),
|
||||
indices: Some(IndicesConfig {
|
||||
indices: Some(polkadot::IndicesConfig {
|
||||
ids: endowed_accounts.iter().cloned()
|
||||
.chain(initial_authorities.iter().map(|x| x.0.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
}),
|
||||
session: Some(SessionConfig {
|
||||
session: Some(polkadot::SessionConfig {
|
||||
keys: initial_authorities.iter().map(|x| (
|
||||
x.0.clone(),
|
||||
session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
|
||||
)).collect::<Vec<_>>(),
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
staking: Some(polkadot::StakingConfig {
|
||||
current_era: 0,
|
||||
validator_count: 50,
|
||||
minimum_validator_count: 4,
|
||||
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
|
||||
stakers: initial_authorities
|
||||
.iter()
|
||||
.map(|x| (x.0.clone(), x.1.clone(), STASH, polkadot::StakerStatus::Validator))
|
||||
.collect(),
|
||||
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
|
||||
force_era: Forcing::ForceNone,
|
||||
slash_reward_fraction: Perbill::from_percent(10),
|
||||
.. Default::default()
|
||||
}),
|
||||
democracy: Some(Default::default()),
|
||||
collective_Instance1: Some(CouncilConfig {
|
||||
collective_Instance1: Some(polkadot::CouncilConfig {
|
||||
members: vec![],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
collective_Instance2: Some(TechnicalCommitteeConfig {
|
||||
collective_Instance2: Some(polkadot::TechnicalCommitteeConfig {
|
||||
members: vec![],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
@@ -184,17 +186,17 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
babe: Some(Default::default()),
|
||||
grandpa: Some(Default::default()),
|
||||
im_online: Some(Default::default()),
|
||||
authority_discovery: Some(AuthorityDiscoveryConfig {
|
||||
authority_discovery: Some(polkadot::AuthorityDiscoveryConfig {
|
||||
keys: vec![],
|
||||
}),
|
||||
parachains: Some(ParachainsConfig {
|
||||
parachains: Some(polkadot::ParachainsConfig {
|
||||
authorities: vec![],
|
||||
}),
|
||||
registrar: Some(RegistrarConfig {
|
||||
registrar: Some(polkadot::RegistrarConfig {
|
||||
parachains: vec![],
|
||||
_phdata: Default::default(),
|
||||
}),
|
||||
claims: Some(ClaimsConfig {
|
||||
claims: Some(polkadot::ClaimsConfig {
|
||||
claims: vec![],
|
||||
vesting: vec![],
|
||||
})
|
||||
@@ -257,7 +259,7 @@ pub fn testnet_genesis(
|
||||
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId, AuthorityDiscoveryId)>,
|
||||
_root_key: AccountId,
|
||||
endowed_accounts: Option<Vec<AccountId>>,
|
||||
) -> GenesisConfig {
|
||||
) -> polkadot::GenesisConfig {
|
||||
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
@@ -278,42 +280,42 @@ pub fn testnet_genesis(
|
||||
const ENDOWMENT: u128 = 1_000_000 * DOTS;
|
||||
const STASH: u128 = 100 * DOTS;
|
||||
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
code: WASM_BINARY.to_vec(),
|
||||
polkadot::GenesisConfig {
|
||||
system: Some(polkadot::SystemConfig {
|
||||
code: polkadot::WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
indices: Some(IndicesConfig {
|
||||
indices: Some(polkadot::IndicesConfig {
|
||||
ids: endowed_accounts.clone(),
|
||||
}),
|
||||
balances: Some(BalancesConfig {
|
||||
balances: Some(polkadot::BalancesConfig {
|
||||
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
|
||||
vesting: vec![],
|
||||
}),
|
||||
session: Some(SessionConfig {
|
||||
session: Some(polkadot::SessionConfig {
|
||||
keys: initial_authorities.iter().map(|x| (
|
||||
x.0.clone(),
|
||||
session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()),
|
||||
)).collect::<Vec<_>>(),
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
staking: Some(polkadot::StakingConfig {
|
||||
current_era: 0,
|
||||
minimum_validator_count: 1,
|
||||
validator_count: 2,
|
||||
stakers: initial_authorities.iter()
|
||||
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
|
||||
.map(|x| (x.0.clone(), x.1.clone(), STASH, polkadot::StakerStatus::Validator))
|
||||
.collect(),
|
||||
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
|
||||
force_era: Forcing::NotForcing,
|
||||
slash_reward_fraction: Perbill::from_percent(10),
|
||||
.. Default::default()
|
||||
}),
|
||||
democracy: Some(DemocracyConfig::default()),
|
||||
collective_Instance1: Some(CouncilConfig {
|
||||
democracy: Some(polkadot::DemocracyConfig::default()),
|
||||
collective_Instance1: Some(polkadot::CouncilConfig {
|
||||
members: vec![],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
collective_Instance2: Some(TechnicalCommitteeConfig {
|
||||
collective_Instance2: Some(polkadot::TechnicalCommitteeConfig {
|
||||
members: vec![],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
@@ -321,17 +323,17 @@ pub fn testnet_genesis(
|
||||
babe: Some(Default::default()),
|
||||
grandpa: Some(Default::default()),
|
||||
im_online: Some(Default::default()),
|
||||
authority_discovery: Some(AuthorityDiscoveryConfig {
|
||||
authority_discovery: Some(polkadot::AuthorityDiscoveryConfig {
|
||||
keys: vec![],
|
||||
}),
|
||||
parachains: Some(ParachainsConfig {
|
||||
parachains: Some(polkadot::ParachainsConfig {
|
||||
authorities: vec![],
|
||||
}),
|
||||
registrar: Some(RegistrarConfig{
|
||||
registrar: Some(polkadot::RegistrarConfig{
|
||||
parachains: vec![],
|
||||
_phdata: Default::default(),
|
||||
}),
|
||||
claims: Some(ClaimsConfig {
|
||||
claims: Some(polkadot::ClaimsConfig {
|
||||
claims: vec![],
|
||||
vesting: vec![],
|
||||
})
|
||||
@@ -339,7 +341,7 @@ pub fn testnet_genesis(
|
||||
}
|
||||
|
||||
|
||||
fn development_config_genesis() -> GenesisConfig {
|
||||
fn development_config_genesis() -> polkadot::GenesisConfig {
|
||||
testnet_genesis(
|
||||
vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
@@ -363,7 +365,7 @@ pub fn development_config() -> ChainSpec {
|
||||
)
|
||||
}
|
||||
|
||||
fn local_testnet_genesis() -> GenesisConfig {
|
||||
fn local_testnet_genesis() -> polkadot::GenesisConfig {
|
||||
testnet_genesis(
|
||||
vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
|
||||
+191
-43
@@ -23,30 +23,35 @@ use futures::{FutureExt, TryFutureExt, task::{Spawn, SpawnError, FutureObj}};
|
||||
use client::LongestChain;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use polkadot_primitives::{parachain, Hash, BlockId};
|
||||
use polkadot_runtime::GenesisConfig;
|
||||
use polkadot_primitives::{parachain, Hash, BlockId, AccountId, Nonce, Balance};
|
||||
use polkadot_network::{gossip::{self as network_gossip, Known}, validation::ValidationNetwork};
|
||||
use service::{error::{Error as ServiceError}, Configuration, ServiceBuilder};
|
||||
use service::{error::{Error as ServiceError}, ServiceBuilder};
|
||||
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
|
||||
use inherents::InherentDataProviders;
|
||||
use sc_executor::native_executor_instance;
|
||||
use log::info;
|
||||
pub use service::{AbstractService, Roles, PruningMode, TransactionPoolOptions, Error};
|
||||
pub use service::ServiceBuilderCommand;
|
||||
pub use service::{
|
||||
AbstractService, Roles, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis, ServiceBuilderCommand,
|
||||
TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor,
|
||||
};
|
||||
pub use service::config::{DatabaseConfig, full_version_from_strs};
|
||||
pub use client::{ExecutionStrategy, CallExecutor};
|
||||
pub use sc_executor::NativeExecutionDispatch;
|
||||
pub use client::{ExecutionStrategy, CallExecutor, Client};
|
||||
pub use client_api::backend::Backend;
|
||||
pub use sp_api::{Core as CoreApi, ConstructRuntimeApi};
|
||||
pub use consensus_common::SelectChain;
|
||||
pub use polkadot_network::{PolkadotProtocol};
|
||||
pub use polkadot_primitives::parachain::{CollatorId, ParachainHost};
|
||||
pub use polkadot_primitives::Block;
|
||||
pub use polkadot_runtime::RuntimeApi;
|
||||
pub use primitives::Blake2Hasher;
|
||||
pub use sp_runtime::traits::ProvideRuntimeApi;
|
||||
pub use sp_runtime::traits::{Block as BlockT, ProvideRuntimeApi, self as runtime_traits};
|
||||
pub use sc_network::specialization::NetworkSpecialization;
|
||||
pub use chain_spec::ChainSpec;
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub use consensus::run_validation_worker;
|
||||
pub use codec::Codec;
|
||||
pub use polkadot_runtime;
|
||||
pub use kusama_runtime;
|
||||
|
||||
/// Wrap a futures01 executor as a futures03 spawn.
|
||||
#[derive(Clone)]
|
||||
@@ -71,50 +76,117 @@ pub struct CustomConfiguration {
|
||||
|
||||
/// Whether to enable or disable the authority discovery module.
|
||||
pub authority_discovery_enabled: bool,
|
||||
|
||||
/// Milliseconds per block.
|
||||
pub slot_duration: u64,
|
||||
}
|
||||
|
||||
/// Configuration type that is being used.
|
||||
///
|
||||
/// See [`ChainSpec`] for more information why Polkadot `GenesisConfig` is safe here.
|
||||
pub type Configuration = service::Configuration<CustomConfiguration, polkadot_runtime::GenesisConfig>;
|
||||
|
||||
impl Default for CustomConfiguration {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
collating_for: None,
|
||||
max_block_data_size: None,
|
||||
authority_discovery_enabled: false,
|
||||
slot_duration: 6000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Chain API type for the transaction pool.
|
||||
pub type TxChainApi<Backend, Executor> = txpool::FullChainApi<
|
||||
client::Client<Backend, Executor, Block, RuntimeApi>,
|
||||
Block,
|
||||
>;
|
||||
native_executor_instance!(
|
||||
pub PolkadotExecutor,
|
||||
polkadot_runtime::api::dispatch,
|
||||
polkadot_runtime::native_version
|
||||
);
|
||||
|
||||
native_executor_instance!(
|
||||
pub KusamaExecutor,
|
||||
kusama_runtime::api::dispatch,
|
||||
kusama_runtime::native_version
|
||||
);
|
||||
|
||||
/// A set of APIs that polkadot-like runtimes must implement.
|
||||
pub trait RuntimeApiCollection<Extrinsic: codec::Codec + Send + Sync + 'static> :
|
||||
sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::ApiExt<Block, Error = sp_blockchain::Error>
|
||||
+ babe_primitives::BabeApi<Block>
|
||||
+ ParachainHost<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
|
||||
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance, Extrinsic>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ authority_discovery_primitives::AuthorityDiscoveryApi<Block>
|
||||
where
|
||||
Extrinsic: RuntimeExtrinsic,
|
||||
{}
|
||||
|
||||
impl<Api, Extrinsic> RuntimeApiCollection<Extrinsic> for Api
|
||||
where
|
||||
Api:
|
||||
sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::ApiExt<Block, Error = sp_blockchain::Error>
|
||||
+ babe_primitives::BabeApi<Block>
|
||||
+ ParachainHost<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
|
||||
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance, Extrinsic>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ authority_discovery_primitives::AuthorityDiscoveryApi<Block>,
|
||||
Extrinsic: RuntimeExtrinsic,
|
||||
{}
|
||||
|
||||
pub trait RuntimeExtrinsic: codec::Codec + Send + Sync + 'static
|
||||
{}
|
||||
|
||||
impl<E> RuntimeExtrinsic for E where E: codec::Codec + Send + Sync + 'static
|
||||
{}
|
||||
|
||||
/// Can be called for a `Configuration` to check if it is a configuration for the `Kusama` network.
|
||||
pub trait IsKusama {
|
||||
/// Returns if this is a configuration for the `Kusama` network.
|
||||
fn is_kusama(&self) -> bool;
|
||||
}
|
||||
|
||||
impl IsKusama for Configuration {
|
||||
fn is_kusama(&self) -> bool {
|
||||
self.chain_spec.name().starts_with("Kusama")
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts a `ServiceBuilder` for a full service.
|
||||
///
|
||||
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||
/// be able to perform chain operations.
|
||||
macro_rules! new_full_start {
|
||||
($config:expr) => {{
|
||||
($config:expr, $runtime:ty, $executor:ty) => {{
|
||||
let mut import_setup = None;
|
||||
let inherent_data_providers = inherents::InherentDataProviders::new();
|
||||
let builder = service::ServiceBuilder::new_full::<
|
||||
Block, RuntimeApi, polkadot_executor::Executor
|
||||
Block, $runtime, $executor
|
||||
>($config)?
|
||||
.with_select_chain(|_, backend| {
|
||||
Ok(client::LongestChain::new(backend.clone()))
|
||||
})?
|
||||
.with_transaction_pool(|config, client, _fetcher| {
|
||||
let pool_api = txpool::FullChainApi::new(client.clone());
|
||||
let pool = txpool::BasicPool::new(config, pool_api);
|
||||
let maintainer = txpool::FullBasicPoolMaintainer::new(pool.pool().clone(), client);
|
||||
let maintainable_pool = txpool_api::MaintainableTransactionPool::new(pool, maintainer);
|
||||
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
|
||||
let pool = sc_transaction_pool::BasicPool::new(config, pool_api);
|
||||
let maintainer = sc_transaction_pool::FullBasicPoolMaintainer::new(pool.pool().clone(), client);
|
||||
let maintainable_pool = sp_transaction_pool::MaintainableTransactionPool::new(pool, maintainer);
|
||||
Ok(maintainable_pool)
|
||||
})?
|
||||
.with_import_queue(|_config, client, mut select_chain, _| {
|
||||
let select_chain = select_chain.take()
|
||||
.ok_or_else(|| service::Error::SelectChainRequired)?;
|
||||
let (grandpa_block_import, grandpa_link) =
|
||||
grandpa::block_import::<_, _, _, RuntimeApi, _>(
|
||||
grandpa::block_import::<_, _, _, Runtime, _>(
|
||||
client.clone(), &*client, select_chain
|
||||
)?;
|
||||
let justification_import = grandpa_block_import.clone();
|
||||
@@ -149,20 +221,60 @@ macro_rules! new_full_start {
|
||||
}
|
||||
|
||||
/// Builds a new object suitable for chain operations.
|
||||
pub fn new_chain_ops(config: Configuration<impl Send + Default + 'static, GenesisConfig>)
|
||||
pub fn new_chain_ops<Runtime, Dispatch, Extrinsic>(config: Configuration)
|
||||
-> Result<impl ServiceBuilderCommand<Block=Block>, ServiceError>
|
||||
where
|
||||
Runtime: ConstructRuntimeApi<Block, service::TFullClient<Block, Runtime, Dispatch>> + Send + Sync + 'static,
|
||||
Runtime::RuntimeApi: RuntimeApiCollection<Extrinsic>,
|
||||
Dispatch: NativeExecutionDispatch + 'static,
|
||||
Extrinsic: RuntimeExtrinsic,
|
||||
{
|
||||
Ok(new_full_start!(config).0)
|
||||
Ok(new_full_start!(config, Runtime, Dispatch).0)
|
||||
}
|
||||
|
||||
/// Create a new Polkadot service for a full node.
|
||||
pub fn polkadot_new_full(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block,
|
||||
RuntimeApi = polkadot_runtime::RuntimeApi,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TFullBackend<Block>,
|
||||
SelectChain = LongestChain<TFullBackend<Block>, Block>,
|
||||
CallExecutor = TFullCallExecutor<Block, PolkadotExecutor>,
|
||||
>, ServiceError>
|
||||
{
|
||||
new_full(config)
|
||||
}
|
||||
|
||||
/// Create a new Kusama service for a full node.
|
||||
pub fn kusama_new_full(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block,
|
||||
RuntimeApi = kusama_runtime::RuntimeApi,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TFullBackend<Block>,
|
||||
SelectChain = LongestChain<TFullBackend<Block>, Block>,
|
||||
CallExecutor = TFullCallExecutor<Block, KusamaExecutor>,
|
||||
>, ServiceError>
|
||||
{
|
||||
new_full(config)
|
||||
}
|
||||
|
||||
/// Builds a new service for a full client.
|
||||
pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block, RuntimeApi = RuntimeApi, NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = impl Backend<Block, Blake2Hasher> + 'static,
|
||||
SelectChain = impl SelectChain<Block>,
|
||||
CallExecutor = impl CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
|
||||
Block = Block,
|
||||
RuntimeApi = Runtime,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TFullBackend<Block>,
|
||||
SelectChain = LongestChain<TFullBackend<Block>, Block>,
|
||||
CallExecutor = TFullCallExecutor<Block, Dispatch>,
|
||||
>, ServiceError>
|
||||
where
|
||||
Runtime: ConstructRuntimeApi<Block, service::TFullClient<Block, Runtime, Dispatch>> + Send + Sync + 'static,
|
||||
Runtime::RuntimeApi: RuntimeApiCollection<Extrinsic>,
|
||||
Dispatch: NativeExecutionDispatch + 'static,
|
||||
Extrinsic: RuntimeExtrinsic,
|
||||
{
|
||||
use sc_network::DhtEvent;
|
||||
use futures::{compat::Stream01CompatExt, stream::StreamExt};
|
||||
@@ -180,13 +292,14 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
let name = config.name.clone();
|
||||
let authority_discovery_enabled = config.custom.authority_discovery_enabled;
|
||||
let sentry_nodes = config.network.sentry_nodes.clone();
|
||||
let slot_duration = config.custom.slot_duration;
|
||||
|
||||
// sentry nodes announce themselves as authorities to the network
|
||||
// and should run the same protocols authorities do, but it should
|
||||
// never actively participate in any consensus process.
|
||||
let participates_in_consensus = is_authority && !config.sentry_mode;
|
||||
|
||||
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
|
||||
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config, Runtime, Dispatch);
|
||||
|
||||
// Dht event channel from the network to the authority discovery module. Use
|
||||
// bounded channel to ensure back-pressure. Authority discovery is triggering one
|
||||
@@ -290,7 +403,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
Arc::new(WrappedExecutor(service.spawn_task_handle())),
|
||||
service.keystore(),
|
||||
availability_store.clone(),
|
||||
polkadot_runtime::constants::time::SLOT_DURATION,
|
||||
slot_duration,
|
||||
max_block_data_size,
|
||||
);
|
||||
|
||||
@@ -315,7 +428,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
env: proposer,
|
||||
sync_oracle: service.network(),
|
||||
inherent_data_providers: inherent_data_providers.clone(),
|
||||
force_authoring: force_authoring,
|
||||
force_authoring,
|
||||
babe_link,
|
||||
can_author_with,
|
||||
};
|
||||
@@ -367,7 +480,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
// provide better guarantees of block and vote data availability than
|
||||
// the observer.
|
||||
let grandpa_config = grandpa::GrandpaParams {
|
||||
config: config,
|
||||
config,
|
||||
link: link_half,
|
||||
network: service.network(),
|
||||
inherent_data_providers: inherent_data_providers.clone(),
|
||||
@@ -388,35 +501,70 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
Ok(service)
|
||||
}
|
||||
|
||||
/// Builds a new service for a light client.
|
||||
pub fn new_light(config: Configuration<CustomConfiguration, GenesisConfig>)
|
||||
/// Create a new Polkadot service for a light client.
|
||||
pub fn polkadot_new_light(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block, RuntimeApi = RuntimeApi, NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = impl Backend<Block, Blake2Hasher> + 'static,
|
||||
SelectChain = impl SelectChain<Block>,
|
||||
CallExecutor = impl CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
|
||||
Block = Block,
|
||||
RuntimeApi = polkadot_runtime::RuntimeApi,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TLightBackend<Block>,
|
||||
SelectChain = LongestChain<TLightBackend<Block>, Block>,
|
||||
CallExecutor = TLightCallExecutor<Block, PolkadotExecutor>,
|
||||
>, ServiceError>
|
||||
{
|
||||
new_light(config)
|
||||
}
|
||||
|
||||
/// Create a new Kusama service for a light client.
|
||||
pub fn kusama_new_light(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block,
|
||||
RuntimeApi = kusama_runtime::RuntimeApi,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TLightBackend<Block>,
|
||||
SelectChain = LongestChain<TLightBackend<Block>, Block>,
|
||||
CallExecutor = TLightCallExecutor<Block, KusamaExecutor>,
|
||||
>, ServiceError>
|
||||
{
|
||||
new_light(config)
|
||||
}
|
||||
|
||||
/// Builds a new service for a light client.
|
||||
pub fn new_light<Runtime, Dispatch, Extrinsic>(config: Configuration)
|
||||
-> Result<impl AbstractService<
|
||||
Block = Block,
|
||||
RuntimeApi = Runtime,
|
||||
NetworkSpecialization = PolkadotProtocol,
|
||||
Backend = TLightBackend<Block>,
|
||||
SelectChain = LongestChain<TLightBackend<Block>, Block>,
|
||||
CallExecutor = TLightCallExecutor<Block, Dispatch>,
|
||||
>, ServiceError>
|
||||
where
|
||||
Runtime: ConstructRuntimeApi<Block, service::TLightClient<Block, Runtime, Dispatch>> + Send + Sync + 'static,
|
||||
Runtime::RuntimeApi: RuntimeApiCollection<Extrinsic>,
|
||||
Dispatch: NativeExecutionDispatch + 'static,
|
||||
Extrinsic: RuntimeExtrinsic,
|
||||
{
|
||||
let inherent_data_providers = InherentDataProviders::new();
|
||||
|
||||
ServiceBuilder::new_light::<Block, RuntimeApi, polkadot_executor::Executor>(config)?
|
||||
ServiceBuilder::new_light::<Block, Runtime, Dispatch>(config)?
|
||||
.with_select_chain(|_, backend| {
|
||||
Ok(LongestChain::new(backend.clone()))
|
||||
})?
|
||||
.with_transaction_pool(|config, client, fetcher| {
|
||||
let fetcher = fetcher
|
||||
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
|
||||
let pool_api = txpool::LightChainApi::new(client.clone(), fetcher.clone());
|
||||
let pool = txpool::BasicPool::new(config, pool_api);
|
||||
let maintainer = txpool::LightBasicPoolMaintainer::with_defaults(pool.pool().clone(), client, fetcher);
|
||||
let maintainable_pool = txpool_api::MaintainableTransactionPool::new(pool, maintainer);
|
||||
let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());
|
||||
let pool = sc_transaction_pool::BasicPool::new(config, pool_api);
|
||||
let maintainer = sc_transaction_pool::LightBasicPoolMaintainer::with_defaults(pool.pool().clone(), client, fetcher);
|
||||
let maintainable_pool = sp_transaction_pool::MaintainableTransactionPool::new(pool, maintainer);
|
||||
Ok(maintainable_pool)
|
||||
})?
|
||||
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _| {
|
||||
let fetch_checker = fetcher
|
||||
.map(|fetcher| fetcher.checker().clone())
|
||||
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
|
||||
let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi>(
|
||||
let grandpa_block_import = grandpa::light_block_import::<_, _, _, Runtime>(
|
||||
client.clone(), backend, &*client, Arc::new(fetch_checker)
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user