difftreelog
Merge pull request #901 from UniqueNetwork/feature/unify-nodes
in: master
6 files changed
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -36,11 +36,17 @@
sc-executor = { workspace = true }
-opal-runtime = { workspace = true }
+opal-runtime = { workspace = true, optional = true }
quartz-runtime = { workspace = true, optional = true }
unique-runtime = { workspace = true, optional = true }
[features]
+default = ['opal-runtime']
+all-runtimes = [
+ 'opal-runtime',
+ 'quartz-runtime',
+ 'unique-runtime',
+]
pov-estimate = [
'opal-runtime/pov-estimate',
'quartz-runtime?/pov-estimate',
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -99,6 +99,11 @@
[features]
default = ["opal-runtime"]
+all-runtimes = [
+ 'opal-runtime',
+ 'quartz-runtime',
+ 'unique-runtime',
+]
pov-estimate = [
'opal-runtime/pov-estimate',
'quartz-runtime?/pov-estimate',
node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -15,11 +15,9 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use crate::chain_spec;
-use std::{path::PathBuf, env};
+use std::path::PathBuf;
use clap::Parser;
-const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";
-
/// Sub-commands supported by the collator.
#[derive(Debug, Parser)]
pub enum Subcommand {
@@ -99,21 +97,7 @@
impl Cli {
pub fn node_name() -> String {
- match env::var(NODE_NAME_ENV).ok() {
- Some(name) => name,
- None => {
- if cfg!(feature = "unique-runtime") {
- "Unique"
- } else if cfg!(feature = "sapphire-runtime") {
- "Sapphire"
- } else if cfg!(feature = "quartz-runtime") {
- "Quartz"
- } else {
- "Opal"
- }
- }
- .into(),
- }
+ "Unique".into()
}
}
node/cli/src/service.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// std18use std::sync::Arc;19use std::sync::Mutex;20use std::collections::BTreeMap;21use std::time::Duration;22use std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25 Stream, StreamExt,26 stream::select,27 task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38 ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41 prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;61use sc_consensus::ImportQueue;6263use polkadot_service::CollatorPair;6465// Frontier Imports66use fc_rpc_core::types::FilterPool;67use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6869use up_common::types::opaque::*;7071#[cfg(feature = "pov-estimate")]72use crate::chain_spec::RuntimeIdentification;7374/// Unique native executor instance.75#[cfg(feature = "unique-runtime")]76pub struct UniqueRuntimeExecutor;7778#[cfg(feature = "quartz-runtime")]79/// Quartz native executor instance.80pub struct QuartzRuntimeExecutor;8182/// Opal native executor instance.83pub struct OpalRuntimeExecutor;8485#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]86pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;8788#[cfg(all(89 not(feature = "unique-runtime"),90 feature = "quartz-runtime",91 feature = "runtime-benchmarks"92))]93pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9495#[cfg(all(96 not(feature = "unique-runtime"),97 not(feature = "quartz-runtime"),98 feature = "runtime-benchmarks"99))]100pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;101102#[cfg(feature = "unique-runtime")]103impl NativeExecutionDispatch for UniqueRuntimeExecutor {104 /// Only enable the benchmarking host functions when we actually want to benchmark.105 #[cfg(feature = "runtime-benchmarks")]106 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;107 /// Otherwise we only use the default Substrate host functions.108 #[cfg(not(feature = "runtime-benchmarks"))]109 type ExtendHostFunctions = ();110111 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {112 unique_runtime::api::dispatch(method, data)113 }114115 fn native_version() -> sc_executor::NativeVersion {116 unique_runtime::native_version()117 }118}119120#[cfg(feature = "quartz-runtime")]121impl NativeExecutionDispatch for QuartzRuntimeExecutor {122 /// Only enable the benchmarking host functions when we actually want to benchmark.123 #[cfg(feature = "runtime-benchmarks")]124 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;125 /// Otherwise we only use the default Substrate host functions.126 #[cfg(not(feature = "runtime-benchmarks"))]127 type ExtendHostFunctions = ();128129 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {130 quartz_runtime::api::dispatch(method, data)131 }132133 fn native_version() -> sc_executor::NativeVersion {134 quartz_runtime::native_version()135 }136}137138impl NativeExecutionDispatch for OpalRuntimeExecutor {139 /// Only enable the benchmarking host functions when we actually want to benchmark.140 #[cfg(feature = "runtime-benchmarks")]141 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;142 /// Otherwise we only use the default Substrate host functions.143 #[cfg(not(feature = "runtime-benchmarks"))]144 type ExtendHostFunctions = ();145146 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {147 opal_runtime::api::dispatch(method, data)148 }149150 fn native_version() -> sc_executor::NativeVersion {151 opal_runtime::native_version()152 }153}154155pub struct AutosealInterval {156 interval: Interval,157}158159impl AutosealInterval {160 pub fn new(config: &Configuration, interval: Duration) -> Self {161 let _tokio_runtime = config.tokio_handle.enter();162 let interval = tokio::time::interval(interval);163164 Self { interval }165 }166}167168impl Stream for AutosealInterval {169 type Item = tokio::time::Instant;170171 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {172 self.interval.poll_tick(cx).map(Some)173 }174}175176pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(177 client: Arc<C>,178 config: &Configuration,179) -> Result<Arc<fc_db::Backend<Block>>, String> {180 let config_dir = config181 .base_path182 .as_ref()183 .map(|base_path| base_path.config_dir(config.chain_spec.id()))184 .unwrap_or_else(|| {185 BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())186 });187 let database_dir = config_dir.join("frontier").join("db");188189 Ok(Arc::new(fc_db::Backend::<Block>::new(190 client,191 &fc_db::DatabaseSettings {192 source: fc_db::DatabaseSource::RocksDb {193 path: database_dir,194 cache_size: 0,195 },196 },197 )?))198}199200type FullClient<RuntimeApi, ExecutorDispatch> =201 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;202type FullBackend = sc_service::TFullBackend<Block>;203type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;204type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =205 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;206207/// Starts a `ServiceBuilder` for a full service.208///209/// Use this macro if you don't actually need the full service, but just the builder in order to210/// be able to perform chain operations.211#[allow(clippy::type_complexity)]212pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(213 config: &Configuration,214 build_import_queue: BIQ,215) -> Result<216 PartialComponents<217 FullClient<RuntimeApi, ExecutorDispatch>,218 FullBackend,219 FullSelectChain,220 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,221 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,222 (223 Option<Telemetry>,224 Option<FilterPool>,225 Arc<fc_db::Backend<Block>>,226 Option<TelemetryWorkerHandle>,227 FeeHistoryCache,228 ),229 >,230 sc_service::Error,231>232where233 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,234 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>235 + Send236 + Sync237 + 'static,238 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,239 ExecutorDispatch: NativeExecutionDispatch + 'static,240 BIQ: FnOnce(241 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,242 Arc<FullBackend>,243 &Configuration,244 Option<TelemetryHandle>,245 &TaskManager,246 ) -> Result<247 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,248 sc_service::Error,249 >,250{251 let _telemetry = config252 .telemetry_endpoints253 .clone()254 .filter(|x| !x.is_empty())255 .map(|endpoints| -> Result<_, sc_telemetry::Error> {256 let worker = TelemetryWorker::new(16)?;257 let telemetry = worker.handle().new_telemetry(endpoints);258 Ok((worker, telemetry))259 })260 .transpose()?;261262 let telemetry = config263 .telemetry_endpoints264 .clone()265 .filter(|x| !x.is_empty())266 .map(|endpoints| -> Result<_, sc_telemetry::Error> {267 let worker = TelemetryWorker::new(16)?;268 let telemetry = worker.handle().new_telemetry(endpoints);269 Ok((worker, telemetry))270 })271 .transpose()?;272273 let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(274 config.wasm_method,275 config.default_heap_pages,276 config.max_runtime_instances,277 config.runtime_cache_size,278 );279280 let (client, backend, keystore_container, task_manager) =281 sc_service::new_full_parts::<Block, RuntimeApi, _>(282 config,283 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),284 executor,285 )?;286 let client = Arc::new(client);287288 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());289290 let telemetry = telemetry.map(|(worker, telemetry)| {291 task_manager292 .spawn_handle()293 .spawn("telemetry", None, worker.run());294 telemetry295 });296297 let select_chain = sc_consensus::LongestChain::new(backend.clone());298299 let transaction_pool = sc_transaction_pool::BasicPool::new_full(300 config.transaction_pool.clone(),301 config.role.is_authority().into(),302 config.prometheus_registry(),303 task_manager.spawn_essential_handle(),304 client.clone(),305 );306307 let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));308309 let frontier_backend = open_frontier_backend(client.clone(), config)?;310311 let import_queue = build_import_queue(312 client.clone(),313 backend.clone(),314 config,315 telemetry.as_ref().map(|telemetry| telemetry.handle()),316 &task_manager,317 )?;318 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));319320 let params = PartialComponents {321 backend,322 client,323 import_queue,324 keystore_container,325 task_manager,326 transaction_pool,327 select_chain,328 other: (329 telemetry,330 filter_pool,331 frontier_backend,332 telemetry_worker_handle,333 fee_history_cache,334 ),335 };336337 Ok(params)338}339340async fn build_relay_chain_interface(341 polkadot_config: Configuration,342 parachain_config: &Configuration,343 telemetry_worker_handle: Option<TelemetryWorkerHandle>,344 task_manager: &mut TaskManager,345 collator_options: CollatorOptions,346 hwbench: Option<sc_sysinfo::HwBench>,347) -> RelayChainResult<(348 Arc<(dyn RelayChainInterface + 'static)>,349 Option<CollatorPair>,350)> {351 if collator_options.relay_chain_rpc_urls.is_empty() {352 build_inprocess_relay_chain(353 polkadot_config,354 parachain_config,355 telemetry_worker_handle,356 task_manager,357 hwbench,358 )359 } else {360 build_minimal_relay_chain_node(361 polkadot_config,362 task_manager,363 collator_options.relay_chain_rpc_urls,364 )365 .await366 }367}368369/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.370///371/// This is the actual implementation that is abstract over the executor and the runtime api.372#[sc_tracing::logging::prefix_logs_with("Parachain")]373async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(374 parachain_config: Configuration,375 polkadot_config: Configuration,376 collator_options: CollatorOptions,377 id: ParaId,378 build_import_queue: BIQ,379 build_consensus: BIC,380 hwbench: Option<sc_sysinfo::HwBench>,381) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>382where383 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,384 Runtime: RuntimeInstance + Send + Sync + 'static,385 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,386 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,387 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>388 + Send389 + Sync390 + 'static,391 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>392 + fp_rpc::EthereumRuntimeRPCApi<Block>393 + fp_rpc::ConvertTransactionRuntimeApi<Block>394 + sp_session::SessionKeys<Block>395 + sp_block_builder::BlockBuilder<Block>396 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>397 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>398 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>399 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>400 + up_pov_estimate_rpc::PovEstimateApi<Block>401 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>402 + sp_api::Metadata<Block>403 + sp_offchain::OffchainWorkerApi<Block>404 + cumulus_primitives_core::CollectCollationInfo<Block>,405 ExecutorDispatch: NativeExecutionDispatch + 'static,406 BIQ: FnOnce(407 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,408 Arc<FullBackend>,409 &Configuration,410 Option<TelemetryHandle>,411 &TaskManager,412 ) -> Result<413 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,414 sc_service::Error,415 >,416 BIC: FnOnce(417 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,418 Arc<FullBackend>,419 Option<&Registry>,420 Option<TelemetryHandle>,421 &TaskManager,422 Arc<dyn RelayChainInterface>,423 Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,424 Arc<NetworkService<Block, Hash>>,425 SyncCryptoStorePtr,426 bool,427 ) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,428{429 let parachain_config = prepare_node_config(parachain_config);430431 let params =432 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;433 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =434 params.other;435436 let client = params.client.clone();437 let backend = params.backend.clone();438 let mut task_manager = params.task_manager;439440 let (relay_chain_interface, collator_key) = build_relay_chain_interface(441 polkadot_config,442 ¶chain_config,443 telemetry_worker_handle,444 &mut task_manager,445 collator_options.clone(),446 hwbench.clone(),447 )448 .await449 .map_err(|e| match e {450 RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,451 s => s.to_string().into(),452 })?;453454 let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);455456 let force_authoring = parachain_config.force_authoring;457 let validator = parachain_config.role.is_authority();458 let prometheus_registry = parachain_config.prometheus_registry().cloned();459 let transaction_pool = params.transaction_pool.clone();460 let import_queue_service = params.import_queue.service();461462 let (network, system_rpc_tx, tx_handler_controller, start_network) =463 sc_service::build_network(sc_service::BuildNetworkParams {464 config: ¶chain_config,465 client: client.clone(),466 transaction_pool: transaction_pool.clone(),467 spawn_handle: task_manager.spawn_handle(),468 import_queue: params.import_queue,469 block_announce_validator_builder: Some(Box::new(|_| {470 Box::new(block_announce_validator)471 })),472 warp_sync_params: None,473 })?;474475 let rpc_client = client.clone();476 let rpc_pool = transaction_pool.clone();477 let select_chain = params.select_chain.clone();478 let rpc_network = network.clone();479480 let rpc_frontier_backend = frontier_backend.clone();481482 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(483 task_manager.spawn_handle(),484 overrides_handle::<_, _, Runtime>(client.clone()),485 50,486 50,487 prometheus_registry.clone(),488 ));489490 task_manager.spawn_essential_handle().spawn(491 "frontier-mapping-sync-worker",492 None,493 MappingSyncWorker::new(494 client.import_notification_stream(),495 Duration::new(6, 0),496 client.clone(),497 backend.clone(),498 overrides_handle::<_, _, Runtime>(client.clone()),499 frontier_backend.clone(),500 3,501 0,502 SyncStrategy::Normal,503 )504 .for_each(|()| futures::future::ready(())),505 );506507 #[cfg(feature = "pov-estimate")]508 let rpc_backend = backend.clone();509510 #[cfg(feature = "pov-estimate")]511 let runtime_id = parachain_config.chain_spec.runtime_id();512513 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {514 let full_deps = unique_rpc::FullDeps {515 #[cfg(feature = "pov-estimate")]516 runtime_id: runtime_id.clone(),517518 #[cfg(feature = "pov-estimate")]519 exec_params: uc_rpc::pov_estimate::ExecutorParams {520 wasm_method: parachain_config.wasm_method,521 default_heap_pages: parachain_config.default_heap_pages,522 max_runtime_instances: parachain_config.max_runtime_instances,523 runtime_cache_size: parachain_config.runtime_cache_size,524 },525526 #[cfg(feature = "pov-estimate")]527 backend: rpc_backend.clone(),528529 eth_backend: rpc_frontier_backend.clone(),530 deny_unsafe,531 client: rpc_client.clone(),532 pool: rpc_pool.clone(),533 graph: rpc_pool.pool().clone(),534 // TODO: Unhardcode535 enable_dev_signer: false,536 filter_pool: filter_pool.clone(),537 network: rpc_network.clone(),538 select_chain: select_chain.clone(),539 is_authority: validator,540 // TODO: Unhardcode541 max_past_logs: 10000,542 block_data_cache: block_data_cache.clone(),543 fee_history_cache: fee_history_cache.clone(),544 // TODO: Unhardcode545 fee_history_limit: 2048,546 };547548 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(549 full_deps,550 subscription_task_executor,551 )552 .map_err(Into::into)553 });554555 sc_service::spawn_tasks(sc_service::SpawnTasksParams {556 rpc_builder,557 client: client.clone(),558 transaction_pool: transaction_pool.clone(),559 task_manager: &mut task_manager,560 config: parachain_config,561 keystore: params.keystore_container.sync_keystore(),562 backend: backend.clone(),563 network: network.clone(),564 system_rpc_tx,565 telemetry: telemetry.as_mut(),566 tx_handler_controller,567 })?;568569 if let Some(hwbench) = hwbench {570 sc_sysinfo::print_hwbench(&hwbench);571572 if let Some(ref mut telemetry) = telemetry {573 let telemetry_handle = telemetry.handle();574 task_manager.spawn_handle().spawn(575 "telemetry_hwbench",576 None,577 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),578 );579 }580 }581582 let announce_block = {583 let network = network.clone();584 Arc::new(Box::new(move |hash, data| {585 network.announce_block(hash, data)586 }))587 };588589 let relay_chain_slot_duration = Duration::from_secs(6);590591 let overseer_handle = relay_chain_interface592 .overseer_handle()593 .map_err(|e| sc_service::Error::Application(Box::new(e)))?;594595 if validator {596 let parachain_consensus = build_consensus(597 client.clone(),598 backend.clone(),599 prometheus_registry.as_ref(),600 telemetry.as_ref().map(|t| t.handle()),601 &task_manager,602 relay_chain_interface.clone(),603 transaction_pool,604 network,605 params.keystore_container.sync_keystore(),606 force_authoring,607 )?;608609 let spawner = task_manager.spawn_handle();610611 let params = StartCollatorParams {612 para_id: id,613 block_status: client.clone(),614 announce_block,615 client: client.clone(),616 task_manager: &mut task_manager,617 spawner,618 parachain_consensus,619 import_queue: import_queue_service,620 collator_key: collator_key.expect("Command line arguments do not allow this. qed"),621 relay_chain_interface,622 relay_chain_slot_duration,623 recovery_handle: Box::new(overseer_handle),624 };625626 start_collator(params).await?;627 } else {628 let params = StartFullNodeParams {629 client: client.clone(),630 announce_block,631 task_manager: &mut task_manager,632 para_id: id,633 import_queue: import_queue_service,634 relay_chain_interface,635 relay_chain_slot_duration,636 recovery_handle: Box::new(overseer_handle),637 };638639 start_full_node(params)?;640 }641642 start_network.start_network();643644 Ok((task_manager, client))645}646647/// Build the import queue for the the parachain runtime.648pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(649 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,650 backend: Arc<FullBackend>,651 config: &Configuration,652 telemetry: Option<TelemetryHandle>,653 task_manager: &TaskManager,654) -> Result<655 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,656 sc_service::Error,657>658where659 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>660 + Send661 + Sync662 + 'static,663 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>664 + sp_block_builder::BlockBuilder<Block>665 + sp_consensus_aura::AuraApi<Block, AuraId>666 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,667 ExecutorDispatch: NativeExecutionDispatch + 'static,668{669 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;670671 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());672673 cumulus_client_consensus_aura::import_queue::<674 sp_consensus_aura::sr25519::AuthorityPair,675 _,676 _,677 _,678 _,679 _,680 >(cumulus_client_consensus_aura::ImportQueueParams {681 block_import,682 client: client.clone(),683 create_inherent_data_providers: move |_, _| async move {684 let time = sp_timestamp::InherentDataProvider::from_system_time();685686 let slot =687 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(688 *time,689 slot_duration,690 );691692 Ok((slot, time))693 },694 registry: config.prometheus_registry(),695 spawner: &task_manager.spawn_essential_handle(),696 telemetry,697 })698 .map_err(Into::into)699}700701/// Start a normal parachain node.702pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(703 parachain_config: Configuration,704 polkadot_config: Configuration,705 collator_options: CollatorOptions,706 id: ParaId,707 hwbench: Option<sc_sysinfo::HwBench>,708) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>709where710 Runtime: RuntimeInstance + Send + Sync + 'static,711 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,712 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,713 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>714 + Send715 + Sync716 + 'static,717 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>718 + fp_rpc::EthereumRuntimeRPCApi<Block>719 + fp_rpc::ConvertTransactionRuntimeApi<Block>720 + sp_session::SessionKeys<Block>721 + sp_block_builder::BlockBuilder<Block>722 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>723 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>724 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>725 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>726 + up_pov_estimate_rpc::PovEstimateApi<Block>727 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>728 + sp_api::Metadata<Block>729 + sp_offchain::OffchainWorkerApi<Block>730 + cumulus_primitives_core::CollectCollationInfo<Block>731 + sp_consensus_aura::AuraApi<Block, AuraId>,732 ExecutorDispatch: NativeExecutionDispatch + 'static,733{734 start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(735 parachain_config,736 polkadot_config,737 collator_options,738 id,739 parachain_build_import_queue,740 |client,741 backend,742 prometheus_registry,743 telemetry,744 task_manager,745 relay_chain_interface,746 transaction_pool,747 sync_oracle,748 keystore,749 force_authoring| {750 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;751752 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(753 task_manager.spawn_handle(),754 client.clone(),755 transaction_pool,756 prometheus_registry,757 telemetry.clone(),758 );759760 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());761762 Ok(AuraConsensus::build::<763 sp_consensus_aura::sr25519::AuthorityPair,764 _,765 _,766 _,767 _,768 _,769 _,770 >(BuildAuraConsensusParams {771 proposer_factory,772 create_inherent_data_providers: move |_, (relay_parent, validation_data)| {773 let relay_chain_interface = relay_chain_interface.clone();774 async move {775 let parachain_inherent =776 cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(777 relay_parent,778 &relay_chain_interface,779 &validation_data,780 id,781 ).await;782783 let time = sp_timestamp::InherentDataProvider::from_system_time();784785 let slot =786 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(787 *time,788 slot_duration,789 );790791 let parachain_inherent = parachain_inherent.ok_or_else(|| {792 Box::<dyn std::error::Error + Send + Sync>::from(793 "Failed to create parachain inherent",794 )795 })?;796 Ok((slot, time, parachain_inherent))797 }798 },799 block_import,800 para_client: client,801 backoff_authoring_blocks: Option::<()>::None,802 sync_oracle,803 keystore,804 force_authoring,805 slot_duration,806 // We got around 500ms for proposing807 block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),808 telemetry,809 max_block_proposal_slot_portion: None,810 }))811 },812 hwbench,813 )814 .await815}816817fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(818 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,819 _: Arc<FullBackend>,820 config: &Configuration,821 _: Option<TelemetryHandle>,822 task_manager: &TaskManager,823) -> Result<824 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,825 sc_service::Error,826>827where828 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>829 + Send830 + Sync831 + 'static,832 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>833 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,834 ExecutorDispatch: NativeExecutionDispatch + 'static,835{836 Ok(sc_consensus_manual_seal::import_queue(837 Box::new(client.clone()),838 &task_manager.spawn_essential_handle(),839 config.prometheus_registry(),840 ))841}842843/// Builds a new development service. This service uses instant seal, and mocks844/// the parachain inherent845pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(846 config: Configuration,847 autoseal_interval: Duration,848) -> sc_service::error::Result<TaskManager>849where850 Runtime: RuntimeInstance + Send + Sync + 'static,851 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,852 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,853 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>854 + Send855 + Sync856 + 'static,857 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>858 + fp_rpc::EthereumRuntimeRPCApi<Block>859 + fp_rpc::ConvertTransactionRuntimeApi<Block>860 + sp_session::SessionKeys<Block>861 + sp_block_builder::BlockBuilder<Block>862 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>863 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>864 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>865 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>866 + up_pov_estimate_rpc::PovEstimateApi<Block>867 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>868 + sp_api::Metadata<Block>869 + sp_offchain::OffchainWorkerApi<Block>870 + cumulus_primitives_core::CollectCollationInfo<Block>871 + sp_consensus_aura::AuraApi<Block, AuraId>,872 ExecutorDispatch: NativeExecutionDispatch + 'static,873{874 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};875 use fc_consensus::FrontierBlockImport;876 use sc_client_api::HeaderBackend;877878 let sc_service::PartialComponents {879 client,880 backend,881 mut task_manager,882 import_queue,883 keystore_container,884 select_chain: maybe_select_chain,885 transaction_pool,886 other:887 (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),888 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(889 &config,890 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,891 )?;892 let prometheus_registry = config.prometheus_registry().cloned();893894 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(895 task_manager.spawn_handle(),896 overrides_handle::<_, _, Runtime>(client.clone()),897 50,898 50,899 prometheus_registry.clone(),900 ));901902 let (network, system_rpc_tx, tx_handler_controller, network_starter) =903 sc_service::build_network(sc_service::BuildNetworkParams {904 config: &config,905 client: client.clone(),906 transaction_pool: transaction_pool.clone(),907 spawn_handle: task_manager.spawn_handle(),908 import_queue,909 block_announce_validator_builder: None,910 warp_sync_params: None,911 })?;912913 if config.offchain_worker.enabled {914 sc_service::build_offchain_workers(915 &config,916 task_manager.spawn_handle(),917 client.clone(),918 network.clone(),919 );920 }921922 let collator = config.role.is_authority();923924 let select_chain = maybe_select_chain.clone();925926 if collator {927 let block_import =928 FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());929930 let env = sc_basic_authorship::ProposerFactory::new(931 task_manager.spawn_handle(),932 client.clone(),933 transaction_pool.clone(),934 prometheus_registry.as_ref(),935 telemetry.as_ref().map(|x| x.handle()),936 );937938 let transactions_commands_stream: Box<939 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,940 > = Box::new(941 transaction_pool942 .pool()943 .validated_pool()944 .import_notification_stream()945 .map(|_| EngineCommand::SealNewBlock {946 create_empty: true,947 finalize: false, // todo:collator finalize true948 parent_hash: None,949 sender: None,950 }),951 );952953 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));954 let idle_commands_stream: Box<955 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,956 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {957 create_empty: true,958 finalize: false, // todo:collator finalize true959 parent_hash: None,960 sender: None,961 }));962963 let commands_stream = select(transactions_commands_stream, idle_commands_stream);964965 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;966 let client_set_aside_for_cidp = client.clone();967968 task_manager.spawn_essential_handle().spawn_blocking(969 "authorship_task",970 Some("block-authoring"),971 run_manual_seal(ManualSealParams {972 block_import,973 env,974 client: client.clone(),975 pool: transaction_pool.clone(),976 commands_stream,977 select_chain: select_chain.clone(),978 consensus_data_provider: None,979 create_inherent_data_providers: move |block: Hash, ()| {980 let current_para_block = client_set_aside_for_cidp981 .number(block)982 .expect("Header lookup should succeed")983 .expect("Header passed in as parent should be present in backend.");984985 let client_for_xcm = client_set_aside_for_cidp.clone();986 async move {987 let time = sp_timestamp::InherentDataProvider::from_system_time();988989 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {990 current_para_block,991 relay_offset: 1000,992 relay_blocks_per_para_block: 2,993 para_blocks_per_relay_epoch: 0,994 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(995 &*client_for_xcm,996 block,997 Default::default(),998 Default::default(),999 ),1000 relay_randomness_config: (),1001 raw_downward_messages: vec![],1002 raw_horizontal_messages: vec![],1003 };10041005 let slot =1006 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(1007 *time,1008 slot_duration,1009 );10101011 Ok((time, slot, mocked_parachain))1012 }1013 },1014 }),1015 );1016 }10171018 task_manager.spawn_essential_handle().spawn(1019 "frontier-mapping-sync-worker",1020 Some("block-authoring"),1021 MappingSyncWorker::new(1022 client.import_notification_stream(),1023 Duration::new(6, 0),1024 client.clone(),1025 backend.clone(),1026 overrides_handle::<_, _, Runtime>(client.clone()),1027 frontier_backend.clone(),1028 3,1029 0,1030 SyncStrategy::Normal,1031 )1032 .for_each(|()| futures::future::ready(())),1033 );10341035 let rpc_client = client.clone();1036 let rpc_pool = transaction_pool.clone();1037 let rpc_network = network.clone();1038 let rpc_frontier_backend = frontier_backend.clone();10391040 #[cfg(feature = "pov-estimate")]1041 let rpc_backend = backend.clone();10421043 #[cfg(feature = "pov-estimate")]1044 let runtime_id = config.chain_spec.runtime_id();10451046 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1047 let full_deps = unique_rpc::FullDeps {1048 #[cfg(feature = "pov-estimate")]1049 runtime_id: runtime_id.clone(),10501051 #[cfg(feature = "pov-estimate")]1052 exec_params: uc_rpc::pov_estimate::ExecutorParams {1053 wasm_method: config.wasm_method,1054 default_heap_pages: config.default_heap_pages,1055 max_runtime_instances: config.max_runtime_instances,1056 runtime_cache_size: config.runtime_cache_size,1057 },10581059 #[cfg(feature = "pov-estimate")]1060 backend: rpc_backend.clone(),1061 eth_backend: rpc_frontier_backend.clone(),1062 deny_unsafe,1063 client: rpc_client.clone(),1064 pool: rpc_pool.clone(),1065 graph: rpc_pool.pool().clone(),1066 // TODO: Unhardcode1067 enable_dev_signer: false,1068 filter_pool: filter_pool.clone(),1069 network: rpc_network.clone(),1070 select_chain: select_chain.clone(),1071 is_authority: collator,1072 // TODO: Unhardcode1073 max_past_logs: 10000,1074 block_data_cache: block_data_cache.clone(),1075 fee_history_cache: fee_history_cache.clone(),1076 // TODO: Unhardcode1077 fee_history_limit: 2048,1078 };10791080 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1081 full_deps,1082 subscription_executor,1083 )1084 .map_err(Into::into)1085 });10861087 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1088 network,1089 client,1090 keystore: keystore_container.sync_keystore(),1091 task_manager: &mut task_manager,1092 transaction_pool,1093 rpc_builder,1094 backend,1095 system_rpc_tx,1096 config,1097 telemetry: None,1098 tx_handler_controller,1099 })?;11001101 network_starter.start_network();1102 Ok(task_manager)1103}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// std18use std::sync::Arc;19use std::sync::Mutex;20use std::collections::BTreeMap;21use std::time::Duration;22use std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25 Stream, StreamExt,26 stream::select,27 task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38 ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41 prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;61use sc_consensus::ImportQueue;6263use polkadot_service::CollatorPair;6465// Frontier Imports66use fc_rpc_core::types::FilterPool;67use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6869use up_common::types::opaque::*;7071use crate::chain_spec::RuntimeIdentification;7273/// Unique native executor instance.74#[cfg(feature = "unique-runtime")]75pub struct UniqueRuntimeExecutor;7677#[cfg(feature = "quartz-runtime")]78/// Quartz native executor instance.79pub struct QuartzRuntimeExecutor;8081/// Opal native executor instance.82pub struct OpalRuntimeExecutor;8384#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]85pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;8687#[cfg(all(88 not(feature = "unique-runtime"),89 feature = "quartz-runtime",90 feature = "runtime-benchmarks"91))]92pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9394#[cfg(all(95 not(feature = "unique-runtime"),96 not(feature = "quartz-runtime"),97 feature = "runtime-benchmarks"98))]99pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;100101#[cfg(feature = "unique-runtime")]102impl NativeExecutionDispatch for UniqueRuntimeExecutor {103 /// Only enable the benchmarking host functions when we actually want to benchmark.104 #[cfg(feature = "runtime-benchmarks")]105 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;106 /// Otherwise we only use the default Substrate host functions.107 #[cfg(not(feature = "runtime-benchmarks"))]108 type ExtendHostFunctions = ();109110 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {111 unique_runtime::api::dispatch(method, data)112 }113114 fn native_version() -> sc_executor::NativeVersion {115 unique_runtime::native_version()116 }117}118119#[cfg(feature = "quartz-runtime")]120impl NativeExecutionDispatch for QuartzRuntimeExecutor {121 /// Only enable the benchmarking host functions when we actually want to benchmark.122 #[cfg(feature = "runtime-benchmarks")]123 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;124 /// Otherwise we only use the default Substrate host functions.125 #[cfg(not(feature = "runtime-benchmarks"))]126 type ExtendHostFunctions = ();127128 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {129 quartz_runtime::api::dispatch(method, data)130 }131132 fn native_version() -> sc_executor::NativeVersion {133 quartz_runtime::native_version()134 }135}136137impl NativeExecutionDispatch for OpalRuntimeExecutor {138 /// Only enable the benchmarking host functions when we actually want to benchmark.139 #[cfg(feature = "runtime-benchmarks")]140 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;141 /// Otherwise we only use the default Substrate host functions.142 #[cfg(not(feature = "runtime-benchmarks"))]143 type ExtendHostFunctions = ();144145 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {146 opal_runtime::api::dispatch(method, data)147 }148149 fn native_version() -> sc_executor::NativeVersion {150 opal_runtime::native_version()151 }152}153154pub struct AutosealInterval {155 interval: Interval,156}157158impl AutosealInterval {159 pub fn new(config: &Configuration, interval: Duration) -> Self {160 let _tokio_runtime = config.tokio_handle.enter();161 let interval = tokio::time::interval(interval);162163 Self { interval }164 }165}166167impl Stream for AutosealInterval {168 type Item = tokio::time::Instant;169170 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {171 self.interval.poll_tick(cx).map(Some)172 }173}174175pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(176 client: Arc<C>,177 config: &Configuration,178) -> Result<Arc<fc_db::Backend<Block>>, String> {179 let config_dir = config180 .base_path181 .as_ref()182 .map(|base_path| base_path.config_dir(config.chain_spec.id()))183 .unwrap_or_else(|| {184 BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())185 });186 let database_dir = config_dir.join("frontier").join("db");187188 Ok(Arc::new(fc_db::Backend::<Block>::new(189 client,190 &fc_db::DatabaseSettings {191 source: fc_db::DatabaseSource::RocksDb {192 path: database_dir,193 cache_size: 0,194 },195 },196 )?))197}198199type FullClient<RuntimeApi, ExecutorDispatch> =200 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;201type FullBackend = sc_service::TFullBackend<Block>;202type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;203type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =204 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;205206/// Starts a `ServiceBuilder` for a full service.207///208/// Use this macro if you don't actually need the full service, but just the builder in order to209/// be able to perform chain operations.210#[allow(clippy::type_complexity)]211pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(212 config: &Configuration,213 build_import_queue: BIQ,214) -> Result<215 PartialComponents<216 FullClient<RuntimeApi, ExecutorDispatch>,217 FullBackend,218 FullSelectChain,219 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,220 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,221 (222 Option<Telemetry>,223 Option<FilterPool>,224 Arc<fc_db::Backend<Block>>,225 Option<TelemetryWorkerHandle>,226 FeeHistoryCache,227 ),228 >,229 sc_service::Error,230>231where232 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,233 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>234 + Send235 + Sync236 + 'static,237 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,238 ExecutorDispatch: NativeExecutionDispatch + 'static,239 BIQ: FnOnce(240 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,241 Arc<FullBackend>,242 &Configuration,243 Option<TelemetryHandle>,244 &TaskManager,245 ) -> Result<246 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,247 sc_service::Error,248 >,249{250 let _telemetry = config251 .telemetry_endpoints252 .clone()253 .filter(|x| !x.is_empty())254 .map(|endpoints| -> Result<_, sc_telemetry::Error> {255 let worker = TelemetryWorker::new(16)?;256 let telemetry = worker.handle().new_telemetry(endpoints);257 Ok((worker, telemetry))258 })259 .transpose()?;260261 let telemetry = config262 .telemetry_endpoints263 .clone()264 .filter(|x| !x.is_empty())265 .map(|endpoints| -> Result<_, sc_telemetry::Error> {266 let worker = TelemetryWorker::new(16)?;267 let telemetry = worker.handle().new_telemetry(endpoints);268 Ok((worker, telemetry))269 })270 .transpose()?;271272 let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(273 config.wasm_method,274 config.default_heap_pages,275 config.max_runtime_instances,276 config.runtime_cache_size,277 );278279 let (client, backend, keystore_container, task_manager) =280 sc_service::new_full_parts::<Block, RuntimeApi, _>(281 config,282 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),283 executor,284 )?;285 let client = Arc::new(client);286287 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());288289 let telemetry = telemetry.map(|(worker, telemetry)| {290 task_manager291 .spawn_handle()292 .spawn("telemetry", None, worker.run());293 telemetry294 });295296 let select_chain = sc_consensus::LongestChain::new(backend.clone());297298 let transaction_pool = sc_transaction_pool::BasicPool::new_full(299 config.transaction_pool.clone(),300 config.role.is_authority().into(),301 config.prometheus_registry(),302 task_manager.spawn_essential_handle(),303 client.clone(),304 );305306 let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));307308 let frontier_backend = open_frontier_backend(client.clone(), config)?;309310 let import_queue = build_import_queue(311 client.clone(),312 backend.clone(),313 config,314 telemetry.as_ref().map(|telemetry| telemetry.handle()),315 &task_manager,316 )?;317 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));318319 let params = PartialComponents {320 backend,321 client,322 import_queue,323 keystore_container,324 task_manager,325 transaction_pool,326 select_chain,327 other: (328 telemetry,329 filter_pool,330 frontier_backend,331 telemetry_worker_handle,332 fee_history_cache,333 ),334 };335336 Ok(params)337}338339async fn build_relay_chain_interface(340 polkadot_config: Configuration,341 parachain_config: &Configuration,342 telemetry_worker_handle: Option<TelemetryWorkerHandle>,343 task_manager: &mut TaskManager,344 collator_options: CollatorOptions,345 hwbench: Option<sc_sysinfo::HwBench>,346) -> RelayChainResult<(347 Arc<(dyn RelayChainInterface + 'static)>,348 Option<CollatorPair>,349)> {350 if collator_options.relay_chain_rpc_urls.is_empty() {351 build_inprocess_relay_chain(352 polkadot_config,353 parachain_config,354 telemetry_worker_handle,355 task_manager,356 hwbench,357 )358 } else {359 build_minimal_relay_chain_node(360 polkadot_config,361 task_manager,362 collator_options.relay_chain_rpc_urls,363 )364 .await365 }366}367368/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.369///370/// This is the actual implementation that is abstract over the executor and the runtime api.371#[sc_tracing::logging::prefix_logs_with("Parachain")]372async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(373 parachain_config: Configuration,374 polkadot_config: Configuration,375 collator_options: CollatorOptions,376 id: ParaId,377 build_import_queue: BIQ,378 build_consensus: BIC,379 hwbench: Option<sc_sysinfo::HwBench>,380) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>381where382 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,383 Runtime: RuntimeInstance + Send + Sync + 'static,384 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,385 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,386 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>387 + Send388 + Sync389 + 'static,390 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>391 + fp_rpc::EthereumRuntimeRPCApi<Block>392 + fp_rpc::ConvertTransactionRuntimeApi<Block>393 + sp_session::SessionKeys<Block>394 + sp_block_builder::BlockBuilder<Block>395 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>396 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>397 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>398 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>399 + up_pov_estimate_rpc::PovEstimateApi<Block>400 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>401 + sp_api::Metadata<Block>402 + sp_offchain::OffchainWorkerApi<Block>403 + cumulus_primitives_core::CollectCollationInfo<Block>,404 ExecutorDispatch: NativeExecutionDispatch + 'static,405 BIQ: FnOnce(406 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,407 Arc<FullBackend>,408 &Configuration,409 Option<TelemetryHandle>,410 &TaskManager,411 ) -> Result<412 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,413 sc_service::Error,414 >,415 BIC: FnOnce(416 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,417 Arc<FullBackend>,418 Option<&Registry>,419 Option<TelemetryHandle>,420 &TaskManager,421 Arc<dyn RelayChainInterface>,422 Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,423 Arc<NetworkService<Block, Hash>>,424 SyncCryptoStorePtr,425 bool,426 ) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,427{428 let parachain_config = prepare_node_config(parachain_config);429430 let params =431 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;432 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =433 params.other;434435 let client = params.client.clone();436 let backend = params.backend.clone();437 let mut task_manager = params.task_manager;438439 let (relay_chain_interface, collator_key) = build_relay_chain_interface(440 polkadot_config,441 ¶chain_config,442 telemetry_worker_handle,443 &mut task_manager,444 collator_options.clone(),445 hwbench.clone(),446 )447 .await448 .map_err(|e| match e {449 RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,450 s => s.to_string().into(),451 })?;452453 let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);454455 let force_authoring = parachain_config.force_authoring;456 let validator = parachain_config.role.is_authority();457 let prometheus_registry = parachain_config.prometheus_registry().cloned();458 let transaction_pool = params.transaction_pool.clone();459 let import_queue_service = params.import_queue.service();460461 let (network, system_rpc_tx, tx_handler_controller, start_network) =462 sc_service::build_network(sc_service::BuildNetworkParams {463 config: ¶chain_config,464 client: client.clone(),465 transaction_pool: transaction_pool.clone(),466 spawn_handle: task_manager.spawn_handle(),467 import_queue: params.import_queue,468 block_announce_validator_builder: Some(Box::new(|_| {469 Box::new(block_announce_validator)470 })),471 warp_sync_params: None,472 })?;473474 let rpc_client = client.clone();475 let rpc_pool = transaction_pool.clone();476 let select_chain = params.select_chain.clone();477 let rpc_network = network.clone();478479 let rpc_frontier_backend = frontier_backend.clone();480481 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(482 task_manager.spawn_handle(),483 overrides_handle::<_, _, Runtime>(client.clone()),484 50,485 50,486 prometheus_registry.clone(),487 ));488489 task_manager.spawn_essential_handle().spawn(490 "frontier-mapping-sync-worker",491 None,492 MappingSyncWorker::new(493 client.import_notification_stream(),494 Duration::new(6, 0),495 client.clone(),496 backend.clone(),497 overrides_handle::<_, _, Runtime>(client.clone()),498 frontier_backend.clone(),499 3,500 0,501 SyncStrategy::Normal,502 )503 .for_each(|()| futures::future::ready(())),504 );505506 #[cfg(feature = "pov-estimate")]507 let rpc_backend = backend.clone();508509 let runtime_id = parachain_config.chain_spec.runtime_id();510511 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {512 let full_deps = unique_rpc::FullDeps {513 runtime_id: runtime_id.clone(),514515 #[cfg(feature = "pov-estimate")]516 exec_params: uc_rpc::pov_estimate::ExecutorParams {517 wasm_method: parachain_config.wasm_method,518 default_heap_pages: parachain_config.default_heap_pages,519 max_runtime_instances: parachain_config.max_runtime_instances,520 runtime_cache_size: parachain_config.runtime_cache_size,521 },522523 #[cfg(feature = "pov-estimate")]524 backend: rpc_backend.clone(),525526 eth_backend: rpc_frontier_backend.clone(),527 deny_unsafe,528 client: rpc_client.clone(),529 pool: rpc_pool.clone(),530 graph: rpc_pool.pool().clone(),531 // TODO: Unhardcode532 enable_dev_signer: false,533 filter_pool: filter_pool.clone(),534 network: rpc_network.clone(),535 select_chain: select_chain.clone(),536 is_authority: validator,537 // TODO: Unhardcode538 max_past_logs: 10000,539 block_data_cache: block_data_cache.clone(),540 fee_history_cache: fee_history_cache.clone(),541 // TODO: Unhardcode542 fee_history_limit: 2048,543 };544545 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(546 full_deps,547 subscription_task_executor,548 )549 .map_err(Into::into)550 });551552 sc_service::spawn_tasks(sc_service::SpawnTasksParams {553 rpc_builder,554 client: client.clone(),555 transaction_pool: transaction_pool.clone(),556 task_manager: &mut task_manager,557 config: parachain_config,558 keystore: params.keystore_container.sync_keystore(),559 backend: backend.clone(),560 network: network.clone(),561 system_rpc_tx,562 telemetry: telemetry.as_mut(),563 tx_handler_controller,564 })?;565566 if let Some(hwbench) = hwbench {567 sc_sysinfo::print_hwbench(&hwbench);568569 if let Some(ref mut telemetry) = telemetry {570 let telemetry_handle = telemetry.handle();571 task_manager.spawn_handle().spawn(572 "telemetry_hwbench",573 None,574 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),575 );576 }577 }578579 let announce_block = {580 let network = network.clone();581 Arc::new(Box::new(move |hash, data| {582 network.announce_block(hash, data)583 }))584 };585586 let relay_chain_slot_duration = Duration::from_secs(6);587588 let overseer_handle = relay_chain_interface589 .overseer_handle()590 .map_err(|e| sc_service::Error::Application(Box::new(e)))?;591592 if validator {593 let parachain_consensus = build_consensus(594 client.clone(),595 backend.clone(),596 prometheus_registry.as_ref(),597 telemetry.as_ref().map(|t| t.handle()),598 &task_manager,599 relay_chain_interface.clone(),600 transaction_pool,601 network,602 params.keystore_container.sync_keystore(),603 force_authoring,604 )?;605606 let spawner = task_manager.spawn_handle();607608 let params = StartCollatorParams {609 para_id: id,610 block_status: client.clone(),611 announce_block,612 client: client.clone(),613 task_manager: &mut task_manager,614 spawner,615 parachain_consensus,616 import_queue: import_queue_service,617 collator_key: collator_key.expect("Command line arguments do not allow this. qed"),618 relay_chain_interface,619 relay_chain_slot_duration,620 recovery_handle: Box::new(overseer_handle),621 };622623 start_collator(params).await?;624 } else {625 let params = StartFullNodeParams {626 client: client.clone(),627 announce_block,628 task_manager: &mut task_manager,629 para_id: id,630 import_queue: import_queue_service,631 relay_chain_interface,632 relay_chain_slot_duration,633 recovery_handle: Box::new(overseer_handle),634 };635636 start_full_node(params)?;637 }638639 start_network.start_network();640641 Ok((task_manager, client))642}643644/// Build the import queue for the the parachain runtime.645pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(646 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,647 backend: Arc<FullBackend>,648 config: &Configuration,649 telemetry: Option<TelemetryHandle>,650 task_manager: &TaskManager,651) -> Result<652 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,653 sc_service::Error,654>655where656 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>657 + Send658 + Sync659 + 'static,660 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>661 + sp_block_builder::BlockBuilder<Block>662 + sp_consensus_aura::AuraApi<Block, AuraId>663 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,664 ExecutorDispatch: NativeExecutionDispatch + 'static,665{666 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;667668 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());669670 cumulus_client_consensus_aura::import_queue::<671 sp_consensus_aura::sr25519::AuthorityPair,672 _,673 _,674 _,675 _,676 _,677 >(cumulus_client_consensus_aura::ImportQueueParams {678 block_import,679 client: client.clone(),680 create_inherent_data_providers: move |_, _| async move {681 let time = sp_timestamp::InherentDataProvider::from_system_time();682683 let slot =684 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(685 *time,686 slot_duration,687 );688689 Ok((slot, time))690 },691 registry: config.prometheus_registry(),692 spawner: &task_manager.spawn_essential_handle(),693 telemetry,694 })695 .map_err(Into::into)696}697698/// Start a normal parachain node.699pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(700 parachain_config: Configuration,701 polkadot_config: Configuration,702 collator_options: CollatorOptions,703 id: ParaId,704 hwbench: Option<sc_sysinfo::HwBench>,705) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>706where707 Runtime: RuntimeInstance + Send + Sync + 'static,708 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,709 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,710 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>711 + Send712 + Sync713 + 'static,714 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>715 + fp_rpc::EthereumRuntimeRPCApi<Block>716 + fp_rpc::ConvertTransactionRuntimeApi<Block>717 + sp_session::SessionKeys<Block>718 + sp_block_builder::BlockBuilder<Block>719 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>720 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>721 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>722 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>723 + up_pov_estimate_rpc::PovEstimateApi<Block>724 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>725 + sp_api::Metadata<Block>726 + sp_offchain::OffchainWorkerApi<Block>727 + cumulus_primitives_core::CollectCollationInfo<Block>728 + sp_consensus_aura::AuraApi<Block, AuraId>,729 ExecutorDispatch: NativeExecutionDispatch + 'static,730{731 start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(732 parachain_config,733 polkadot_config,734 collator_options,735 id,736 parachain_build_import_queue,737 |client,738 backend,739 prometheus_registry,740 telemetry,741 task_manager,742 relay_chain_interface,743 transaction_pool,744 sync_oracle,745 keystore,746 force_authoring| {747 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;748749 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(750 task_manager.spawn_handle(),751 client.clone(),752 transaction_pool,753 prometheus_registry,754 telemetry.clone(),755 );756757 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());758759 Ok(AuraConsensus::build::<760 sp_consensus_aura::sr25519::AuthorityPair,761 _,762 _,763 _,764 _,765 _,766 _,767 >(BuildAuraConsensusParams {768 proposer_factory,769 create_inherent_data_providers: move |_, (relay_parent, validation_data)| {770 let relay_chain_interface = relay_chain_interface.clone();771 async move {772 let parachain_inherent =773 cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(774 relay_parent,775 &relay_chain_interface,776 &validation_data,777 id,778 ).await;779780 let time = sp_timestamp::InherentDataProvider::from_system_time();781782 let slot =783 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(784 *time,785 slot_duration,786 );787788 let parachain_inherent = parachain_inherent.ok_or_else(|| {789 Box::<dyn std::error::Error + Send + Sync>::from(790 "Failed to create parachain inherent",791 )792 })?;793 Ok((slot, time, parachain_inherent))794 }795 },796 block_import,797 para_client: client,798 backoff_authoring_blocks: Option::<()>::None,799 sync_oracle,800 keystore,801 force_authoring,802 slot_duration,803 // We got around 500ms for proposing804 block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),805 telemetry,806 max_block_proposal_slot_portion: None,807 }))808 },809 hwbench,810 )811 .await812}813814fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(815 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,816 _: Arc<FullBackend>,817 config: &Configuration,818 _: Option<TelemetryHandle>,819 task_manager: &TaskManager,820) -> Result<821 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,822 sc_service::Error,823>824where825 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>826 + Send827 + Sync828 + 'static,829 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>830 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,831 ExecutorDispatch: NativeExecutionDispatch + 'static,832{833 Ok(sc_consensus_manual_seal::import_queue(834 Box::new(client.clone()),835 &task_manager.spawn_essential_handle(),836 config.prometheus_registry(),837 ))838}839840/// Builds a new development service. This service uses instant seal, and mocks841/// the parachain inherent842pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(843 config: Configuration,844 autoseal_interval: Duration,845) -> sc_service::error::Result<TaskManager>846where847 Runtime: RuntimeInstance + Send + Sync + 'static,848 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,849 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,850 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>851 + Send852 + Sync853 + 'static,854 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>855 + fp_rpc::EthereumRuntimeRPCApi<Block>856 + fp_rpc::ConvertTransactionRuntimeApi<Block>857 + sp_session::SessionKeys<Block>858 + sp_block_builder::BlockBuilder<Block>859 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>860 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>861 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>862 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>863 + up_pov_estimate_rpc::PovEstimateApi<Block>864 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>865 + sp_api::Metadata<Block>866 + sp_offchain::OffchainWorkerApi<Block>867 + cumulus_primitives_core::CollectCollationInfo<Block>868 + sp_consensus_aura::AuraApi<Block, AuraId>,869 ExecutorDispatch: NativeExecutionDispatch + 'static,870{871 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};872 use fc_consensus::FrontierBlockImport;873 use sc_client_api::HeaderBackend;874875 let sc_service::PartialComponents {876 client,877 backend,878 mut task_manager,879 import_queue,880 keystore_container,881 select_chain: maybe_select_chain,882 transaction_pool,883 other:884 (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),885 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(886 &config,887 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,888 )?;889 let prometheus_registry = config.prometheus_registry().cloned();890891 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(892 task_manager.spawn_handle(),893 overrides_handle::<_, _, Runtime>(client.clone()),894 50,895 50,896 prometheus_registry.clone(),897 ));898899 let (network, system_rpc_tx, tx_handler_controller, network_starter) =900 sc_service::build_network(sc_service::BuildNetworkParams {901 config: &config,902 client: client.clone(),903 transaction_pool: transaction_pool.clone(),904 spawn_handle: task_manager.spawn_handle(),905 import_queue,906 block_announce_validator_builder: None,907 warp_sync_params: None,908 })?;909910 if config.offchain_worker.enabled {911 sc_service::build_offchain_workers(912 &config,913 task_manager.spawn_handle(),914 client.clone(),915 network.clone(),916 );917 }918919 let collator = config.role.is_authority();920921 let select_chain = maybe_select_chain.clone();922923 if collator {924 let block_import =925 FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());926927 let env = sc_basic_authorship::ProposerFactory::new(928 task_manager.spawn_handle(),929 client.clone(),930 transaction_pool.clone(),931 prometheus_registry.as_ref(),932 telemetry.as_ref().map(|x| x.handle()),933 );934935 let transactions_commands_stream: Box<936 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,937 > = Box::new(938 transaction_pool939 .pool()940 .validated_pool()941 .import_notification_stream()942 .map(|_| EngineCommand::SealNewBlock {943 create_empty: true,944 finalize: false, // todo:collator finalize true945 parent_hash: None,946 sender: None,947 }),948 );949950 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));951 let idle_commands_stream: Box<952 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,953 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {954 create_empty: true,955 finalize: false, // todo:collator finalize true956 parent_hash: None,957 sender: None,958 }));959960 let commands_stream = select(transactions_commands_stream, idle_commands_stream);961962 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;963 let client_set_aside_for_cidp = client.clone();964965 task_manager.spawn_essential_handle().spawn_blocking(966 "authorship_task",967 Some("block-authoring"),968 run_manual_seal(ManualSealParams {969 block_import,970 env,971 client: client.clone(),972 pool: transaction_pool.clone(),973 commands_stream,974 select_chain: select_chain.clone(),975 consensus_data_provider: None,976 create_inherent_data_providers: move |block: Hash, ()| {977 let current_para_block = client_set_aside_for_cidp978 .number(block)979 .expect("Header lookup should succeed")980 .expect("Header passed in as parent should be present in backend.");981982 let client_for_xcm = client_set_aside_for_cidp.clone();983 async move {984 let time = sp_timestamp::InherentDataProvider::from_system_time();985986 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {987 current_para_block,988 relay_offset: 1000,989 relay_blocks_per_para_block: 2,990 para_blocks_per_relay_epoch: 0,991 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(992 &*client_for_xcm,993 block,994 Default::default(),995 Default::default(),996 ),997 relay_randomness_config: (),998 raw_downward_messages: vec![],999 raw_horizontal_messages: vec![],1000 };10011002 let slot =1003 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(1004 *time,1005 slot_duration,1006 );10071008 Ok((time, slot, mocked_parachain))1009 }1010 },1011 }),1012 );1013 }10141015 task_manager.spawn_essential_handle().spawn(1016 "frontier-mapping-sync-worker",1017 Some("block-authoring"),1018 MappingSyncWorker::new(1019 client.import_notification_stream(),1020 Duration::new(6, 0),1021 client.clone(),1022 backend.clone(),1023 overrides_handle::<_, _, Runtime>(client.clone()),1024 frontier_backend.clone(),1025 3,1026 0,1027 SyncStrategy::Normal,1028 )1029 .for_each(|()| futures::future::ready(())),1030 );10311032 let rpc_client = client.clone();1033 let rpc_pool = transaction_pool.clone();1034 let rpc_network = network.clone();1035 let rpc_frontier_backend = frontier_backend.clone();10361037 #[cfg(feature = "pov-estimate")]1038 let rpc_backend = backend.clone();10391040 let runtime_id = config.chain_spec.runtime_id();10411042 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1043 let full_deps = unique_rpc::FullDeps {1044 runtime_id: runtime_id.clone(),10451046 #[cfg(feature = "pov-estimate")]1047 exec_params: uc_rpc::pov_estimate::ExecutorParams {1048 wasm_method: config.wasm_method,1049 default_heap_pages: config.default_heap_pages,1050 max_runtime_instances: config.max_runtime_instances,1051 runtime_cache_size: config.runtime_cache_size,1052 },10531054 #[cfg(feature = "pov-estimate")]1055 backend: rpc_backend.clone(),1056 eth_backend: rpc_frontier_backend.clone(),1057 deny_unsafe,1058 client: rpc_client.clone(),1059 pool: rpc_pool.clone(),1060 graph: rpc_pool.pool().clone(),1061 // TODO: Unhardcode1062 enable_dev_signer: false,1063 filter_pool: filter_pool.clone(),1064 network: rpc_network.clone(),1065 select_chain: select_chain.clone(),1066 is_authority: collator,1067 // TODO: Unhardcode1068 max_past_logs: 10000,1069 block_data_cache: block_data_cache.clone(),1070 fee_history_cache: fee_history_cache.clone(),1071 // TODO: Unhardcode1072 fee_history_limit: 2048,1073 };10741075 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1076 full_deps,1077 subscription_executor,1078 )1079 .map_err(Into::into)1080 });10811082 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1083 network,1084 client,1085 keystore: keystore_container.sync_keystore(),1086 task_manager: &mut task_manager,1087 transaction_pool,1088 rpc_builder,1089 backend,1090 system_rpc_tx,1091 config,1092 telemetry: None,1093 tx_handler_controller,1094 })?;10951096 network_starter.start_network();1097 Ok(task_manager)1098}node/rpc/Cargo.tomldiffbeforeafterboth--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -44,4 +44,3 @@
default = []
pov-estimate = ['uc-rpc/pov-estimate']
std = []
-unique-runtime = []
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -80,7 +80,7 @@
/// EthFilterApi pool.
pub filter_pool: Option<FilterPool>,
- #[cfg(feature = "pov-estimate")]
+ /// Runtime identification (read from the chain spec)
pub runtime_id: RuntimeId,
/// Executor params for PoV estimating
#[cfg(feature = "pov-estimate")]
@@ -194,8 +194,7 @@
deny_unsafe,
filter_pool,
- #[cfg(feature = "pov-estimate")]
- runtime_id,
+ runtime_id: _,
#[cfg(feature = "pov-estimate")]
exec_params,