From edffda783bc1d4fea56e13fa14a121f77ae41daf Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 24 Jun 2024 15:37:36 +0800 Subject: [PATCH] paritytech/polkadot-sdk#2521 Signed-off-by: Xavier Lau --- node/src/command.rs | 24 +++---- node/src/service/executors.rs | 80 ----------------------- node/src/service/mod.rs | 117 ++++++++++++++-------------------- 3 files changed, 60 insertions(+), 161 deletions(-) delete mode 100644 node/src/service/executors.rs diff --git a/node/src/command.rs b/node/src/command.rs index fc348e3b3..60f2f1d37 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -240,7 +240,7 @@ pub fn run() -> Result<()> { ($config:expr, $cli:ident, |$partials:ident| $code:expr) => {{ #[cfg(feature = "crab-native")] if $config.chain_spec.is_crab() { - let $partials = service::new_partial::( + let $partials = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config(), )?; @@ -250,7 +250,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "darwinia-native")] if $config.chain_spec.is_darwinia() { - let $partials = service::new_partial::( + let $partials = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config(), )?; @@ -260,7 +260,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "koi-native")] if $config.chain_spec.is_koi() { - let $partials = service::new_partial::( + let $partials = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config(), )?; @@ -282,7 +282,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "crab-native")] if chain_spec.is_crab() { return runner.async_run(|$config| { - let $components = service::new_partial::( + let $components = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config() )?; @@ -295,7 +295,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "darwinia-native")] if chain_spec.is_darwinia() { return runner.async_run(|$config| { - let $components = service::new_partial::( + let $components = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config() )?; @@ -308,7 +308,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "koi-native")] if chain_spec.is_koi() { return runner.async_run(|$config| { - let $components = service::new_partial::( + let $components = service::new_partial::( &$config, &$cli.eth_args.build_eth_rpc_config() )?; @@ -506,7 +506,7 @@ pub fn run() -> Result<()> { if chain_spec.is_dev() { #[cfg(feature = "crab-native")] if chain_spec.is_crab() { - return service::start_dev_node::( + return service::start_dev_node::( config, ð_rpc_config, ) @@ -515,7 +515,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "darwinia-native")] if chain_spec.is_darwinia() { - return service::start_dev_node::( + return service::start_dev_node::( config, ð_rpc_config, ) @@ -524,7 +524,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "koi-native")] if chain_spec.is_koi() { - return service::start_dev_node::( + return service::start_dev_node::( config, ð_rpc_config, ) @@ -538,7 +538,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "crab-native")] if chain_spec.is_crab() { - return service::start_parachain_node::( + return service::start_parachain_node::( config, polkadot_config, collator_options, @@ -553,7 +553,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "darwinia-native")] if chain_spec.is_darwinia() { - return service::start_parachain_node::( + return service::start_parachain_node::( config, polkadot_config, collator_options, @@ -568,7 +568,7 @@ pub fn run() -> Result<()> { #[cfg(feature = "koi-native")] if chain_spec.is_koi() { - return service::start_parachain_node::( + return service::start_parachain_node::( config, polkadot_config, collator_options, diff --git a/node/src/service/executors.rs b/node/src/service/executors.rs deleted file mode 100644 index 0da755248..000000000 --- a/node/src/service/executors.rs +++ /dev/null @@ -1,80 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia 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. -// -// Darwinia 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 Darwinia. If not, see . - -// substrate -use sc_executor::{NativeExecutionDispatch, NativeVersion}; - -#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))] -pub type HostFunctions = ( - frame_benchmarking::benchmarking::HostFunctions, - moonbeam_primitives_ext::moonbeam_ext::HostFunctions, -); -#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))] -pub type HostFunctions = frame_benchmarking::benchmarking::HostFunctions; -#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))] -pub type HostFunctions = moonbeam_primitives_ext::moonbeam_ext::HostFunctions; -#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))] -pub type HostFunctions = (); - -/// Darwinia native executor instance. -#[cfg(feature = "darwinia-native")] -pub struct DarwiniaRuntimeExecutor; -#[cfg(feature = "darwinia-native")] -impl NativeExecutionDispatch for DarwiniaRuntimeExecutor { - type ExtendHostFunctions = HostFunctions; - - fn dispatch(method: &str, data: &[u8]) -> Option> { - darwinia_runtime::api::dispatch(method, data) - } - - fn native_version() -> NativeVersion { - darwinia_runtime::native_version() - } -} - -/// Crab native executor instance. -#[cfg(feature = "crab-native")] -pub struct CrabRuntimeExecutor; -#[cfg(feature = "crab-native")] -impl NativeExecutionDispatch for CrabRuntimeExecutor { - type ExtendHostFunctions = HostFunctions; - - fn dispatch(method: &str, data: &[u8]) -> Option> { - crab_runtime::api::dispatch(method, data) - } - - fn native_version() -> NativeVersion { - crab_runtime::native_version() - } -} - -/// Koi native executor instance. -#[cfg(feature = "koi-native")] -pub struct KoiRuntimeExecutor; -#[cfg(feature = "koi-native")] -impl NativeExecutionDispatch for KoiRuntimeExecutor { - type ExtendHostFunctions = HostFunctions; - - fn dispatch(method: &str, data: &[u8]) -> Option> { - koi_runtime::api::dispatch(method, data) - } - - fn native_version() -> NativeVersion { - koi_runtime::native_version() - } -} diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index 4d78ba730..7beea86dc 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -18,9 +18,6 @@ //! Service and service factory implementation. Specialized wrapper over substrate service. -pub mod executors; -pub use executors::*; - pub mod frontier; mod instant_finalize; @@ -47,30 +44,44 @@ use sc_client_api::Backend; use sc_consensus::ImportQueue; use sc_network::NetworkBlock; +#[cfg(all(feature = "runtime-benchmarks", feature = "evm-tracing"))] +type HostFunctions = ( + frame_benchmarking::benchmarking::HostFunctions, + moonbeam_primitives_ext::moonbeam_ext::HostFunctions, + sp_io::SubstrateHostFunctions, +); +#[cfg(all(feature = "runtime-benchmarks", not(feature = "evm-tracing")))] +type HostFunctions = + (frame_benchmarking::benchmarking::HostFunctions, sp_io::SubstrateHostFunctions); +#[cfg(all(not(feature = "runtime-benchmarks"), feature = "evm-tracing"))] +type HostFunctions = + (moonbeam_primitives_ext::moonbeam_ext::HostFunctions, sp_io::SubstrateHostFunctions); +#[cfg(not(any(feature = "evm-tracing", feature = "runtime-benchmarks")))] +type HostFunctions = sp_io::SubstrateHostFunctions; + /// Full client backend type. type FullBackend = sc_service::TFullBackend; /// Full client type. -type FullClient = - sc_service::TFullClient>; +type FullClient = + sc_service::TFullClient>; /// Parachain specific block import. -type ParachainBlockImport = - cumulus_client_consensus_common::ParachainBlockImport< - Block, - Arc>, - FullBackend, - >; -type Service = sc_service::PartialComponents< - FullClient, +type ParachainBlockImport = cumulus_client_consensus_common::ParachainBlockImport< + Block, + Arc>, + FullBackend, +>; +type Service = sc_service::PartialComponents< + FullClient, FullBackend, sc_consensus::LongestChain, sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool>, + sc_transaction_pool::FullPool>, ( fc_db::Backend, Option, fc_rpc_core::types::FeeHistoryCache, fc_rpc_core::types::FeeHistoryCacheLimit, - ParachainBlockImport, + ParachainBlockImport, Option, Option, ), @@ -147,17 +158,13 @@ impl RuntimeApiCollection for Api where /// 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. #[allow(clippy::type_complexity)] -pub fn new_partial( +pub fn new_partial( config: &sc_service::Configuration, eth_rpc_config: &crate::cli::EthRpcConfig, -) -> Result, sc_service::Error> +) -> Result, sc_service::Error> where - RuntimeApi: 'static - + Send - + Sync - + sp_api::ConstructRuntimeApi>, + RuntimeApi: 'static + Send + Sync + sp_api::ConstructRuntimeApi>, RuntimeApi::RuntimeApi: RuntimeApiCollection, - Executor: 'static + sc_executor::NativeExecutionDispatch, { let telemetry = config .telemetry_endpoints @@ -169,19 +176,7 @@ where Ok((worker, telemetry)) }) .transpose()?; - let heap_pages = - config.default_heap_pages.map_or(sc_executor::DEFAULT_HEAP_ALLOC_STRATEGY, |h| { - sc_executor::HeapAllocStrategy::Static { extra_pages: h as _ } - }); - let wasm_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 executor = - >::new_with_wasm_executor(wasm_executor); + let executor = sc_service::new_wasm_executor::(config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( config, @@ -240,7 +235,7 @@ where /// This is the actual implementation that is abstract over the executor and the 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: sc_service::Configuration, polkadot_config: sc_service::Configuration, collator_options: cumulus_client_cli::CollatorOptions, @@ -249,22 +244,18 @@ async fn start_node_impl( start_consensus: SC, hwbench: Option, eth_rpc_config: &crate::cli::EthRpcConfig, -) -> sc_service::error::Result<(sc_service::TaskManager, Arc>)> +) -> sc_service::error::Result<(sc_service::TaskManager, Arc>)> where - RuntimeApi: 'static - + Send - + Sync - + sp_api::ConstructRuntimeApi>, + RuntimeApi: 'static + Send + Sync + sp_api::ConstructRuntimeApi>, RuntimeApi::RuntimeApi: RuntimeApiCollection, - Executor: 'static + sc_executor::NativeExecutionDispatch, SC: FnOnce( - Arc>, - ParachainBlockImport, + Arc>, + ParachainBlockImport, Option<&substrate_prometheus_endpoint::Registry>, Option, &sc_service::TaskManager, Arc, - Arc>>, + Arc>>, Arc>, sp_keystore::KeystorePtr, Duration, @@ -293,7 +284,7 @@ where mut telemetry, telemetry_worker_handle, ), - } = new_partial::(¶chain_config, eth_rpc_config)?; + } = new_partial::(¶chain_config, eth_rpc_config)?; let (relay_chain_interface, collator_key) = cumulus_client_service::build_relay_chain_interface( @@ -539,20 +530,16 @@ where } /// Build the import queue for the parachain runtime. -pub fn build_import_queue( - client: Arc>, - block_import: ParachainBlockImport, +pub fn build_import_queue( + client: Arc>, + block_import: ParachainBlockImport, config: &sc_service::Configuration, telemetry: Option, task_manager: &sc_service::TaskManager, ) -> Result, sc_service::Error> where - RuntimeApi: 'static - + Send - + Sync - + sp_api::ConstructRuntimeApi>, + RuntimeApi: 'static + Send + Sync + sp_api::ConstructRuntimeApi>, RuntimeApi::RuntimeApi: RuntimeApiCollection, - Executor: 'static + sc_executor::NativeExecutionDispatch, { let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; @@ -578,25 +565,21 @@ where } /// Start a parachain node. -pub async fn start_parachain_node( +pub async fn start_parachain_node( parachain_config: sc_service::Configuration, polkadot_config: sc_service::Configuration, collator_options: cumulus_client_cli::CollatorOptions, para_id: cumulus_primitives_core::ParaId, hwbench: Option, eth_rpc_config: &crate::cli::EthRpcConfig, -) -> sc_service::error::Result<(sc_service::TaskManager, Arc>)> +) -> sc_service::error::Result<(sc_service::TaskManager, Arc>)> where - RuntimeApi: sp_api::ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: sp_api::ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, RuntimeApi::RuntimeApi: sp_consensus_aura::AuraApi, - Executor: 'static + sc_executor::NativeExecutionDispatch, { - start_node_impl::( + start_node_impl::( parachain_config, polkadot_config, collator_options, @@ -673,19 +656,15 @@ where /// Start a dev node which can seal instantly. /// !!! WARNING: DO NOT USE ELSEWHERE -pub fn start_dev_node( +pub fn start_dev_node( mut config: sc_service::Configuration, eth_rpc_config: &crate::cli::EthRpcConfig, ) -> Result where - RuntimeApi: sp_api::ConstructRuntimeApi> - + Send - + Sync - + 'static, + RuntimeApi: sp_api::ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: RuntimeApiCollection, RuntimeApi::RuntimeApi: sp_consensus_aura::AuraApi, - Executor: 'static + sc_executor::NativeExecutionDispatch, { // substrate use sc_client_api::HeaderBackend; @@ -708,7 +687,7 @@ where _telemetry, _telemetry_worker_handle, ), - } = new_partial::(&config, eth_rpc_config)?; + } = new_partial::(&config, eth_rpc_config)?; let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =