git.delta.rocks / unique-network / refs/commits / 16474c6279e3

difftreelog

source

node/cli/src/service.rs30.3 KiBsourcehistory
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::ParachainConsensus;38use cumulus_client_service::{39	prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,40};41use cumulus_client_cli::CollatorOptions;42use cumulus_client_network::BlockAnnounceValidator;43use cumulus_primitives_core::ParaId;44use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;45use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};46use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;4748// Substrate Imports49use sc_client_api::ExecutorProvider;50use sc_executor::NativeElseWasmExecutor;51use sc_executor::NativeExecutionDispatch;52use sc_network::NetworkService;53use sc_service::{BasePath, Configuration, PartialComponents, Role, TaskManager};54use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};55use sp_keystore::SyncCryptoStorePtr;56use sp_runtime::traits::BlakeTwo256;57use substrate_prometheus_endpoint::Registry;58use sc_client_api::BlockchainEvents;5960use polkadot_service::CollatorPair;6162// Frontier Imports63use fc_rpc_core::types::FilterPool;64use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6566use unique_runtime_common::types::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};6768// RMRK69use up_data_structs::{70	RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,71	RmrkPartType, RmrkTheme,72};7374/// Unique native executor instance.75#[cfg(feature = "unique-runtime")]76pub struct UniqueRuntimeExecutor;7778#[cfg(feature = "quartz-runtime")]79/// Quartz native executor instance.8081pub struct QuartzRuntimeExecutor;8283/// Opal native executor instance.84pub struct OpalRuntimeExecutor;8586#[cfg(feature = "unique-runtime")]87impl NativeExecutionDispatch for UniqueRuntimeExecutor {88	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;8990	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {91		unique_runtime::api::dispatch(method, data)92	}9394	fn native_version() -> sc_executor::NativeVersion {95		unique_runtime::native_version()96	}97}9899#[cfg(feature = "quartz-runtime")]100impl NativeExecutionDispatch for QuartzRuntimeExecutor {101	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;102103	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {104		quartz_runtime::api::dispatch(method, data)105	}106107	fn native_version() -> sc_executor::NativeVersion {108		quartz_runtime::native_version()109	}110}111112impl NativeExecutionDispatch for OpalRuntimeExecutor {113	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;114115	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {116		opal_runtime::api::dispatch(method, data)117	}118119	fn native_version() -> sc_executor::NativeVersion {120		opal_runtime::native_version()121	}122}123124pub struct AutosealInterval {125	interval: Interval,126}127128impl AutosealInterval {129	pub fn new(config: &Configuration, interval: Duration) -> Self {130		let _tokio_runtime = config.tokio_handle.enter();131		let interval = tokio::time::interval(interval);132133		Self { interval }134	}135}136137impl Stream for AutosealInterval {138	type Item = tokio::time::Instant;139140	fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {141		self.interval.poll_tick(cx).map(Some)142	}143}144145pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {146	let config_dir = config147		.base_path148		.as_ref()149		.map(|base_path| base_path.config_dir(config.chain_spec.id()))150		.unwrap_or_else(|| {151			BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())152		});153	let database_dir = config_dir.join("frontier").join("db");154155	Ok(Arc::new(fc_db::Backend::<Block>::new(156		&fc_db::DatabaseSettings {157			source: fc_db::DatabaseSource::RocksDb {158				path: database_dir,159				cache_size: 0,160			},161		},162	)?))163}164165type FullClient<RuntimeApi, ExecutorDispatch> =166	sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;167type FullBackend = sc_service::TFullBackend<Block>;168type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;169170/// Starts a `ServiceBuilder` for a full service.171///172/// Use this macro if you don't actually need the full service, but just the builder in order to173/// be able to perform chain operations.174#[allow(clippy::type_complexity)]175pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(176	config: &Configuration,177	build_import_queue: BIQ,178) -> Result<179	PartialComponents<180		FullClient<RuntimeApi, ExecutorDispatch>,181		FullBackend,182		FullSelectChain,183		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,184		sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,185		(186			Option<Telemetry>,187			Option<FilterPool>,188			Arc<fc_db::Backend<Block>>,189			Option<TelemetryWorkerHandle>,190			FeeHistoryCache,191		),192	>,193	sc_service::Error,194>195where196	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,197	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>198		+ Send199		+ Sync200		+ 'static,201	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,202	ExecutorDispatch: NativeExecutionDispatch + 'static,203	BIQ: FnOnce(204		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,205		&Configuration,206		Option<TelemetryHandle>,207		&TaskManager,208	) -> Result<209		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,210		sc_service::Error,211	>,212{213	let _telemetry = config214		.telemetry_endpoints215		.clone()216		.filter(|x| !x.is_empty())217		.map(|endpoints| -> Result<_, sc_telemetry::Error> {218			let worker = TelemetryWorker::new(16)?;219			let telemetry = worker.handle().new_telemetry(endpoints);220			Ok((worker, telemetry))221		})222		.transpose()?;223224	let telemetry = config225		.telemetry_endpoints226		.clone()227		.filter(|x| !x.is_empty())228		.map(|endpoints| -> Result<_, sc_telemetry::Error> {229			let worker = TelemetryWorker::new(16)?;230			let telemetry = worker.handle().new_telemetry(endpoints);231			Ok((worker, telemetry))232		})233		.transpose()?;234235	let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(236		config.wasm_method,237		config.default_heap_pages,238		config.max_runtime_instances,239		config.runtime_cache_size,240	);241242	let (client, backend, keystore_container, task_manager) =243		sc_service::new_full_parts::<Block, RuntimeApi, _>(244			config,245			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),246			executor,247		)?;248	let client = Arc::new(client);249250	let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());251252	let telemetry = telemetry.map(|(worker, telemetry)| {253		task_manager254			.spawn_handle()255			.spawn("telemetry", None, worker.run());256		telemetry257	});258259	let select_chain = sc_consensus::LongestChain::new(backend.clone());260261	let transaction_pool = sc_transaction_pool::BasicPool::new_full(262		config.transaction_pool.clone(),263		config.role.is_authority().into(),264		config.prometheus_registry(),265		task_manager.spawn_essential_handle(),266		client.clone(),267	);268269	let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));270271	let frontier_backend = open_frontier_backend(config)?;272273	let import_queue = build_import_queue(274		client.clone(),275		config,276		telemetry.as_ref().map(|telemetry| telemetry.handle()),277		&task_manager,278	)?;279	let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));280281	let params = PartialComponents {282		backend,283		client,284		import_queue,285		keystore_container,286		task_manager,287		transaction_pool,288		select_chain,289		other: (290			telemetry,291			filter_pool,292			frontier_backend,293			telemetry_worker_handle,294			fee_history_cache,295		),296	};297298	Ok(params)299}300301async fn build_relay_chain_interface(302	polkadot_config: Configuration,303	parachain_config: &Configuration,304	telemetry_worker_handle: Option<TelemetryWorkerHandle>,305	task_manager: &mut TaskManager,306	collator_options: CollatorOptions,307	hwbench: Option<sc_sysinfo::HwBench>,308) -> RelayChainResult<(309	Arc<(dyn RelayChainInterface + 'static)>,310	Option<CollatorPair>,311)> {312	match collator_options.relay_chain_rpc_url {313		Some(relay_chain_url) => Ok((314			Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>,315			None,316		)),317		None => build_inprocess_relay_chain(318			polkadot_config,319			parachain_config,320			telemetry_worker_handle,321			task_manager,322			hwbench,323		),324	}325}326327/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.328///329/// This is the actual implementation that is abstract over the executor and the runtime api.330#[sc_tracing::logging::prefix_logs_with("Parachain")]331async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(332	parachain_config: Configuration,333	polkadot_config: Configuration,334	collator_options: CollatorOptions,335	id: ParaId,336	build_import_queue: BIQ,337	build_consensus: BIC,338	hwbench: Option<sc_sysinfo::HwBench>,339) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>340where341	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,342	Runtime: RuntimeInstance + Send + Sync + 'static,343	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,344	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,345	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>346		+ Send347		+ Sync348		+ 'static,349	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>350		+ fp_rpc::EthereumRuntimeRPCApi<Block>351		+ fp_rpc::ConvertTransactionRuntimeApi<Block>352		+ sp_session::SessionKeys<Block>353		+ sp_block_builder::BlockBuilder<Block>354		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>355		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>356		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>357		+ rmrk_rpc::RmrkApi<358			Block,359			AccountId,360			RmrkCollectionInfo<AccountId>,361			RmrkInstanceInfo<AccountId>,362			RmrkResourceInfo,363			RmrkPropertyInfo,364			RmrkBaseInfo<AccountId>,365			RmrkPartType,366			RmrkTheme,367		>368		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>369		+ sp_api::Metadata<Block>370		+ sp_offchain::OffchainWorkerApi<Block>371		+ cumulus_primitives_core::CollectCollationInfo<Block>,372	ExecutorDispatch: NativeExecutionDispatch + 'static,373	BIQ: FnOnce(374		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,375		&Configuration,376		Option<TelemetryHandle>,377		&TaskManager,378	) -> Result<379		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,380		sc_service::Error,381	>,382	BIC: FnOnce(383		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,384		Option<&Registry>,385		Option<TelemetryHandle>,386		&TaskManager,387		Arc<dyn RelayChainInterface>,388		Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,389		Arc<NetworkService<Block, Hash>>,390		SyncCryptoStorePtr,391		bool,392	) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,393{394	if matches!(parachain_config.role, Role::Light) {395		return Err("Light client not supported!".into());396	}397398	let parachain_config = prepare_node_config(parachain_config);399400	let params =401		new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;402	let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =403		params.other;404405	let client = params.client.clone();406	let backend = params.backend.clone();407	let mut task_manager = params.task_manager;408409	let (relay_chain_interface, collator_key) = build_relay_chain_interface(410		polkadot_config,411		&parachain_config,412		telemetry_worker_handle,413		&mut task_manager,414		collator_options.clone(),415		hwbench.clone(),416	)417	.await418	.map_err(|e| match e {419		RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,420		s => s.to_string().into(),421	})?;422423	let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);424425	let force_authoring = parachain_config.force_authoring;426	let validator = parachain_config.role.is_authority();427	let prometheus_registry = parachain_config.prometheus_registry().cloned();428	let transaction_pool = params.transaction_pool.clone();429	let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);430431	let (network, system_rpc_tx, start_network) =432		sc_service::build_network(sc_service::BuildNetworkParams {433			config: &parachain_config,434			client: client.clone(),435			transaction_pool: transaction_pool.clone(),436			spawn_handle: task_manager.spawn_handle(),437			import_queue: import_queue.clone(),438			block_announce_validator_builder: Some(Box::new(|_| {439				Box::new(block_announce_validator)440			})),441			warp_sync: None,442		})?;443444	let rpc_client = client.clone();445	let rpc_pool = transaction_pool.clone();446	let select_chain = params.select_chain.clone();447	let rpc_network = network.clone();448449	let rpc_frontier_backend = frontier_backend.clone();450451	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(452		task_manager.spawn_handle(),453		overrides_handle::<_, _, Runtime>(client.clone()),454		50,455		50,456		prometheus_registry.clone(),457	));458459	task_manager.spawn_essential_handle().spawn(460		"frontier-mapping-sync-worker",461		None,462		MappingSyncWorker::new(463			client.import_notification_stream(),464			Duration::new(6, 0),465			client.clone(),466			backend.clone(),467			frontier_backend.clone(),468			3,469			0,470			SyncStrategy::Normal,471		)472		.for_each(|()| futures::future::ready(())),473	);474475	let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {476		let full_deps = unique_rpc::FullDeps {477			backend: rpc_frontier_backend.clone(),478			deny_unsafe,479			client: rpc_client.clone(),480			pool: rpc_pool.clone(),481			graph: rpc_pool.pool().clone(),482			// TODO: Unhardcode483			enable_dev_signer: false,484			filter_pool: filter_pool.clone(),485			network: rpc_network.clone(),486			select_chain: select_chain.clone(),487			is_authority: validator,488			// TODO: Unhardcode489			max_past_logs: 10000,490			block_data_cache: block_data_cache.clone(),491			fee_history_cache: fee_history_cache.clone(),492			// TODO: Unhardcode493			fee_history_limit: 2048,494		};495496		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(497			full_deps,498			subscription_task_executor,499		)500		.map_err(Into::into)501	});502503	sc_service::spawn_tasks(sc_service::SpawnTasksParams {504		rpc_builder,505		client: client.clone(),506		transaction_pool: transaction_pool.clone(),507		task_manager: &mut task_manager,508		config: parachain_config,509		keystore: params.keystore_container.sync_keystore(),510		backend: backend.clone(),511		network: network.clone(),512		system_rpc_tx,513		telemetry: telemetry.as_mut(),514	})?;515516	if let Some(hwbench) = hwbench {517		sc_sysinfo::print_hwbench(&hwbench);518519		if let Some(ref mut telemetry) = telemetry {520			let telemetry_handle = telemetry.handle();521			task_manager.spawn_handle().spawn(522				"telemetry_hwbench",523				None,524				sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),525			);526		}527	}528529	let announce_block = {530		let network = network.clone();531		Arc::new(move |hash, data| network.announce_block(hash, data))532	};533534	let relay_chain_slot_duration = Duration::from_secs(6);535536	if validator {537		let parachain_consensus = build_consensus(538			client.clone(),539			prometheus_registry.as_ref(),540			telemetry.as_ref().map(|t| t.handle()),541			&task_manager,542			relay_chain_interface.clone(),543			transaction_pool,544			network,545			params.keystore_container.sync_keystore(),546			force_authoring,547		)?;548549		let spawner = task_manager.spawn_handle();550551		let params = StartCollatorParams {552			para_id: id,553			block_status: client.clone(),554			announce_block,555			client: client.clone(),556			task_manager: &mut task_manager,557			spawner,558			parachain_consensus,559			import_queue,560			collator_key: collator_key.expect("Command line arguments do not allow this. qed"),561			relay_chain_interface,562			relay_chain_slot_duration,563		};564565		start_collator(params).await?;566	} else {567		let params = StartFullNodeParams {568			client: client.clone(),569			announce_block,570			task_manager: &mut task_manager,571			para_id: id,572			import_queue,573			relay_chain_interface,574			relay_chain_slot_duration,575			collator_options,576		};577578		start_full_node(params)?;579	}580581	start_network.start_network();582583	Ok((task_manager, client))584}585586/// Build the import queue for the the parachain runtime.587pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(588	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,589	config: &Configuration,590	telemetry: Option<TelemetryHandle>,591	task_manager: &TaskManager,592) -> Result<593	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,594	sc_service::Error,595>596where597	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>598		+ Send599		+ Sync600		+ 'static,601	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>602		+ sp_block_builder::BlockBuilder<Block>603		+ sp_consensus_aura::AuraApi<Block, AuraId>604		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,605	ExecutorDispatch: NativeExecutionDispatch + 'static,606{607	let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;608609	cumulus_client_consensus_aura::import_queue::<610		sp_consensus_aura::sr25519::AuthorityPair,611		_,612		_,613		_,614		_,615		_,616		_,617	>(cumulus_client_consensus_aura::ImportQueueParams {618		block_import: client.clone(),619		client: client.clone(),620		create_inherent_data_providers: move |_, _| async move {621			let time = sp_timestamp::InherentDataProvider::from_system_time();622623			let slot =624				sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(625					*time,626					slot_duration,627				);628629			Ok((time, slot))630		},631		registry: config.prometheus_registry(),632		can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),633		spawner: &task_manager.spawn_essential_handle(),634		telemetry,635	})636	.map_err(Into::into)637}638639/// Start a normal parachain node.640pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(641	parachain_config: Configuration,642	polkadot_config: Configuration,643	collator_options: CollatorOptions,644	id: ParaId,645	hwbench: Option<sc_sysinfo::HwBench>,646) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>647where648	Runtime: RuntimeInstance + Send + Sync + 'static,649	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,650	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,651	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>652		+ Send653		+ Sync654		+ 'static,655	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>656		+ fp_rpc::EthereumRuntimeRPCApi<Block>657		+ fp_rpc::ConvertTransactionRuntimeApi<Block>658		+ sp_session::SessionKeys<Block>659		+ sp_block_builder::BlockBuilder<Block>660		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>661		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>662		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>663		+ rmrk_rpc::RmrkApi<664			Block,665			AccountId,666			RmrkCollectionInfo<AccountId>,667			RmrkInstanceInfo<AccountId>,668			RmrkResourceInfo,669			RmrkPropertyInfo,670			RmrkBaseInfo<AccountId>,671			RmrkPartType,672			RmrkTheme,673		>674		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>675		+ sp_api::Metadata<Block>676		+ sp_offchain::OffchainWorkerApi<Block>677		+ cumulus_primitives_core::CollectCollationInfo<Block>678		+ sp_consensus_aura::AuraApi<Block, AuraId>,679	ExecutorDispatch: NativeExecutionDispatch + 'static,680{681	start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(682		parachain_config,683		polkadot_config,684		collator_options,685		id,686		parachain_build_import_queue,687		|client,688		 prometheus_registry,689		 telemetry,690		 task_manager,691		 relay_chain_interface,692		 transaction_pool,693		 sync_oracle,694		 keystore,695		 force_authoring| {696			let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;697698			let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(699				task_manager.spawn_handle(),700				client.clone(),701				transaction_pool,702				prometheus_registry,703				telemetry.clone(),704			);705706			Ok(AuraConsensus::build::<707				sp_consensus_aura::sr25519::AuthorityPair,708				_,709				_,710				_,711				_,712				_,713				_,714			>(BuildAuraConsensusParams {715				proposer_factory,716				create_inherent_data_providers: move |_, (relay_parent, validation_data)| {717					let relay_chain_interface = relay_chain_interface.clone();718					async move {719						let parachain_inherent =720						cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(721							relay_parent,722							&relay_chain_interface,723							&validation_data,724							id,725						).await;726727						let time = sp_timestamp::InherentDataProvider::from_system_time();728729						let slot =730						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(731							*time,732							slot_duration,733						);734735						let parachain_inherent = parachain_inherent.ok_or_else(|| {736							Box::<dyn std::error::Error + Send + Sync>::from(737								"Failed to create parachain inherent",738							)739						})?;740						Ok((time, slot, parachain_inherent))741					}742				},743				block_import: client.clone(),744				para_client: client,745				backoff_authoring_blocks: Option::<()>::None,746				sync_oracle,747				keystore,748				force_authoring,749				slot_duration,750				// We got around 500ms for proposing751				block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),752				telemetry,753				max_block_proposal_slot_portion: None,754			}))755		},756		hwbench,757	)758	.await759}760761fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(762	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,763	config: &Configuration,764	_: Option<TelemetryHandle>,765	task_manager: &TaskManager,766) -> Result<767	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,768	sc_service::Error,769>770where771	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>772		+ Send773		+ Sync774		+ 'static,775	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>776		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,777	ExecutorDispatch: NativeExecutionDispatch + 'static,778{779	Ok(sc_consensus_manual_seal::import_queue(780		Box::new(client.clone()),781		&task_manager.spawn_essential_handle(),782		config.prometheus_registry(),783	))784}785786/// Builds a new development service. This service uses instant seal, and mocks787/// the parachain inherent788pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(789	config: Configuration,790	autoseal_interval: Duration,791) -> sc_service::error::Result<TaskManager>792where793	Runtime: RuntimeInstance + Send + Sync + 'static,794	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,795	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,796	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>797		+ Send798		+ Sync799		+ 'static,800	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>801		+ fp_rpc::EthereumRuntimeRPCApi<Block>802		+ fp_rpc::ConvertTransactionRuntimeApi<Block>803		+ sp_session::SessionKeys<Block>804		+ sp_block_builder::BlockBuilder<Block>805		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>806		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>807		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>808		+ rmrk_rpc::RmrkApi<809			Block,810			AccountId,811			RmrkCollectionInfo<AccountId>,812			RmrkInstanceInfo<AccountId>,813			RmrkResourceInfo,814			RmrkPropertyInfo,815			RmrkBaseInfo<AccountId>,816			RmrkPartType,817			RmrkTheme,818		>819		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>820		+ sp_api::Metadata<Block>821		+ sp_offchain::OffchainWorkerApi<Block>822		+ cumulus_primitives_core::CollectCollationInfo<Block>823		+ sp_consensus_aura::AuraApi<Block, AuraId>,824	ExecutorDispatch: NativeExecutionDispatch + 'static,825{826	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};827	use fc_consensus::FrontierBlockImport;828	use sc_client_api::HeaderBackend;829830	let sc_service::PartialComponents {831		client,832		backend,833		mut task_manager,834		import_queue,835		keystore_container,836		select_chain: maybe_select_chain,837		transaction_pool,838		other:839			(telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),840	} = new_partial::<RuntimeApi, ExecutorDispatch, _>(841		&config,842		dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,843	)?;844	let prometheus_registry = config.prometheus_registry().cloned();845846	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(847		task_manager.spawn_handle(),848		overrides_handle::<_, _, Runtime>(client.clone()),849		50,850		50,851		prometheus_registry.clone(),852	));853854	let (network, system_rpc_tx, network_starter) =855		sc_service::build_network(sc_service::BuildNetworkParams {856			config: &config,857			client: client.clone(),858			transaction_pool: transaction_pool.clone(),859			spawn_handle: task_manager.spawn_handle(),860			import_queue,861			block_announce_validator_builder: None,862			warp_sync: None,863		})?;864865	if config.offchain_worker.enabled {866		sc_service::build_offchain_workers(867			&config,868			task_manager.spawn_handle(),869			client.clone(),870			network.clone(),871		);872	}873874	let collator = config.role.is_authority();875876	let select_chain = maybe_select_chain.clone();877878	if collator {879		let block_import =880			FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());881882		let env = sc_basic_authorship::ProposerFactory::new(883			task_manager.spawn_handle(),884			client.clone(),885			transaction_pool.clone(),886			prometheus_registry.as_ref(),887			telemetry.as_ref().map(|x| x.handle()),888		);889890		let transactions_commands_stream: Box<891			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,892		> = Box::new(893			transaction_pool894				.pool()895				.validated_pool()896				.import_notification_stream()897				.map(|_| EngineCommand::SealNewBlock {898					create_empty: true,899					finalize: false,900					parent_hash: None,901					sender: None,902				}),903		);904905		let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));906		let idle_commands_stream: Box<907			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,908		> = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {909			create_empty: true,910			finalize: false,911			parent_hash: None,912			sender: None,913		}));914915		let commands_stream = select(transactions_commands_stream, idle_commands_stream);916917		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;918		let client_set_aside_for_cidp = client.clone();919920		task_manager.spawn_essential_handle().spawn_blocking(921			"authorship_task",922			Some("block-authoring"),923			run_manual_seal(ManualSealParams {924				block_import,925				env,926				client: client.clone(),927				pool: transaction_pool.clone(),928				commands_stream,929				select_chain: select_chain.clone(),930				consensus_data_provider: None,931				create_inherent_data_providers: move |block: Hash, ()| {932					let current_para_block = client_set_aside_for_cidp933						.number(block)934						.expect("Header lookup should succeed")935						.expect("Header passed in as parent should be present in backend.");936937					let client_for_xcm = client_set_aside_for_cidp.clone();938					async move {939						let time = sp_timestamp::InherentDataProvider::from_system_time();940941						let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {942							current_para_block,943							relay_offset: 1000,944							relay_blocks_per_para_block: 2,945							xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(946								&*client_for_xcm,947								block,948								Default::default(),949								Default::default(),950							),951							raw_downward_messages: vec![],952							raw_horizontal_messages: vec![],953						};954955						let slot =956						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(957							*time,958							slot_duration,959						);960961						Ok((time, slot, mocked_parachain))962					}963				},964			}),965		);966	}967968	task_manager.spawn_essential_handle().spawn(969		"frontier-mapping-sync-worker",970		Some("block-authoring"),971		MappingSyncWorker::new(972			client.import_notification_stream(),973			Duration::new(6, 0),974			client.clone(),975			backend.clone(),976			frontier_backend.clone(),977			3,978			0,979			SyncStrategy::Normal,980		)981		.for_each(|()| futures::future::ready(())),982	);983984	let rpc_client = client.clone();985	let rpc_pool = transaction_pool.clone();986	let rpc_network = network.clone();987	let rpc_frontier_backend = frontier_backend.clone();988	let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {989		let full_deps = unique_rpc::FullDeps {990			backend: rpc_frontier_backend.clone(),991			deny_unsafe,992			client: rpc_client.clone(),993			pool: rpc_pool.clone(),994			graph: rpc_pool.pool().clone(),995			// TODO: Unhardcode996			enable_dev_signer: false,997			filter_pool: filter_pool.clone(),998			network: rpc_network.clone(),999			select_chain: select_chain.clone(),1000			is_authority: collator,1001			// TODO: Unhardcode1002			max_past_logs: 10000,1003			block_data_cache: block_data_cache.clone(),1004			fee_history_cache: fee_history_cache.clone(),1005			// TODO: Unhardcode1006			fee_history_limit: 2048,1007		};10081009		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1010			full_deps,1011			subscription_executor,1012		)1013		.map_err(Into::into)1014	});10151016	sc_service::spawn_tasks(sc_service::SpawnTasksParams {1017		network,1018		client,1019		keystore: keystore_container.sync_keystore(),1020		task_manager: &mut task_manager,1021		transaction_pool,1022		rpc_builder,1023		backend,1024		system_rpc_tx,1025		config,1026		telemetry: None,1027	})?;10281029	network_starter.start_network();1030	Ok(task_manager)1031}