diff --git a/nodes/parachain/src/command.rs b/nodes/parachain/src/command.rs index 075905a146..7d1dc0966e 100644 --- a/nodes/parachain/src/command.rs +++ b/nodes/parachain/src/command.rs @@ -47,9 +47,9 @@ macro_rules! construct_async_run { match runtime { ParachainRuntime::Spiritnet(_) => { runner.async_run(|$config| { - let $components = new_partial::( + let $components = new_partial::( &$config, - crate::service::build_import_queue::, + crate::service::build_import_queue::, )?; let task_manager = $components.task_manager; { $( $code )* }.map(|v| (v, task_manager)) @@ -57,9 +57,9 @@ macro_rules! construct_async_run { }, ParachainRuntime::Peregrine(_) => { runner.async_run(|$config| { - let $components = new_partial::( + let $components = new_partial::( &$config, - crate::service::build_import_queue::, + crate::service::build_import_queue::, )?; let task_manager = $components.task_manager; { $( $code )* }.map(|v| (v, task_manager)) @@ -123,7 +123,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { match runtime { ParachainRuntime::Spiritnet(_) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; @@ -131,7 +131,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { cmd.run(partials.client) }), ParachainRuntime::Peregrine(_) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; @@ -187,14 +187,14 @@ pub(crate) fn run() -> sc_cli::Result<()> { } } (BenchmarkCmd::Block(cmd), ParachainRuntime::Spiritnet(_)) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; cmd.run(partials.client) }), (BenchmarkCmd::Block(cmd), ParachainRuntime::Peregrine(_)) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; @@ -208,7 +208,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { )), #[cfg(feature = "runtime-benchmarks")] (BenchmarkCmd::Storage(cmd), ParachainRuntime::Spiritnet(_)) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; @@ -220,7 +220,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { }), #[cfg(feature = "runtime-benchmarks")] (BenchmarkCmd::Storage(cmd), ParachainRuntime::Peregrine(_)) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, crate::service::build_import_queue, )?; @@ -284,7 +284,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { match runtime { ParachainRuntime::Peregrine(_) => { - crate::service::start_node::( + crate::service::start_node::( config, polkadot_config, collator_options, @@ -296,7 +296,7 @@ pub(crate) fn run() -> sc_cli::Result<()> { .map_err(Into::into) }, ParachainRuntime::Spiritnet(_) => { - crate::service::start_node::( + crate::service::start_node::( config, polkadot_config, collator_options, diff --git a/nodes/parachain/src/service.rs b/nodes/parachain/src/service.rs index eb4dd658fb..5624712377 100644 --- a/nodes/parachain/src/service.rs +++ b/nodes/parachain/src/service.rs @@ -32,14 +32,14 @@ use cumulus_primitives_core::{ ParaId, }; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; -use polkadot_service::NativeExecutionDispatch; use sc_consensus::ImportQueue; -use sc_executor::NativeElseWasmExecutor; +use sc_executor::WasmExecutor; use sc_network::NetworkBlock; use sc_network_sync::SyncingService; use sc_service::{Configuration, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; +use sp_io::SubstrateHostFunctions; use sp_keystore::KeystorePtr; use sp_runtime::traits::BlakeTwo256; use std::{sync::Arc, time::Duration}; @@ -54,26 +54,31 @@ type Header = sp_runtime::generic::Header; -type ParachainExecutor = NativeElseWasmExecutor; +#[cfg(not(feature = "runtime-benchmarks"))] +type HostFunctions = SubstrateHostFunctions; +#[cfg(feature = "runtime-benchmarks")] +type HostFunctions = (SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions); -type ParachainClient = TFullClient>; +type ParachainExecutor = WasmExecutor; + +type ParachainClient = TFullClient; type ParachainBackend = TFullBackend; -type ParachainBlockImport = - TParachainBlockImport>, ParachainBackend>; +type ParachainBlockImport = + TParachainBlockImport>, ParachainBackend>; -pub(crate) type TransactionPool = - sc_transaction_pool::FullPool>; +pub(crate) type TransactionPool = + sc_transaction_pool::FullPool>>; -type PartialComponents = sc_service::PartialComponents< - TFullClient>, +type PartialComponents = sc_service::PartialComponents< + TFullClient>, TFullBackend, (), sc_consensus::DefaultImportQueue, - TransactionPool>, + TransactionPool, ( - ParachainBlockImport, + ParachainBlockImport, Option, Option, ), @@ -113,15 +118,13 @@ impl sc_executor::NativeExecutionDispatch for PeregrineRuntimeExecutor { /// /// 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. -pub(crate) fn new_partial( +pub(crate) fn new_partial( config: &Configuration, build_import_queue: BIQ, -) -> Result, sc_service::Error> +) -> Result, sc_service::Error> where - RuntimeApi: ConstructRuntimeApi>> - + Send - + Sync - + 'static, + RuntimeApi: + ConstructRuntimeApi>> + Send + Sync + 'static, RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + sp_session::SessionKeys @@ -129,10 +132,9 @@ where + sp_offchain::OffchainWorkerApi + sp_block_builder::BlockBuilder, sc_client_api::StateBackendFor, Block>: sp_state_machine::Backend, - Executor: NativeExecutionDispatch + 'static, BIQ: FnOnce( - Arc>>, - ParachainBlockImport, + Arc>>, + ParachainBlockImport, &Configuration, Option, &TaskManager, @@ -149,7 +151,14 @@ where }) .transpose()?; - let executor = sc_service::new_native_or_wasm_executor(config); + #[allow(deprecated)] + let executor = ParachainExecutor::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + None, + config.runtime_cache_size, + ); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( config, @@ -173,7 +182,7 @@ where Arc::clone(&client), ); - let block_import = ParachainBlockImport::::new(Arc::clone(&client), Arc::clone(&backend)); + let block_import = ParachainBlockImport::::new(Arc::clone(&client), Arc::clone(&backend)); let import_queue = build_import_queue( Arc::clone(&client), @@ -202,7 +211,7 @@ where /// runtime api. #[allow(clippy::too_many_arguments)] #[sc_tracing::logging::prefix_logs_with("Parachain")] -async fn start_node_impl( +async fn start_node_impl( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, @@ -212,13 +221,11 @@ async fn start_node_impl( hwbench: Option, ) -> sc_service::error::Result<( TaskManager, - Arc>>, + Arc>>, )> where - RuntimeApi: ConstructRuntimeApi>> - + Send - + Sync - + 'static, + RuntimeApi: + ConstructRuntimeApi>> + Send + Sync + 'static, RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + sp_session::SessionKeys @@ -231,15 +238,14 @@ where + sp_consensus_aura::AuraApi + cumulus_primitives_aura::AuraUnincludedSegmentApi, sc_client_api::StateBackendFor, Block>: sp_state_machine::Backend, - Executor: sc_executor::NativeExecutionDispatch + 'static, RB: FnOnce( - Arc>>, + Arc>>, ) -> Result, sc_service::Error> + Send + 'static, BIQ: FnOnce( - Arc>>, - ParachainBlockImport, + Arc>>, + ParachainBlockImport, &Configuration, Option, &TaskManager, @@ -247,7 +253,7 @@ where { let parachain_config = prepare_node_config(parachain_config); - let params = new_partial::(¶chain_config, build_import_queue)?; + let params = new_partial::(¶chain_config, build_import_queue)?; let (block_import, mut telemetry, telemetry_worker_handle) = params.other; let client = Arc::clone(¶ms.client); @@ -357,7 +363,7 @@ where })?; if validator { - start_consensus::( + start_consensus::( Arc::clone(&client), Arc::clone(&backend), block_import, @@ -383,16 +389,15 @@ where #[allow(clippy::type_complexity)] /// Build the import queue for THE runtime. -pub(crate) fn build_import_queue( - client: Arc>>, - block_import: ParachainBlockImport, +pub(crate) fn build_import_queue( + client: Arc>>, + block_import: ParachainBlockImport, config: &Configuration, telemetry: Option, task_manager: &TaskManager, ) -> Result, sc_service::Error> where - RE: sc_executor::NativeExecutionDispatch + 'static, - API: ConstructRuntimeApi>> + Send + Sync + 'static, + API: ConstructRuntimeApi>> + Send + Sync + 'static, API::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + sp_session::SessionKeys @@ -430,16 +435,15 @@ where } /// Start a parachain node. -pub(crate) async fn start_node( +pub(crate) async fn start_node( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, id: ParaId, hwbench: Option, -) -> sc_service::error::Result<(TaskManager, Arc>>)> +) -> sc_service::error::Result<(TaskManager, Arc>>)> where - RE: sc_executor::NativeExecutionDispatch + 'static, - API: ConstructRuntimeApi>> + Send + Sync + 'static, + API: ConstructRuntimeApi>> + Send + Sync + 'static, API::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + sp_session::SessionKeys @@ -453,28 +457,28 @@ where + cumulus_primitives_aura::AuraUnincludedSegmentApi, sc_client_api::StateBackendFor, Block>: sp_state_machine::Backend, { - start_node_impl::( + start_node_impl::( parachain_config, polkadot_config, collator_options, id, |_| Ok(RpcModule::new(())), - build_import_queue::, + build_import_queue::, hwbench, ) .await } #[allow(clippy::too_many_arguments)] -fn start_consensus( - client: Arc>, +fn start_consensus( + client: Arc>, backend: Arc, - block_import: ParachainBlockImport, + block_import: ParachainBlockImport, prometheus_registry: Option<&Registry>, telemetry: Option, task_manager: &TaskManager, relay_chain_interface: Arc, - transaction_pool: Arc>>, + transaction_pool: Arc>>, sync_oracle: Arc>, keystore: KeystorePtr, relay_chain_slot_duration: Duration, @@ -484,10 +488,8 @@ fn start_consensus( announce_block: Arc>) + Send + Sync>, ) -> Result<(), sc_service::Error> where - RuntimeApi: ConstructRuntimeApi>> - + Send - + Sync - + 'static, + RuntimeApi: + ConstructRuntimeApi>> + Send + Sync + 'static, RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::Metadata + sp_session::SessionKeys @@ -499,7 +501,6 @@ where + substrate_frame_rpc_system::AccountNonceApi + sp_consensus_aura::AuraApi + cumulus_primitives_aura::AuraUnincludedSegmentApi, - Executor: sc_executor::NativeExecutionDispatch + 'static, { use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; diff --git a/nodes/standalone/src/service.rs b/nodes/standalone/src/service.rs index bca98ac4ef..8afb22fac7 100644 --- a/nodes/standalone/src/service.rs +++ b/nodes/standalone/src/service.rs @@ -23,11 +23,12 @@ use futures::FutureExt; use sc_client_api::{Backend, BlockBackend}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; use sc_consensus_grandpa::SharedVoterState; -use sc_executor::NativeElseWasmExecutor; +use sc_executor::WasmExecutor; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_consensus_aura::ed25519::AuthorityPair as AuraPair; +use sp_io::SubstrateHostFunctions; use std::{sync::Arc, time::Duration}; @@ -48,7 +49,12 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { } } -type FullClient = sc_service::TFullClient>; +#[cfg(not(feature = "runtime-benchmarks"))] +type HostFunctions = SubstrateHostFunctions; +#[cfg(feature = "runtime-benchmarks")] +type HostFunctions = (SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions); + +type FullClient = sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -82,7 +88,14 @@ pub(crate) fn new_partial(config: &Configuration) -> Result::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + None, + config.runtime_cache_size, + ); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( config, @@ -109,7 +122,7 @@ pub(crate) fn new_partial(config: &Configuration) -> Result), + &(Arc::clone(&client)), select_chain.clone(), telemetry.as_ref().map(|x| x.handle()), )?;