diff --git a/Cargo.lock b/Cargo.lock
index 885e2b4b4cf30..07295630b1298 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13992,6 +13992,7 @@ dependencies = [
"sc-chain-spec",
"sc-cli",
"sc-client-api",
+ "sc-client-db",
"sc-consensus",
"sc-executor",
"sc-network",
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
index 09bde034cf262..066cbfae53ae7 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
@@ -38,6 +38,7 @@ sc-consensus = { workspace = true, default-features = true }
frame-support = { optional = true, workspace = true, default-features = true }
sc-cli = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
+sc-client-db = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
@@ -105,6 +106,7 @@ runtime-benchmarks = [
"parachains-common/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
+ "sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
index 31eb2cf880609..15d21235d1a15 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
@@ -36,8 +36,10 @@ use std::{fmt::Debug, marker::PhantomData, path::PathBuf};
/// The related info is shown to the customer as part of logs or help messages.
/// It does not impact functionality.
pub trait CliConfig {
+ /// The version of the resulting node binary.
fn impl_version() -> String;
+ /// The description of the resulting node binary.
fn description(executable_name: String) -> String {
format!(
"The command-line arguments provided first will be passed to the parachain node, \n\
@@ -50,10 +52,13 @@ pub trait CliConfig {
)
}
+ /// The author of the resulting node binary.
fn author() -> String;
+ /// The support URL for the resulting node binary.
fn support_url() -> String;
+ /// The starting copyright year of the resulting node binary.
fn copyright_start_year() -> u16;
}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
index 7f915b729e0a4..320511ece5e51 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see .
-#[cfg(feature = "runtime-benchmarks")]
-use crate::service::Block;
use crate::{
cli::{Cli, RelayChainCli, Subcommand},
common::{
@@ -24,32 +22,56 @@ use crate::{
AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT,
RuntimeResolver,
},
- NodeExtraArgs,
- },
- fake_runtime_api::{
- asset_hub_polkadot_aura::RuntimeApi as AssetHubPolkadotRuntimeApi,
- aura::RuntimeApi as AuraRuntimeApi,
+ spec::DynNodeSpec,
+ types::Block,
+ NodeBlock, NodeExtraArgs,
},
- service::{new_aura_node_spec, DynNodeSpec, ShellNode},
+ fake_runtime_api,
+ runtime::BlockNumber,
+ service::ShellNode,
};
#[cfg(feature = "runtime-benchmarks")]
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
-use parachains_common::{AssetHubPolkadotAuraId, AuraId};
use sc_cli::{Result, SubstrateCli};
use sp_runtime::traits::AccountIdConversion;
#[cfg(feature = "runtime-benchmarks")]
use sp_runtime::traits::HashingFor;
+use std::panic::{RefUnwindSafe, UnwindSafe};
/// Structure that can be used in order to provide customizers for different functionalities of the
/// node binary that is being built using this library.
pub struct RunConfig {
+ /// A custom chain spec loader.
pub chain_spec_loader: Box,
+ /// A custom runtime resolver.
pub runtime_resolver: Box,
}
+pub fn new_aura_node_spec(
+ aura_id: AuraConsensusId,
+ extra_args: &NodeExtraArgs,
+) -> Box
+where
+ Block: NodeBlock + UnwindSafe + RefUnwindSafe,
+ Block::BoundedHeader: UnwindSafe + RefUnwindSafe,
+{
+ match aura_id {
+ AuraConsensusId::Sr25519 => crate::service::new_aura_node_spec::<
+ Block,
+ fake_runtime_api::aura_sr25519::RuntimeApi,
+ sp_consensus_aura::sr25519::AuthorityId,
+ >(extra_args),
+ AuraConsensusId::Ed25519 => crate::service::new_aura_node_spec::<
+ Block,
+ fake_runtime_api::aura_ed25519::RuntimeApi,
+ sp_consensus_aura::ed25519::AuthorityId,
+ >(extra_args),
+ }
+}
+
fn new_node_spec(
config: &sc_service::Configuration,
runtime_resolver: &Box,
@@ -59,11 +81,11 @@ fn new_node_spec(
Ok(match runtime {
Runtime::Shell => Box::new(ShellNode),
- Runtime::Omni(consensus) => match consensus {
- Consensus::Aura(AuraConsensusId::Sr25519) =>
- new_aura_node_spec::(extra_args),
- Consensus::Aura(AuraConsensusId::Ed25519) =>
- new_aura_node_spec::(extra_args),
+ Runtime::Omni(block_number, consensus) => match (block_number, consensus) {
+ (BlockNumber::U32, Consensus::Aura(aura_id)) =>
+ new_aura_node_spec::>(aura_id, extra_args),
+ (BlockNumber::U64, Consensus::Aura(aura_id)) =>
+ new_aura_node_spec::>(aura_id, extra_args),
},
})
}
@@ -156,7 +178,7 @@ pub fn run(cmd_config: RunConfig) -> Result<()
match cmd {
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Pallet(cmd) => runner.sync_run(|config| {
- cmd.run_with_spec::, ReclaimHostFunctions>(Some(
+ cmd.run_with_spec::>, ReclaimHostFunctions>(Some(
config.chain_spec,
))
}),
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/command.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/command.rs
new file mode 100644
index 0000000000000..e2826826d40ed
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/command.rs
@@ -0,0 +1,161 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus. If not, see .
+
+use crate::common::spec::NodeSpec;
+use cumulus_client_cli::ExportGenesisHeadCommand;
+use frame_benchmarking_cli::BlockCmd;
+#[cfg(any(feature = "runtime-benchmarks"))]
+use frame_benchmarking_cli::StorageCmd;
+use sc_cli::{CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
+use sc_service::{Configuration, TaskManager};
+use std::{future::Future, pin::Pin};
+
+type SyncCmdResult = sc_cli::Result<()>;
+
+type AsyncCmdResult<'a> =
+ sc_cli::Result<(Pin + 'a>>, TaskManager)>;
+
+pub trait NodeCommandRunner {
+ fn prepare_check_block_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &CheckBlockCmd,
+ ) -> AsyncCmdResult<'_>;
+
+ fn prepare_export_blocks_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportBlocksCmd,
+ ) -> AsyncCmdResult<'_>;
+
+ fn prepare_export_state_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportStateCmd,
+ ) -> AsyncCmdResult<'_>;
+
+ fn prepare_import_blocks_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ImportBlocksCmd,
+ ) -> AsyncCmdResult<'_>;
+
+ fn prepare_revert_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &RevertCmd,
+ ) -> AsyncCmdResult<'_>;
+
+ fn run_export_genesis_head_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportGenesisHeadCommand,
+ ) -> SyncCmdResult;
+
+ fn run_benchmark_block_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &BlockCmd,
+ ) -> SyncCmdResult;
+
+ #[cfg(any(feature = "runtime-benchmarks"))]
+ fn run_benchmark_storage_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &StorageCmd,
+ ) -> SyncCmdResult;
+}
+
+impl NodeCommandRunner for T
+where
+ T: NodeSpec,
+{
+ fn prepare_check_block_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &CheckBlockCmd,
+ ) -> AsyncCmdResult<'_> {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
+ }
+
+ fn prepare_export_blocks_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportBlocksCmd,
+ ) -> AsyncCmdResult<'_> {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ Ok((Box::pin(cmd.run(partial.client, config.database)), partial.task_manager))
+ }
+
+ fn prepare_export_state_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportStateCmd,
+ ) -> AsyncCmdResult<'_> {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ Ok((Box::pin(cmd.run(partial.client, config.chain_spec)), partial.task_manager))
+ }
+
+ fn prepare_import_blocks_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ImportBlocksCmd,
+ ) -> AsyncCmdResult<'_> {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
+ }
+
+ fn prepare_revert_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &RevertCmd,
+ ) -> AsyncCmdResult<'_> {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ Ok((Box::pin(cmd.run(partial.client, partial.backend, None)), partial.task_manager))
+ }
+
+ fn run_export_genesis_head_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &ExportGenesisHeadCommand,
+ ) -> SyncCmdResult {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ cmd.run(partial.client)
+ }
+
+ fn run_benchmark_block_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &BlockCmd,
+ ) -> SyncCmdResult {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ cmd.run(partial.client)
+ }
+
+ #[cfg(any(feature = "runtime-benchmarks"))]
+ fn run_benchmark_storage_cmd(
+ self: Box,
+ config: Configuration,
+ cmd: &StorageCmd,
+ ) -> SyncCmdResult {
+ let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
+ let db = partial.backend.expose_db();
+ let storage = partial.backend.expose_storage();
+
+ cmd.run(config, partial.client, db, storage)
+ }
+}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs
index 89bc7511dac3b..907f09263fc1c 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs
@@ -20,15 +20,43 @@
pub(crate) mod aura;
pub mod chain_spec;
+pub mod command;
+pub mod rpc;
pub mod runtime;
+pub mod spec;
+pub mod types;
use cumulus_primitives_core::CollectCollationInfo;
+use sc_client_db::DbHash;
use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
use sp_block_builder::BlockBuilder;
-use sp_runtime::traits::Block as BlockT;
+use sp_runtime::{
+ traits::{Block as BlockT, BlockNumber, Header as HeaderT, NumberFor},
+ OpaqueExtrinsic,
+};
use sp_session::SessionKeys;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
-use std::path::PathBuf;
+use std::{fmt::Debug, path::PathBuf, str::FromStr};
+
+pub trait NodeBlock:
+ BlockT
+ + for<'de> serde::Deserialize<'de>
+{
+ type BoundedFromStrErr: Debug;
+ type BoundedNumber: FromStr + BlockNumber;
+ type BoundedHeader: HeaderT + Unpin;
+}
+
+impl NodeBlock for T
+where
+ T: BlockT + for<'de> serde::Deserialize<'de>,
+ ::Header: Unpin,
+ as FromStr>::Err: Debug,
+{
+ type BoundedFromStrErr = as FromStr>::Err;
+ type BoundedNumber = NumberFor;
+ type BoundedHeader = ::Header;
+}
/// Convenience trait that defines the basic bounds for the `RuntimeApi` of a parachain node.
pub trait NodeRuntimeApi:
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/rpc.rs
similarity index 65%
rename from cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs
rename to cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/rpc.rs
index d156ebe2bd6d4..a4e157e87216e 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/rpc.rs
@@ -18,13 +18,13 @@
#![warn(missing_docs)]
-use crate::{
- common::ConstructNodeRuntimeApi,
- service::{ParachainBackend, ParachainClient},
+use crate::common::{
+ types::{AccountId, Balance, Nonce, ParachainBackend, ParachainClient},
+ ConstructNodeRuntimeApi,
};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
-use parachains_common::{AccountId, Balance, Block, Nonce};
use sc_rpc::dev::{Dev, DevApiServer};
+use sp_runtime::traits::Block as BlockT;
use std::{marker::PhantomData, sync::Arc};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
@@ -40,43 +40,45 @@ pub(crate) trait BuildRpcExtensions {
) -> sc_service::error::Result;
}
-pub(crate) struct BuildEmptyRpcExtensions(PhantomData);
+pub(crate) struct BuildEmptyRpcExtensions(PhantomData<(Block, RuntimeApi)>);
-impl
+impl
BuildRpcExtensions<
- ParachainClient,
- ParachainBackend,
- sc_transaction_pool::FullPool>,
- > for BuildEmptyRpcExtensions
+ ParachainClient,
+ ParachainBackend,
+ sc_transaction_pool::FullPool>,
+ > for BuildEmptyRpcExtensions
where
- RuntimeApi: ConstructNodeRuntimeApi> + Send + Sync + 'static,
+ RuntimeApi:
+ ConstructNodeRuntimeApi> + Send + Sync + 'static,
{
fn build_rpc_extensions(
- _client: Arc>,
- _backend: Arc,
- _pool: Arc>>,
+ _client: Arc>,
+ _backend: Arc>,
+ _pool: Arc>>,
) -> sc_service::error::Result {
Ok(RpcExtension::new(()))
}
}
-pub(crate) struct BuildParachainRpcExtensions(PhantomData);
+pub(crate) struct BuildParachainRpcExtensions(PhantomData<(Block, RuntimeApi)>);
-impl
+impl
BuildRpcExtensions<
- ParachainClient,
- ParachainBackend,
- sc_transaction_pool::FullPool>,
- > for BuildParachainRpcExtensions
+ ParachainClient,
+ ParachainBackend,
+ sc_transaction_pool::FullPool>,
+ > for BuildParachainRpcExtensions
where
- RuntimeApi: ConstructNodeRuntimeApi> + Send + Sync + 'static,
+ RuntimeApi:
+ ConstructNodeRuntimeApi> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi
+ substrate_frame_rpc_system::AccountNonceApi,
{
fn build_rpc_extensions(
- client: Arc>,
- backend: Arc,
- pool: Arc>>,
+ client: Arc>,
+ backend: Arc>,
+ pool: Arc>>,
) -> sc_service::error::Result {
let build = || -> Result> {
let mut module = RpcExtension::new(());
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs
index c64eda12d5ef2..bddbb0a85d036 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/runtime.rs
@@ -34,12 +34,21 @@ pub enum Consensus {
Aura(AuraConsensusId),
}
+/// The choice of block number for the parachain omni-node.
+#[derive(PartialEq)]
+pub enum BlockNumber {
+ /// u32
+ U32,
+ /// u64
+ U64,
+}
+
/// Helper enum listing the supported Runtime types
#[derive(PartialEq)]
pub enum Runtime {
/// None of the system-chain runtimes, rather the node will act agnostic to the runtime ie. be
/// an omni-node, and simply run a node with the given consensus algorithm.
- Omni(Consensus),
+ Omni(BlockNumber, Consensus),
/// Shell
Shell,
}
@@ -51,11 +60,11 @@ pub trait RuntimeResolver {
}
/// Default implementation for `RuntimeResolver` that just returns
-/// `Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519))`.
+/// `Runtime::Omni(BlockNumber::U32, Consensus::Aura(AuraConsensusId::Sr25519))`.
pub struct DefaultRuntimeResolver;
impl RuntimeResolver for DefaultRuntimeResolver {
fn runtime(&self, _chain_spec: &dyn ChainSpec) -> sc_cli::Result {
- Ok(Runtime::Omni(Consensus::Aura(AuraConsensusId::Sr25519)))
+ Ok(Runtime::Omni(BlockNumber::U32, Consensus::Aura(AuraConsensusId::Sr25519)))
}
}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/spec.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/spec.rs
new file mode 100644
index 0000000000000..55e042aed87e7
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/spec.rs
@@ -0,0 +1,392 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus. If not, see .
+
+use crate::common::{
+ command::NodeCommandRunner,
+ rpc::BuildRpcExtensions,
+ types::{
+ ParachainBackend, ParachainBlockImport, ParachainClient, ParachainHostFunctions,
+ ParachainService,
+ },
+ ConstructNodeRuntimeApi, NodeBlock, NodeExtraArgs,
+};
+use cumulus_client_cli::CollatorOptions;
+use cumulus_client_service::{
+ build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks,
+ BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
+};
+use cumulus_primitives_core::{BlockT, ParaId};
+use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
+use parachains_common::Hash;
+use polkadot_primitives::CollatorPair;
+use prometheus_endpoint::Registry;
+use sc_consensus::DefaultImportQueue;
+use sc_executor::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY};
+use sc_network::{config::FullNetworkConfiguration, NetworkBackend, NetworkBlock};
+use sc_service::{Configuration, ImportQueue, PartialComponents, TaskManager};
+use sc_sysinfo::HwBench;
+use sc_telemetry::{TelemetryHandle, TelemetryWorker};
+use sc_transaction_pool::FullPool;
+use sp_keystore::KeystorePtr;
+use std::{future::Future, pin::Pin, sync::Arc, time::Duration};
+
+pub(crate) trait BuildImportQueue {
+ fn build_import_queue(
+ client: Arc>,
+ block_import: ParachainBlockImport,
+ config: &Configuration,
+ telemetry_handle: Option,
+ task_manager: &TaskManager,
+ ) -> sc_service::error::Result>;
+}
+
+pub(crate) trait StartConsensus
+where
+ RuntimeApi: ConstructNodeRuntimeApi>,
+{
+ fn start_consensus(
+ client: Arc>,
+ block_import: ParachainBlockImport,
+ prometheus_registry: Option<&Registry>,
+ telemetry: Option,
+ task_manager: &TaskManager,
+ relay_chain_interface: Arc,
+ transaction_pool: Arc>>,
+ keystore: KeystorePtr,
+ relay_chain_slot_duration: Duration,
+ para_id: ParaId,
+ collator_key: CollatorPair,
+ overseer_handle: OverseerHandle,
+ announce_block: Arc>) + Send + Sync>,
+ backend: Arc>,
+ node_extra_args: NodeExtraArgs,
+ ) -> Result<(), sc_service::Error>;
+}
+
+/// Checks that the hardware meets the requirements and print a warning otherwise.
+fn warn_if_slow_hardware(hwbench: &sc_sysinfo::HwBench) {
+ // Polkadot para-chains should generally use these requirements to ensure that the relay-chain
+ // will not take longer than expected to import its blocks.
+ if let Err(err) = frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE.check_hardware(hwbench) {
+ log::warn!(
+ "⚠️ The hardware does not meet the minimal requirements {} for role 'Authority' find out more at:\n\
+ https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#reference-hardware",
+ err
+ );
+ }
+}
+
+pub(crate) trait NodeSpec {
+ type Block: NodeBlock;
+
+ type RuntimeApi: ConstructNodeRuntimeApi<
+ Self::Block,
+ ParachainClient,
+ >;
+
+ type BuildImportQueue: BuildImportQueue;
+
+ type BuildRpcExtensions: BuildRpcExtensions<
+ ParachainClient,
+ ParachainBackend,
+ FullPool>,
+ >;
+
+ type StartConsensus: StartConsensus;
+
+ const SYBIL_RESISTANCE: CollatorSybilResistance;
+
+ /// 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.
+ fn new_partial(
+ config: &Configuration,
+ ) -> sc_service::error::Result> {
+ let telemetry = config
+ .telemetry_endpoints
+ .clone()
+ .filter(|x| !x.is_empty())
+ .map(|endpoints| -> Result<_, sc_telemetry::Error> {
+ let worker = TelemetryWorker::new(16)?;
+ let telemetry = worker.handle().new_telemetry(endpoints);
+ Ok((worker, telemetry))
+ })
+ .transpose()?;
+
+ let heap_pages = config.default_heap_pages.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| {
+ HeapAllocStrategy::Static { extra_pages: h as _ }
+ });
+
+ let executor = sc_executor::WasmExecutor::::builder()
+ .with_execution_method(config.wasm_method)
+ .with_max_runtime_instances(config.max_runtime_instances)
+ .with_runtime_cache_size(config.runtime_cache_size)
+ .with_onchain_heap_alloc_strategy(heap_pages)
+ .with_offchain_heap_alloc_strategy(heap_pages)
+ .build();
+
+ let (client, backend, keystore_container, task_manager) =
+ sc_service::new_full_parts_record_import::(
+ config,
+ telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
+ executor,
+ true,
+ )?;
+ let client = Arc::new(client);
+
+ let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());
+
+ let telemetry = telemetry.map(|(worker, telemetry)| {
+ task_manager.spawn_handle().spawn("telemetry", None, worker.run());
+ telemetry
+ });
+
+ let transaction_pool = sc_transaction_pool::BasicPool::new_full(
+ config.transaction_pool.clone(),
+ config.role.is_authority().into(),
+ config.prometheus_registry(),
+ task_manager.spawn_essential_handle(),
+ client.clone(),
+ );
+
+ let block_import = ParachainBlockImport::new(client.clone(), backend.clone());
+
+ let import_queue = Self::BuildImportQueue::build_import_queue(
+ client.clone(),
+ block_import.clone(),
+ config,
+ telemetry.as_ref().map(|telemetry| telemetry.handle()),
+ &task_manager,
+ )?;
+
+ Ok(PartialComponents {
+ backend,
+ client,
+ import_queue,
+ keystore_container,
+ task_manager,
+ transaction_pool,
+ select_chain: (),
+ other: (block_import, telemetry, telemetry_worker_handle),
+ })
+ }
+
+ /// Start a node with the given parachain spec.
+ ///
+ /// This is the actual implementation that is abstract over the executor and the runtime api.
+ fn start_node(
+ parachain_config: Configuration,
+ polkadot_config: Configuration,
+ collator_options: CollatorOptions,
+ para_id: ParaId,
+ hwbench: Option,
+ node_extra_args: NodeExtraArgs,
+ ) -> Pin>>>
+ where
+ Net: NetworkBackend,
+ {
+ Box::pin(async move {
+ let parachain_config = prepare_node_config(parachain_config);
+
+ let params = Self::new_partial(¶chain_config)?;
+ let (block_import, mut telemetry, telemetry_worker_handle) = params.other;
+
+ let client = params.client.clone();
+ let backend = params.backend.clone();
+
+ let mut task_manager = params.task_manager;
+ let (relay_chain_interface, collator_key) = build_relay_chain_interface(
+ polkadot_config,
+ ¶chain_config,
+ telemetry_worker_handle,
+ &mut task_manager,
+ collator_options.clone(),
+ hwbench.clone(),
+ )
+ .await
+ .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;
+
+ let validator = parachain_config.role.is_authority();
+ let prometheus_registry = parachain_config.prometheus_registry().cloned();
+ let transaction_pool = params.transaction_pool.clone();
+ let import_queue_service = params.import_queue.service();
+ let net_config = FullNetworkConfiguration::<_, _, Net>::new(
+ ¶chain_config.network,
+ prometheus_registry.clone(),
+ );
+
+ let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
+ build_network(BuildNetworkParams {
+ parachain_config: ¶chain_config,
+ net_config,
+ client: client.clone(),
+ transaction_pool: transaction_pool.clone(),
+ para_id,
+ spawn_handle: task_manager.spawn_handle(),
+ relay_chain_interface: relay_chain_interface.clone(),
+ import_queue: params.import_queue,
+ sybil_resistance_level: Self::SYBIL_RESISTANCE,
+ })
+ .await?;
+
+ let rpc_builder = {
+ let client = client.clone();
+ let transaction_pool = transaction_pool.clone();
+ let backend_for_rpc = backend.clone();
+
+ Box::new(move |_| {
+ Self::BuildRpcExtensions::build_rpc_extensions(
+ client.clone(),
+ backend_for_rpc.clone(),
+ transaction_pool.clone(),
+ )
+ })
+ };
+
+ sc_service::spawn_tasks(sc_service::SpawnTasksParams {
+ rpc_builder,
+ client: client.clone(),
+ transaction_pool: transaction_pool.clone(),
+ task_manager: &mut task_manager,
+ config: parachain_config,
+ keystore: params.keystore_container.keystore(),
+ backend: backend.clone(),
+ network: network.clone(),
+ sync_service: sync_service.clone(),
+ system_rpc_tx,
+ tx_handler_controller,
+ telemetry: telemetry.as_mut(),
+ })?;
+
+ if let Some(hwbench) = hwbench {
+ sc_sysinfo::print_hwbench(&hwbench);
+ if validator {
+ warn_if_slow_hardware(&hwbench);
+ }
+
+ if let Some(ref mut telemetry) = telemetry {
+ let telemetry_handle = telemetry.handle();
+ task_manager.spawn_handle().spawn(
+ "telemetry_hwbench",
+ None,
+ sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
+ );
+ }
+ }
+
+ let announce_block = {
+ let sync_service = sync_service.clone();
+ Arc::new(move |hash, data| sync_service.announce_block(hash, data))
+ };
+
+ let relay_chain_slot_duration = Duration::from_secs(6);
+
+ let overseer_handle = relay_chain_interface
+ .overseer_handle()
+ .map_err(|e| sc_service::Error::Application(Box::new(e)))?;
+
+ start_relay_chain_tasks(StartRelayChainTasksParams {
+ client: client.clone(),
+ announce_block: announce_block.clone(),
+ para_id,
+ relay_chain_interface: relay_chain_interface.clone(),
+ task_manager: &mut task_manager,
+ da_recovery_profile: if validator {
+ DARecoveryProfile::Collator
+ } else {
+ DARecoveryProfile::FullNode
+ },
+ import_queue: import_queue_service,
+ relay_chain_slot_duration,
+ recovery_handle: Box::new(overseer_handle.clone()),
+ sync_service,
+ })?;
+
+ if validator {
+ Self::StartConsensus::start_consensus(
+ client.clone(),
+ block_import,
+ prometheus_registry.as_ref(),
+ telemetry.as_ref().map(|t| t.handle()),
+ &task_manager,
+ relay_chain_interface.clone(),
+ transaction_pool,
+ params.keystore_container.keystore(),
+ relay_chain_slot_duration,
+ para_id,
+ collator_key.expect("Command line arguments do not allow this. qed"),
+ overseer_handle,
+ announce_block,
+ backend.clone(),
+ node_extra_args,
+ )?;
+ }
+
+ start_network.start_network();
+
+ Ok(task_manager)
+ })
+ }
+}
+
+pub(crate) trait DynNodeSpec: NodeCommandRunner {
+ fn start_node(
+ self: Box,
+ parachain_config: Configuration,
+ polkadot_config: Configuration,
+ collator_options: CollatorOptions,
+ para_id: ParaId,
+ hwbench: Option,
+ node_extra_args: NodeExtraArgs,
+ ) -> Pin>>>;
+}
+
+impl DynNodeSpec for T
+where
+ T: NodeSpec + NodeCommandRunner,
+{
+ fn start_node(
+ self: Box,
+ parachain_config: Configuration,
+ polkadot_config: Configuration,
+ collator_options: CollatorOptions,
+ para_id: ParaId,
+ hwbench: Option,
+ node_extra_args: NodeExtraArgs,
+ ) -> Pin>>> {
+ match parachain_config.network.network_backend {
+ sc_network::config::NetworkBackendType::Libp2p =>
+ ::start_node::>(
+ parachain_config,
+ polkadot_config,
+ collator_options,
+ para_id,
+ hwbench,
+ node_extra_args,
+ ),
+ sc_network::config::NetworkBackendType::Litep2p =>
+ ::start_node::(
+ parachain_config,
+ polkadot_config,
+ collator_options,
+ para_id,
+ hwbench,
+ node_extra_args,
+ ),
+ }
+ }
+}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/types.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/types.rs
new file mode 100644
index 0000000000000..9cfdcb22451c7
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/types.rs
@@ -0,0 +1,56 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus. If not, see .
+
+use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
+use cumulus_primitives_core::relay_chain::UncheckedExtrinsic;
+use sc_consensus::DefaultImportQueue;
+use sc_executor::WasmExecutor;
+use sc_service::{PartialComponents, TFullBackend, TFullClient};
+use sc_telemetry::{Telemetry, TelemetryWorkerHandle};
+use sc_transaction_pool::FullPool;
+use sp_runtime::{generic, traits::BlakeTwo256};
+use std::sync::Arc;
+
+pub use parachains_common::{AccountId, Balance, Hash, Nonce};
+
+type Header = generic::Header;
+pub type Block = generic::Block, UncheckedExtrinsic>;
+
+#[cfg(not(feature = "runtime-benchmarks"))]
+pub type ParachainHostFunctions = cumulus_client_service::ParachainHostFunctions;
+#[cfg(feature = "runtime-benchmarks")]
+pub type ParachainHostFunctions = (
+ cumulus_client_service::ParachainHostFunctions,
+ frame_benchmarking::benchmarking::HostFunctions,
+);
+
+pub type ParachainClient =
+ TFullClient>;
+
+pub type ParachainBackend = TFullBackend;
+
+pub type ParachainBlockImport =
+ TParachainBlockImport>, ParachainBackend>;
+
+/// Assembly of PartialComponents (enough to run chain ops subcommands)
+pub type ParachainService = PartialComponents<
+ ParachainClient,
+ ParachainBackend,
+ (),
+ DefaultImportQueue,
+ FullPool>,
+ (ParachainBlockImport, Option, Option),
+>;
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs
deleted file mode 100644
index f2b8b4d562b96..0000000000000
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/asset_hub_polkadot_aura.rs
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (C) Parity Technologies (UK) Ltd.
-// This file is part of Cumulus.
-
-// Cumulus is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Cumulus is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Cumulus. If not, see .
-
-//! These are used to provide a type that implements these runtime APIs without requiring to import
-//! the native runtimes.
-
-use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance, Block, Nonce};
-use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
-use sp_runtime::{
- traits::Block as BlockT,
- transaction_validity::{TransactionSource, TransactionValidity},
- ApplyExtrinsicResult,
-};
-use sp_weights::Weight;
-
-pub struct Runtime;
-
-sp_api::impl_runtime_apis! {
- impl sp_api::Core for Runtime {
- fn version() -> sp_version::RuntimeVersion {
- unimplemented!()
- }
-
- fn execute_block(_: Block) {
- unimplemented!()
- }
-
- fn initialize_block(_: &::Header) -> sp_runtime::ExtrinsicInclusionMode {
- unimplemented!()
- }
- }
-
- impl sp_api::Metadata for Runtime {
- fn metadata() -> OpaqueMetadata {
- unimplemented!()
- }
-
- fn metadata_at_version(_: u32) -> Option {
- unimplemented!()
- }
-
- fn metadata_versions() -> Vec {
- unimplemented!()
- }
- }
-
- impl sp_consensus_aura::AuraApi for Runtime {
- fn slot_duration() -> sp_consensus_aura::SlotDuration {
- unimplemented!()
- }
-
- fn authorities() -> Vec {
- unimplemented!()
- }
- }
-
- impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime {
- fn can_build_upon(
- _: ::Hash,
- _: cumulus_primitives_aura::Slot,
- ) -> bool {
- unimplemented!()
- }
- }
-
- impl sp_block_builder::BlockBuilder for Runtime {
- fn apply_extrinsic(_: ::Extrinsic) -> ApplyExtrinsicResult {
- unimplemented!()
- }
-
- fn finalize_block() -> ::Header {
- unimplemented!()
- }
-
- fn inherent_extrinsics(_: sp_inherents::InherentData) -> Vec<::Extrinsic> {
- unimplemented!()
- }
-
- fn check_inherents(_: Block, _: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
- unimplemented!()
- }
- }
-
- impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime {
- fn validate_transaction(
- _: TransactionSource,
- _: ::Extrinsic,
- _: ::Hash,
- ) -> TransactionValidity {
- unimplemented!()
- }
- }
-
- impl sp_session::SessionKeys for Runtime {
- fn generate_session_keys(_: Option>) -> Vec {
- unimplemented!()
- }
-
- fn decode_session_keys(
- _: Vec,
- ) -> Option, KeyTypeId)>> {
- unimplemented!()
- }
- }
-
- impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime {
- fn query_info(
- _: ::Extrinsic,
- _: u32,
- ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo {
- unimplemented!()
- }
- fn query_fee_details(
- _: ::Extrinsic,
- _: u32,
- ) -> pallet_transaction_payment::FeeDetails {
- unimplemented!()
- }
- fn query_weight_to_fee(_: Weight) -> Balance {
- unimplemented!()
- }
- fn query_length_to_fee(_: u32) -> Balance {
- unimplemented!()
- }
- }
-
- impl cumulus_primitives_core::CollectCollationInfo for Runtime {
- fn collect_collation_info(_: &::Header) -> cumulus_primitives_core::CollationInfo {
- unimplemented!()
- }
- }
-
- #[cfg(feature = "try-runtime")]
- impl frame_try_runtime::TryRuntime for Runtime {
- fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
- unimplemented!()
- }
-
- fn execute_block(
- _: Block,
- _: bool,
- _: bool,
- _: frame_try_runtime::TryStateSelect,
- ) -> Weight {
- unimplemented!()
- }
- }
-
- impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime {
- fn account_nonce(_: AccountId) -> Nonce {
- unimplemented!()
- }
- }
-
- #[cfg(feature = "runtime-benchmarks")]
- impl frame_benchmarking::Benchmark for Runtime {
- fn benchmark_metadata(_: bool) -> (
- Vec,
- Vec,
- ) {
- unimplemented!()
- }
-
- fn dispatch_benchmark(
- _: frame_benchmarking::BenchmarkConfig
- ) -> Result, sp_runtime::RuntimeString> {
- unimplemented!()
- }
- }
-
- impl sp_genesis_builder::GenesisBuilder for Runtime {
- fn build_state(_: Vec) -> sp_genesis_builder::Result {
- unimplemented!()
- }
-
- fn get_preset(_id: &Option) -> Option> {
- unimplemented!()
- }
-
- fn preset_names() -> Vec {
- unimplemented!()
- }
- }
-}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs
deleted file mode 100644
index eb6d3fafa3d67..0000000000000
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/aura.rs
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (C) Parity Technologies (UK) Ltd.
-// This file is part of Cumulus.
-
-// Cumulus is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Cumulus is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Cumulus. If not, see .
-
-//! These are used to provide a type that implements these runtime APIs without requiring to import
-//! the native runtimes.
-
-use parachains_common::{AccountId, AuraId, Balance, Block, Nonce};
-use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
-use sp_runtime::{
- traits::Block as BlockT,
- transaction_validity::{TransactionSource, TransactionValidity},
- ApplyExtrinsicResult,
-};
-use sp_weights::Weight;
-
-pub struct Runtime;
-
-sp_api::impl_runtime_apis! {
- impl sp_api::Core for Runtime {
- fn version() -> sp_version::RuntimeVersion {
- unimplemented!()
- }
-
- fn execute_block(_: Block) {
- unimplemented!()
- }
-
- fn initialize_block(_: &::Header) -> sp_runtime::ExtrinsicInclusionMode {
- unimplemented!()
- }
- }
-
- impl sp_api::Metadata for Runtime {
- fn metadata() -> OpaqueMetadata {
- unimplemented!()
- }
-
- fn metadata_at_version(_: u32) -> Option {
- unimplemented!()
- }
-
- fn metadata_versions() -> Vec {
- unimplemented!()
- }
- }
-
- impl sp_consensus_aura::AuraApi for Runtime {
- fn slot_duration() -> sp_consensus_aura::SlotDuration {
- unimplemented!()
- }
-
- fn authorities() -> Vec {
- unimplemented!()
- }
- }
-
- impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime {
- fn can_build_upon(
- _: ::Hash,
- _: cumulus_primitives_aura::Slot,
- ) -> bool {
- unimplemented!()
- }
- }
-
- impl sp_block_builder::BlockBuilder for Runtime {
- fn apply_extrinsic(_: ::Extrinsic) -> ApplyExtrinsicResult {
- unimplemented!()
- }
-
- fn finalize_block() -> ::Header {
- unimplemented!()
- }
-
- fn inherent_extrinsics(_: sp_inherents::InherentData) -> Vec<::Extrinsic> {
- unimplemented!()
- }
-
- fn check_inherents(_: Block, _: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
- unimplemented!()
- }
- }
-
- impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime {
- fn validate_transaction(
- _: TransactionSource,
- _: ::Extrinsic,
- _: ::Hash,
- ) -> TransactionValidity {
- unimplemented!()
- }
- }
-
- impl sp_session::SessionKeys for Runtime {
- fn generate_session_keys(_: Option>) -> Vec {
- unimplemented!()
- }
-
- fn decode_session_keys(
- _: Vec,
- ) -> Option, KeyTypeId)>> {
- unimplemented!()
- }
- }
-
- impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime {
- fn query_info(
- _: ::Extrinsic,
- _: u32,
- ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo {
- unimplemented!()
- }
- fn query_fee_details(
- _: ::Extrinsic,
- _: u32,
- ) -> pallet_transaction_payment::FeeDetails {
- unimplemented!()
- }
- fn query_weight_to_fee(_: Weight) -> Balance {
- unimplemented!()
- }
- fn query_length_to_fee(_: u32) -> Balance {
- unimplemented!()
- }
- }
-
- impl cumulus_primitives_core::CollectCollationInfo for Runtime {
- fn collect_collation_info(_: &::Header) -> cumulus_primitives_core::CollationInfo {
- unimplemented!()
- }
- }
-
- #[cfg(feature = "try-runtime")]
- impl frame_try_runtime::TryRuntime for Runtime {
- fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
- unimplemented!()
- }
-
- fn execute_block(
- _: Block,
- _: bool,
- _: bool,
- _: frame_try_runtime::TryStateSelect,
- ) -> Weight {
- unimplemented!()
- }
- }
-
- impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime {
- fn account_nonce(_: AccountId) -> Nonce {
- unimplemented!()
- }
- }
-
- #[cfg(feature = "runtime-benchmarks")]
- impl frame_benchmarking::Benchmark for Runtime {
- fn benchmark_metadata(_: bool) -> (
- Vec,
- Vec,
- ) {
- unimplemented!()
- }
-
- fn dispatch_benchmark(
- _: frame_benchmarking::BenchmarkConfig
- ) -> Result, sp_runtime::RuntimeString> {
- unimplemented!()
- }
- }
-
- impl sp_genesis_builder::GenesisBuilder for Runtime {
- fn build_state(_: Vec) -> sp_genesis_builder::Result {
- unimplemented!()
- }
-
- fn get_preset(_id: &Option) -> Option> {
- unimplemented!()
- }
-
- fn preset_names() -> Vec {
- unimplemented!()
- }
- }
-}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs
index 29e2736b06ff3..02aa867d70fec 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs
@@ -17,5 +17,19 @@
//! In an ideal world this would be one runtime which would simplify the code massively.
//! This is not an ideal world - Polkadot Asset Hub has a different key type.
-pub mod asset_hub_polkadot_aura;
-pub mod aura;
+mod utils;
+
+use utils::{impl_node_runtime_apis, imports::*};
+
+type CustomBlock = crate::common::types::Block;
+pub mod aura_sr25519 {
+ use super::*;
+ struct FakeRuntime;
+ impl_node_runtime_apis!(FakeRuntime, CustomBlock, sp_consensus_aura::sr25519::AuthorityId);
+}
+
+pub mod aura_ed25519 {
+ use super::*;
+ struct FakeRuntime;
+ impl_node_runtime_apis!(FakeRuntime, CustomBlock, sp_consensus_aura::ed25519::AuthorityId);
+}
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs
new file mode 100644
index 0000000000000..442b87b5d7752
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs
@@ -0,0 +1,220 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus. If not, see .
+
+pub(crate) mod imports {
+ pub use parachains_common::{AccountId, Balance, Nonce};
+ pub use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
+ pub use sp_runtime::{
+ traits::Block as BlockT,
+ transaction_validity::{TransactionSource, TransactionValidity},
+ ApplyExtrinsicResult,
+ };
+ pub use sp_weights::Weight;
+}
+
+macro_rules! impl_node_runtime_apis {
+ ($runtime: ty, $block: tt, $aura_id: ty) => {
+ sp_api::impl_runtime_apis! {
+ impl sp_api::Core<$block> for $runtime {
+ fn version() -> sp_version::RuntimeVersion {
+ unimplemented!()
+ }
+
+ fn execute_block(_: $block) {
+ unimplemented!()
+ }
+
+ fn initialize_block(
+ _: &<$block as BlockT>::Header
+ ) -> sp_runtime::ExtrinsicInclusionMode {
+ unimplemented!()
+ }
+ }
+
+ impl sp_api::Metadata<$block> for $runtime {
+ fn metadata() -> OpaqueMetadata {
+ unimplemented!()
+ }
+
+ fn metadata_at_version(_: u32) -> Option {
+ unimplemented!()
+ }
+
+ fn metadata_versions() -> Vec {
+ unimplemented!()
+ }
+ }
+
+ impl sp_consensus_aura::AuraApi<$block, $aura_id> for $runtime {
+ fn slot_duration() -> sp_consensus_aura::SlotDuration {
+ unimplemented!()
+ }
+
+ fn authorities() -> Vec<$aura_id> {
+ unimplemented!()
+ }
+ }
+
+ impl cumulus_primitives_aura::AuraUnincludedSegmentApi<$block> for $runtime {
+ fn can_build_upon(
+ _: <$block as BlockT>::Hash,
+ _: cumulus_primitives_aura::Slot,
+ ) -> bool {
+ unimplemented!()
+ }
+ }
+
+ impl sp_block_builder::BlockBuilder<$block> for $runtime {
+ fn apply_extrinsic(_: <$block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
+ unimplemented!()
+ }
+
+ fn finalize_block() -> <$block as BlockT>::Header {
+ unimplemented!()
+ }
+
+ fn inherent_extrinsics(
+ _: sp_inherents::InherentData
+ ) -> Vec<<$block as BlockT>::Extrinsic> {
+ unimplemented!()
+ }
+
+ fn check_inherents(
+ _: $block,
+ _: sp_inherents::InherentData
+ ) -> sp_inherents::CheckInherentsResult {
+ unimplemented!()
+ }
+ }
+
+ impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<$block> for $runtime {
+ fn validate_transaction(
+ _: TransactionSource,
+ _: <$block as BlockT>::Extrinsic,
+ _: <$block as BlockT>::Hash,
+ ) -> TransactionValidity {
+ unimplemented!()
+ }
+ }
+
+ impl sp_session::SessionKeys<$block> for $runtime {
+ fn generate_session_keys(_: Option>) -> Vec {
+ unimplemented!()
+ }
+
+ fn decode_session_keys(
+ _: Vec,
+ ) -> Option, KeyTypeId)>> {
+ unimplemented!()
+ }
+ }
+
+ impl
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
+ $block,
+ Balance,
+ > for $runtime
+ {
+ fn query_info(
+ _: <$block as BlockT>::Extrinsic,
+ _: u32,
+ ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo {
+ unimplemented!()
+ }
+ fn query_fee_details(
+ _: <$block as BlockT>::Extrinsic,
+ _: u32,
+ ) -> pallet_transaction_payment::FeeDetails {
+ unimplemented!()
+ }
+ fn query_weight_to_fee(_: Weight) -> Balance {
+ unimplemented!()
+ }
+ fn query_length_to_fee(_: u32) -> Balance {
+ unimplemented!()
+ }
+ }
+
+ impl cumulus_primitives_core::CollectCollationInfo<$block> for $runtime {
+ fn collect_collation_info(
+ _: &<$block as BlockT>::Header
+ ) -> cumulus_primitives_core::CollationInfo {
+ unimplemented!()
+ }
+ }
+
+ #[cfg(feature = "try-runtime")]
+ impl frame_try_runtime::TryRuntime<$block> for $runtime {
+ fn on_runtime_upgrade(
+ _: frame_try_runtime::UpgradeCheckSelect
+ ) -> (Weight, Weight) {
+ unimplemented!()
+ }
+
+ fn execute_block(
+ _: $block,
+ _: bool,
+ _: bool,
+ _: frame_try_runtime::TryStateSelect,
+ ) -> Weight {
+ unimplemented!()
+ }
+ }
+
+ impl frame_system_rpc_runtime_api::AccountNonceApi<
+ $block,
+ AccountId,
+ Nonce
+ > for $runtime {
+ fn account_nonce(_: AccountId) -> Nonce {
+ unimplemented!()
+ }
+ }
+
+ #[cfg(feature = "runtime-benchmarks")]
+ impl frame_benchmarking::Benchmark<$block> for $runtime {
+ fn benchmark_metadata(_: bool) -> (
+ Vec,
+ Vec,
+ ) {
+ unimplemented!()
+ }
+
+ fn dispatch_benchmark(
+ _: frame_benchmarking::BenchmarkConfig
+ ) -> Result, sp_runtime::RuntimeString> {
+ unimplemented!()
+ }
+ }
+
+ impl sp_genesis_builder::GenesisBuilder<$block> for $runtime {
+ fn build_state(_: Vec) -> sp_genesis_builder::Result {
+ unimplemented!()
+ }
+
+ fn get_preset(_id: &Option) -> Option> {
+ unimplemented!()
+ }
+
+ fn preset_names() -> Vec {
+ unimplemented!()
+ }
+ }
+ }
+ };
+}
+
+pub(crate) use impl_node_runtime_apis;
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs
index fc164a9d89077..6aa2f656a48ba 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/lib.rs
@@ -39,11 +39,12 @@
//!
//! For an example, see the `polkadot-parachain-bin` crate.
+#![deny(missing_docs)]
+
mod cli;
mod command;
mod common;
mod fake_runtime_api;
-mod rpc;
mod service;
pub use cli::CliConfig;
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs
index 057b8af9af526..303ec1e3b298b 100644
--- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs
@@ -14,7 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see .
-use cumulus_client_cli::{CollatorOptions, ExportGenesisHeadCommand};
+use crate::{
+ common::{
+ aura::{AuraIdT, AuraRuntimeApi},
+ rpc::{BuildEmptyRpcExtensions, BuildParachainRpcExtensions},
+ spec::{BuildImportQueue, DynNodeSpec, NodeSpec, StartConsensus},
+ types::{
+ AccountId, Balance, Block, Hash, Nonce, ParachainBackend, ParachainBlockImport,
+ ParachainClient,
+ },
+ ConstructNodeRuntimeApi, NodeBlock, NodeExtraArgs,
+ },
+ fake_runtime_api::aura_sr25519::RuntimeApi as FakeRuntimeApi,
+};
use cumulus_client_collator::service::{
CollatorService, ServiceInterface as CollatorServiceInterface,
};
@@ -23,370 +35,45 @@ use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params a
use cumulus_client_consensus_aura::collators::slot_based::{
self as slot_based, Params as SlotBasedParams,
};
-use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
use cumulus_client_consensus_proposer::{Proposer, ProposerInterface};
use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
#[allow(deprecated)]
use cumulus_client_service::old_consensus;
-use cumulus_client_service::{
- build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks,
- BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
-};
+use cumulus_client_service::CollatorSybilResistance;
use cumulus_primitives_core::{relay_chain::ValidationCode, ParaId};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
-
-use crate::{
- common::{
- aura::{AuraIdT, AuraRuntimeApi},
- ConstructNodeRuntimeApi, NodeExtraArgs,
- },
- fake_runtime_api::aura::RuntimeApi as FakeRuntimeApi,
- rpc::BuildRpcExtensions,
-};
-pub use parachains_common::{AccountId, Balance, Block, Hash, Nonce};
-
-use crate::rpc::{BuildEmptyRpcExtensions, BuildParachainRpcExtensions};
-use frame_benchmarking_cli::BlockCmd;
-#[cfg(any(feature = "runtime-benchmarks"))]
-use frame_benchmarking_cli::StorageCmd;
use futures::prelude::*;
use polkadot_primitives::CollatorPair;
use prometheus_endpoint::Registry;
-use sc_cli::{CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
use sc_client_api::BlockchainEvents;
+use sc_client_db::DbHash;
use sc_consensus::{
import_queue::{BasicQueue, Verifier as VerifierT},
- BlockImportParams, DefaultImportQueue, ImportQueue,
+ BlockImportParams, DefaultImportQueue,
};
-use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
-use sc_network::{config::FullNetworkConfiguration, service::traits::NetworkBackend, NetworkBlock};
-use sc_service::{Configuration, Error, PartialComponents, TFullBackend, TFullClient, TaskManager};
-use sc_sysinfo::HwBench;
-use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
+use sc_service::{Configuration, Error, TaskManager};
+use sc_telemetry::TelemetryHandle;
use sc_transaction_pool::FullPool;
use sp_api::ProvideRuntimeApi;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
-use sp_runtime::{app_crypto::AppCrypto, traits::Header as HeaderT};
-use std::{marker::PhantomData, pin::Pin, sync::Arc, time::Duration};
-
-#[cfg(not(feature = "runtime-benchmarks"))]
-type HostFunctions = cumulus_client_service::ParachainHostFunctions;
-
-#[cfg(feature = "runtime-benchmarks")]
-type HostFunctions = (
- cumulus_client_service::ParachainHostFunctions,
- frame_benchmarking::benchmarking::HostFunctions,
-);
-
-pub type ParachainClient = TFullClient>;
-
-pub type ParachainBackend = TFullBackend;
-
-type ParachainBlockImport =
- TParachainBlockImport>, ParachainBackend>;
-
-/// Assembly of PartialComponents (enough to run chain ops subcommands)
-pub type Service = PartialComponents<
- ParachainClient,
- ParachainBackend,
- (),
- sc_consensus::DefaultImportQueue,
- sc_transaction_pool::FullPool>,
- (ParachainBlockImport, Option, Option),
->;
-
-pub(crate) trait BuildImportQueue {
- fn build_import_queue(
- client: Arc>,
- block_import: ParachainBlockImport