git.delta.rocks / unique-network / refs/commits / a52d1da68afc

difftreelog

merge master

Igor Kozyrev2022-03-30parents: #c21a15c #17c0e89.patch.diff
in: master

10 files changed

modifiedREADME.mddiffbeforeafterboth
--- a/README.md
+++ b/README.md
@@ -155,13 +155,13 @@
 location:
 	V0(X2(Parent, Parachain(PARA_ID)))
 metadata:
-	name         OPL
-	symbol       OPL
+	name         QTZ
+	symbol       QTZ
 	decimals     18
 minimalBalance	 1
 ```
 
-### Next, we can send tokens from Opal to Karura:
+### Next, we can send tokens from Quartz to Karura:
 ```
 polkadotXcm -> reserveTransferAssets
 dest:
@@ -179,7 +179,7 @@
 The result will be displayed in ChainState
 tokens -> accounts
 
-### To send tokens from Karura to Opal:
+### To send tokens from Karura to Quartz:
 ```
 xtokens -> transfer
 
modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+// Original License
 use std::sync::Arc;
 
 use codec::Decode;
modifiednode/cli/src/service.rsdiffbeforeafterboth
before · node/cli/src/service.rs
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//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.1819// std20use std::sync::Arc;21use std::sync::Mutex;22use std::collections::BTreeMap;23use std::time::Duration;24use fc_rpc_core::types::FeeHistoryCache;25use futures::StreamExt;2627use unique_rpc::overrides_handle;2829use serde::{Serialize, Deserialize};3031// Cumulus Imports32use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};33use cumulus_client_consensus_common::ParachainConsensus;34use cumulus_client_service::{35	prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,36};37use cumulus_client_cli::CollatorOptions;38use cumulus_client_network::BlockAnnounceValidator;39use cumulus_primitives_core::ParaId;40use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;41use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};42use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;4344// Substrate Imports45use sc_client_api::ExecutorProvider;46use sc_executor::NativeElseWasmExecutor;47use sc_executor::NativeExecutionDispatch;48use sc_network::NetworkService;49use sc_service::{BasePath, Configuration, PartialComponents, Role, TaskManager};50use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};51use sp_keystore::SyncCryptoStorePtr;52use sp_runtime::traits::BlakeTwo256;53use substrate_prometheus_endpoint::Registry;54use sc_client_api::BlockchainEvents;5556use polkadot_service::CollatorPair;5758// Frontier Imports59use fc_rpc_core::types::FilterPool;60use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6162use unique_runtime_common::types::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};6364/// Unique native executor instance.65#[cfg(feature = "unique-runtime")]66pub struct UniqueRuntimeExecutor;6768#[cfg(feature = "quartz-runtime")]69/// Quartz native executor instance.7071pub struct QuartzRuntimeExecutor;7273/// Opal native executor instance.74pub struct OpalRuntimeExecutor;7576#[cfg(feature = "unique-runtime")]77impl NativeExecutionDispatch for UniqueRuntimeExecutor {78	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;7980	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {81		unique_runtime::api::dispatch(method, data)82	}8384	fn native_version() -> sc_executor::NativeVersion {85		unique_runtime::native_version()86	}87}8889#[cfg(feature = "quartz-runtime")]90impl NativeExecutionDispatch for QuartzRuntimeExecutor {91	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;9293	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {94		quartz_runtime::api::dispatch(method, data)95	}9697	fn native_version() -> sc_executor::NativeVersion {98		quartz_runtime::native_version()99	}100}101102impl NativeExecutionDispatch for OpalRuntimeExecutor {103	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;104105	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {106		opal_runtime::api::dispatch(method, data)107	}108109	fn native_version() -> sc_executor::NativeVersion {110		opal_runtime::native_version()111	}112}113114pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {115	let config_dir = config116		.base_path117		.as_ref()118		.map(|base_path| base_path.config_dir(config.chain_spec.id()))119		.unwrap_or_else(|| {120			BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())121		});122	let database_dir = config_dir.join("frontier").join("db");123124	Ok(Arc::new(fc_db::Backend::<Block>::new(125		&fc_db::DatabaseSettings {126			source: fc_db::DatabaseSettingsSrc::RocksDb {127				path: database_dir,128				cache_size: 0,129			},130		},131	)?))132}133134type FullClient<RuntimeApi, ExecutorDispatch> =135	sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;136type FullBackend = sc_service::TFullBackend<Block>;137type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;138139/// Starts a `ServiceBuilder` for a full service.140///141/// Use this macro if you don't actually need the full service, but just the builder in order to142/// be able to perform chain operations.143#[allow(clippy::type_complexity)]144pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(145	config: &Configuration,146	build_import_queue: BIQ,147) -> Result<148	PartialComponents<149		FullClient<RuntimeApi, ExecutorDispatch>,150		FullBackend,151		FullSelectChain,152		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,153		sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,154		(155			Option<Telemetry>,156			Option<FilterPool>,157			Arc<fc_db::Backend<Block>>,158			Option<TelemetryWorkerHandle>,159			FeeHistoryCache,160		),161	>,162	sc_service::Error,163>164where165	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,166	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>167		+ Send168		+ Sync169		+ 'static,170	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,171	ExecutorDispatch: NativeExecutionDispatch + 'static,172	BIQ: FnOnce(173		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,174		&Configuration,175		Option<TelemetryHandle>,176		&TaskManager,177	) -> Result<178		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,179		sc_service::Error,180	>,181{182	let _telemetry = config183		.telemetry_endpoints184		.clone()185		.filter(|x| !x.is_empty())186		.map(|endpoints| -> Result<_, sc_telemetry::Error> {187			let worker = TelemetryWorker::new(16)?;188			let telemetry = worker.handle().new_telemetry(endpoints);189			Ok((worker, telemetry))190		})191		.transpose()?;192193	let telemetry = config194		.telemetry_endpoints195		.clone()196		.filter(|x| !x.is_empty())197		.map(|endpoints| -> Result<_, sc_telemetry::Error> {198			let worker = TelemetryWorker::new(16)?;199			let telemetry = worker.handle().new_telemetry(endpoints);200			Ok((worker, telemetry))201		})202		.transpose()?;203204	let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(205		config.wasm_method,206		config.default_heap_pages,207		config.max_runtime_instances,208		config.runtime_cache_size,209	);210211	let (client, backend, keystore_container, task_manager) =212		sc_service::new_full_parts::<Block, RuntimeApi, _>(213			config,214			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),215			executor,216		)?;217	let client = Arc::new(client);218219	let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());220221	let telemetry = telemetry.map(|(worker, telemetry)| {222		task_manager223			.spawn_handle()224			.spawn("telemetry", None, worker.run());225		telemetry226	});227228	let select_chain = sc_consensus::LongestChain::new(backend.clone());229230	let transaction_pool = sc_transaction_pool::BasicPool::new_full(231		config.transaction_pool.clone(),232		config.role.is_authority().into(),233		config.prometheus_registry(),234		task_manager.spawn_essential_handle(),235		client.clone(),236	);237238	let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));239240	let frontier_backend = open_frontier_backend(config)?;241242	let import_queue = build_import_queue(243		client.clone(),244		config,245		telemetry.as_ref().map(|telemetry| telemetry.handle()),246		&task_manager,247	)?;248	let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));249250	let params = PartialComponents {251		backend,252		client,253		import_queue,254		keystore_container,255		task_manager,256		transaction_pool,257		select_chain,258		other: (259			telemetry,260			filter_pool,261			frontier_backend,262			telemetry_worker_handle,263			fee_history_cache,264		),265	};266267	Ok(params)268}269270async fn build_relay_chain_interface(271	polkadot_config: Configuration,272	parachain_config: &Configuration,273	telemetry_worker_handle: Option<TelemetryWorkerHandle>,274	task_manager: &mut TaskManager,275	collator_options: CollatorOptions,276) -> RelayChainResult<(277	Arc<(dyn RelayChainInterface + 'static)>,278	Option<CollatorPair>,279)> {280	match collator_options.relay_chain_rpc_url {281		Some(relay_chain_url) => Ok((282			Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>,283			None,284		)),285		None => build_inprocess_relay_chain(286			polkadot_config,287			parachain_config,288			telemetry_worker_handle,289			task_manager,290		),291	}292}293294/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.295///296/// This is the actual implementation that is abstract over the executor and the runtime api.297#[sc_tracing::logging::prefix_logs_with("Parachain")]298async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(299	parachain_config: Configuration,300	polkadot_config: Configuration,301	collator_options: CollatorOptions,302	id: ParaId,303	build_import_queue: BIQ,304	build_consensus: BIC,305) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>306where307	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,308	Runtime: RuntimeInstance + Send + Sync + 'static,309	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,310	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,311	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>312		+ Send313		+ Sync314		+ 'static,315	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>316		+ fp_rpc::EthereumRuntimeRPCApi<Block>317		+ sp_session::SessionKeys<Block>318		+ sp_block_builder::BlockBuilder<Block>319		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>320		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>321		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>322		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>323		+ sp_api::Metadata<Block>324		+ sp_offchain::OffchainWorkerApi<Block>325		+ cumulus_primitives_core::CollectCollationInfo<Block>,326	ExecutorDispatch: NativeExecutionDispatch + 'static,327	BIQ: FnOnce(328		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,329		&Configuration,330		Option<TelemetryHandle>,331		&TaskManager,332	) -> Result<333		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,334		sc_service::Error,335	>,336	BIC: FnOnce(337		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,338		Option<&Registry>,339		Option<TelemetryHandle>,340		&TaskManager,341		Arc<dyn RelayChainInterface>,342		Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,343		Arc<NetworkService<Block, Hash>>,344		SyncCryptoStorePtr,345		bool,346	) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,347{348	if matches!(parachain_config.role, Role::Light) {349		return Err("Light client not supported!".into());350	}351352	let parachain_config = prepare_node_config(parachain_config);353354	let params =355		new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;356	let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =357		params.other;358359	let client = params.client.clone();360	let backend = params.backend.clone();361	let mut task_manager = params.task_manager;362363	let (relay_chain_interface, collator_key) = build_relay_chain_interface(364		polkadot_config,365		&parachain_config,366		telemetry_worker_handle,367		&mut task_manager,368		collator_options.clone(),369	)370	.await371	.map_err(|e| match e {372		RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,373		s => s.to_string().into(),374	})?;375376	let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);377378	let force_authoring = parachain_config.force_authoring;379	let validator = parachain_config.role.is_authority();380	let prometheus_registry = parachain_config.prometheus_registry().cloned();381	let transaction_pool = params.transaction_pool.clone();382	let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);383384	let (network, system_rpc_tx, start_network) =385		sc_service::build_network(sc_service::BuildNetworkParams {386			config: &parachain_config,387			client: client.clone(),388			transaction_pool: transaction_pool.clone(),389			spawn_handle: task_manager.spawn_handle(),390			import_queue: import_queue.clone(),391			block_announce_validator_builder: Some(Box::new(|_| {392				Box::new(block_announce_validator)393			})),394			warp_sync: None,395		})?;396397	let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());398	let rpc_client = client.clone();399	let rpc_pool = transaction_pool.clone();400	let select_chain = params.select_chain.clone();401	let rpc_network = network.clone();402403	let rpc_frontier_backend = frontier_backend.clone();404405	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(406		task_manager.spawn_handle(),407		overrides_handle::<_, _, Runtime>(client.clone()),408		50,409		50,410	));411412	let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {413		let full_deps = unique_rpc::FullDeps {414			backend: rpc_frontier_backend.clone(),415			deny_unsafe,416			client: rpc_client.clone(),417			pool: rpc_pool.clone(),418			graph: rpc_pool.pool().clone(),419			// TODO: Unhardcode420			enable_dev_signer: false,421			filter_pool: filter_pool.clone(),422			network: rpc_network.clone(),423			select_chain: select_chain.clone(),424			is_authority: validator,425			// TODO: Unhardcode426			max_past_logs: 10000,427			block_data_cache: block_data_cache.clone(),428			fee_history_cache: fee_history_cache.clone(),429			// TODO: Unhardcode430			fee_history_limit: 2048,431		};432433		Ok(434			unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(435				full_deps,436				subscription_executor.clone(),437			),438		)439	});440441	task_manager.spawn_essential_handle().spawn(442		"frontier-mapping-sync-worker",443		None,444		MappingSyncWorker::new(445			client.import_notification_stream(),446			Duration::new(6, 0),447			client.clone(),448			backend.clone(),449			frontier_backend.clone(),450			SyncStrategy::Normal,451		)452		.for_each(|()| futures::future::ready(())),453	);454455	sc_service::spawn_tasks(sc_service::SpawnTasksParams {456		rpc_extensions_builder,457		client: client.clone(),458		transaction_pool: transaction_pool.clone(),459		task_manager: &mut task_manager,460		config: parachain_config,461		keystore: params.keystore_container.sync_keystore(),462		backend: backend.clone(),463		network: network.clone(),464		system_rpc_tx,465		telemetry: telemetry.as_mut(),466	})?;467468	let announce_block = {469		let network = network.clone();470		Arc::new(move |hash, data| network.announce_block(hash, data))471	};472473	let relay_chain_slot_duration = Duration::from_secs(6);474475	if validator {476		let parachain_consensus = build_consensus(477			client.clone(),478			prometheus_registry.as_ref(),479			telemetry.as_ref().map(|t| t.handle()),480			&task_manager,481			relay_chain_interface.clone(),482			transaction_pool,483			network,484			params.keystore_container.sync_keystore(),485			force_authoring,486		)?;487488		let spawner = task_manager.spawn_handle();489490		let params = StartCollatorParams {491			para_id: id,492			block_status: client.clone(),493			announce_block,494			client: client.clone(),495			task_manager: &mut task_manager,496			spawner,497			parachain_consensus,498			import_queue,499			collator_key: collator_key.expect("Command line arguments do not allow this. qed"),500			relay_chain_interface,501			relay_chain_slot_duration,502		};503504		start_collator(params).await?;505	} else {506		let params = StartFullNodeParams {507			client: client.clone(),508			announce_block,509			task_manager: &mut task_manager,510			para_id: id,511			import_queue,512			relay_chain_interface,513			relay_chain_slot_duration,514			collator_options,515		};516517		start_full_node(params)?;518	}519520	start_network.start_network();521522	Ok((task_manager, client))523}524525/// Build the import queue for the the parachain runtime.526pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(527	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,528	config: &Configuration,529	telemetry: Option<TelemetryHandle>,530	task_manager: &TaskManager,531) -> Result<532	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,533	sc_service::Error,534>535where536	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>537		+ Send538		+ Sync539		+ 'static,540	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>541		+ sp_block_builder::BlockBuilder<Block>542		+ sp_consensus_aura::AuraApi<Block, AuraId>543		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,544	ExecutorDispatch: NativeExecutionDispatch + 'static,545{546	let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;547548	cumulus_client_consensus_aura::import_queue::<549		sp_consensus_aura::sr25519::AuthorityPair,550		_,551		_,552		_,553		_,554		_,555		_,556	>(cumulus_client_consensus_aura::ImportQueueParams {557		block_import: client.clone(),558		client: client.clone(),559		create_inherent_data_providers: move |_, _| async move {560			let time = sp_timestamp::InherentDataProvider::from_system_time();561562			let slot =563				sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(564					*time,565					slot_duration,566				);567568			Ok((time, slot))569		},570		registry: config.prometheus_registry(),571		can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),572		spawner: &task_manager.spawn_essential_handle(),573		telemetry,574	})575	.map_err(Into::into)576}577578/// Start a normal parachain node.579pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(580	parachain_config: Configuration,581	polkadot_config: Configuration,582	collator_options: CollatorOptions,583	id: ParaId,584) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>585where586	Runtime: RuntimeInstance + Send + Sync + 'static,587	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,588	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,589	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>590		+ Send591		+ Sync592		+ 'static,593	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>594		+ fp_rpc::EthereumRuntimeRPCApi<Block>595		+ sp_session::SessionKeys<Block>596		+ sp_block_builder::BlockBuilder<Block>597		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>598		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>599		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>600		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>601		+ sp_api::Metadata<Block>602		+ sp_offchain::OffchainWorkerApi<Block>603		+ cumulus_primitives_core::CollectCollationInfo<Block>604		+ sp_consensus_aura::AuraApi<Block, AuraId>,605	ExecutorDispatch: NativeExecutionDispatch + 'static,606{607	start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(608		parachain_config,609		polkadot_config,610		collator_options,611		id,612		parachain_build_import_queue,613		|client,614		 prometheus_registry,615		 telemetry,616		 task_manager,617		 relay_chain_interface,618		 transaction_pool,619		 sync_oracle,620		 keystore,621		 force_authoring| {622			let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;623624			let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(625				task_manager.spawn_handle(),626				client.clone(),627				transaction_pool,628				prometheus_registry,629				telemetry.clone(),630			);631632			Ok(AuraConsensus::build::<633				sp_consensus_aura::sr25519::AuthorityPair,634				_,635				_,636				_,637				_,638				_,639				_,640			>(BuildAuraConsensusParams {641				proposer_factory,642				create_inherent_data_providers: move |_, (relay_parent, validation_data)| {643					let relay_chain_interface = relay_chain_interface.clone();644					async move {645						let parachain_inherent =646						cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(647							relay_parent,648							&relay_chain_interface,649							&validation_data,650							id,651						).await;652653						let time = sp_timestamp::InherentDataProvider::from_system_time();654655						let slot =656						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(657							*time,658							slot_duration,659						);660661						let parachain_inherent = parachain_inherent.ok_or_else(|| {662							Box::<dyn std::error::Error + Send + Sync>::from(663								"Failed to create parachain inherent",664							)665						})?;666						Ok((time, slot, parachain_inherent))667					}668				},669				block_import: client.clone(),670				para_client: client,671				backoff_authoring_blocks: Option::<()>::None,672				sync_oracle,673				keystore,674				force_authoring,675				slot_duration,676				// We got around 500ms for proposing677				block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),678				telemetry,679				max_block_proposal_slot_portion: None,680			}))681		},682	)683	.await684}685686fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(687	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,688	config: &Configuration,689	_: Option<TelemetryHandle>,690	task_manager: &TaskManager,691) -> Result<692	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,693	sc_service::Error,694>695where696	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>697		+ Send698		+ Sync699		+ 'static,700	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>701		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,702	ExecutorDispatch: NativeExecutionDispatch + 'static,703{704	Ok(sc_consensus_manual_seal::import_queue(705		Box::new(client.clone()),706		&task_manager.spawn_essential_handle(),707		config.prometheus_registry(),708	))709}710711/// Builds a new development service. This service uses instant seal, and mocks712/// the parachain inherent713pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(714	config: Configuration,715) -> sc_service::error::Result<TaskManager>716where717	Runtime: RuntimeInstance + Send + Sync + 'static,718	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,719	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,720	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>721		+ Send722		+ Sync723		+ 'static,724	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>725		+ fp_rpc::EthereumRuntimeRPCApi<Block>726		+ sp_session::SessionKeys<Block>727		+ sp_block_builder::BlockBuilder<Block>728		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>729		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>730		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>731		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>732		+ sp_api::Metadata<Block>733		+ sp_offchain::OffchainWorkerApi<Block>734		+ cumulus_primitives_core::CollectCollationInfo<Block>735		+ sp_consensus_aura::AuraApi<Block, AuraId>,736	ExecutorDispatch: NativeExecutionDispatch + 'static,737{738	use futures::Stream;739	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};740	use fc_consensus::FrontierBlockImport;741	use sc_client_api::HeaderBackend;742743	let sc_service::PartialComponents {744		client,745		backend,746		mut task_manager,747		import_queue,748		keystore_container,749		select_chain: maybe_select_chain,750		transaction_pool,751		other:752			(telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),753	} = new_partial::<RuntimeApi, ExecutorDispatch, _>(754		&config,755		dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,756	)?;757758	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(759		task_manager.spawn_handle(),760		overrides_handle::<_, _, Runtime>(client.clone()),761		50,762		50,763	));764765	let (network, system_rpc_tx, network_starter) =766		sc_service::build_network(sc_service::BuildNetworkParams {767			config: &config,768			client: client.clone(),769			transaction_pool: transaction_pool.clone(),770			spawn_handle: task_manager.spawn_handle(),771			import_queue,772			block_announce_validator_builder: None,773			warp_sync: None,774		})?;775776	if config.offchain_worker.enabled {777		sc_service::build_offchain_workers(778			&config,779			task_manager.spawn_handle(),780			client.clone(),781			network.clone(),782		);783	}784785	let prometheus_registry = config.prometheus_registry().cloned();786	let collator = config.role.is_authority();787788	let select_chain = maybe_select_chain.clone();789790	if collator {791		let block_import =792			FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());793794		let env = sc_basic_authorship::ProposerFactory::new(795			task_manager.spawn_handle(),796			client.clone(),797			transaction_pool.clone(),798			prometheus_registry.as_ref(),799			telemetry.as_ref().map(|x| x.handle()),800		);801802		let commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =803			Box::new(804				// This bit cribbed from the implementation of instant seal.805				transaction_pool806					.pool()807					.validated_pool()808					.import_notification_stream()809					.map(|_| EngineCommand::SealNewBlock {810						create_empty: true, // was false in Moonbeam811						finalize: false,812						parent_hash: None,813						sender: None,814					}),815			);816817		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;818		let client_set_aside_for_cidp = client.clone();819820		task_manager.spawn_essential_handle().spawn_blocking(821			"authorship_task",822			Some("block-authoring"),823			run_manual_seal(ManualSealParams {824				block_import,825				env,826				client: client.clone(),827				pool: transaction_pool.clone(),828				commands_stream,829				select_chain: select_chain.clone(),830				consensus_data_provider: None,831				create_inherent_data_providers: move |block: Hash, ()| {832					let current_para_block = client_set_aside_for_cidp833						.number(block)834						.expect("Header lookup should succeed")835						.expect("Header passed in as parent should be present in backend.");836837					let client_for_xcm = client_set_aside_for_cidp.clone();838					async move {839						let time = sp_timestamp::InherentDataProvider::from_system_time();840841						let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {842							current_para_block,843							relay_offset: 1000,844							relay_blocks_per_para_block: 2,845							xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(846								&*client_for_xcm,847								block,848								Default::default(),849								Default::default(),850							),851							raw_downward_messages: vec![],852							raw_horizontal_messages: vec![],853						};854855						let slot =856						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(857							*time,858							slot_duration,859						);860861						Ok((time, slot, mocked_parachain))862					}863				},864			}),865		);866	}867868	task_manager.spawn_essential_handle().spawn(869		"frontier-mapping-sync-worker",870		Some("block-authoring"),871		MappingSyncWorker::new(872			client.import_notification_stream(),873			Duration::new(6, 0),874			client.clone(),875			backend.clone(),876			frontier_backend.clone(),877			SyncStrategy::Normal,878		)879		.for_each(|()| futures::future::ready(())),880	);881882	let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());883	let rpc_client = client.clone();884	let rpc_pool = transaction_pool.clone();885	let rpc_network = network.clone();886	let rpc_frontier_backend = frontier_backend.clone();887	let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {888		let full_deps = unique_rpc::FullDeps {889			backend: rpc_frontier_backend.clone(),890			deny_unsafe,891			client: rpc_client.clone(),892			pool: rpc_pool.clone(),893			graph: rpc_pool.pool().clone(),894			// TODO: Unhardcode895			enable_dev_signer: false,896			filter_pool: filter_pool.clone(),897			network: rpc_network.clone(),898			select_chain: select_chain.clone(),899			is_authority: collator,900			// TODO: Unhardcode901			max_past_logs: 10000,902			block_data_cache: block_data_cache.clone(),903			fee_history_cache: fee_history_cache.clone(),904			// TODO: Unhardcode905			fee_history_limit: 2048,906		};907908		Ok(909			unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(910				full_deps,911				subscription_executor.clone(),912			),913		)914	});915916	sc_service::spawn_tasks(sc_service::SpawnTasksParams {917		network,918		client,919		keystore: keystore_container.sync_keystore(),920		task_manager: &mut task_manager,921		transaction_pool,922		rpc_extensions_builder,923		backend,924		system_rpc_tx,925		config,926		telemetry: None,927	})?;928929	network_starter.start_network();930	Ok(task_manager)931}
after · node/cli/src/service.rs
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 fc_rpc_core::types::FeeHistoryCache;23use futures::StreamExt;2425use unique_rpc::overrides_handle;2627use serde::{Serialize, Deserialize};2829// Cumulus Imports30use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};31use cumulus_client_consensus_common::ParachainConsensus;32use cumulus_client_service::{33	prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,34};35use cumulus_client_cli::CollatorOptions;36use cumulus_client_network::BlockAnnounceValidator;37use cumulus_primitives_core::ParaId;38use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;39use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};40use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;4142// Substrate Imports43use sc_client_api::ExecutorProvider;44use sc_executor::NativeElseWasmExecutor;45use sc_executor::NativeExecutionDispatch;46use sc_network::NetworkService;47use sc_service::{BasePath, Configuration, PartialComponents, Role, TaskManager};48use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};49use sp_keystore::SyncCryptoStorePtr;50use sp_runtime::traits::BlakeTwo256;51use substrate_prometheus_endpoint::Registry;52use sc_client_api::BlockchainEvents;5354use polkadot_service::CollatorPair;5556// Frontier Imports57use fc_rpc_core::types::FilterPool;58use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};5960use unique_runtime_common::types::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};6162/// Unique native executor instance.63#[cfg(feature = "unique-runtime")]64pub struct UniqueRuntimeExecutor;6566#[cfg(feature = "quartz-runtime")]67/// Quartz native executor instance.6869pub struct QuartzRuntimeExecutor;7071/// Opal native executor instance.72pub struct OpalRuntimeExecutor;7374#[cfg(feature = "unique-runtime")]75impl NativeExecutionDispatch for UniqueRuntimeExecutor {76	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;7778	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {79		unique_runtime::api::dispatch(method, data)80	}8182	fn native_version() -> sc_executor::NativeVersion {83		unique_runtime::native_version()84	}85}8687#[cfg(feature = "quartz-runtime")]88impl NativeExecutionDispatch for QuartzRuntimeExecutor {89	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;9091	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {92		quartz_runtime::api::dispatch(method, data)93	}9495	fn native_version() -> sc_executor::NativeVersion {96		quartz_runtime::native_version()97	}98}99100impl NativeExecutionDispatch for OpalRuntimeExecutor {101	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;102103	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {104		opal_runtime::api::dispatch(method, data)105	}106107	fn native_version() -> sc_executor::NativeVersion {108		opal_runtime::native_version()109	}110}111112pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {113	let config_dir = config114		.base_path115		.as_ref()116		.map(|base_path| base_path.config_dir(config.chain_spec.id()))117		.unwrap_or_else(|| {118			BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())119		});120	let database_dir = config_dir.join("frontier").join("db");121122	Ok(Arc::new(fc_db::Backend::<Block>::new(123		&fc_db::DatabaseSettings {124			source: fc_db::DatabaseSettingsSrc::RocksDb {125				path: database_dir,126				cache_size: 0,127			},128		},129	)?))130}131132type FullClient<RuntimeApi, ExecutorDispatch> =133	sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;134type FullBackend = sc_service::TFullBackend<Block>;135type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;136137/// Starts a `ServiceBuilder` for a full service.138///139/// Use this macro if you don't actually need the full service, but just the builder in order to140/// be able to perform chain operations.141#[allow(clippy::type_complexity)]142pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(143	config: &Configuration,144	build_import_queue: BIQ,145) -> Result<146	PartialComponents<147		FullClient<RuntimeApi, ExecutorDispatch>,148		FullBackend,149		FullSelectChain,150		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,151		sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,152		(153			Option<Telemetry>,154			Option<FilterPool>,155			Arc<fc_db::Backend<Block>>,156			Option<TelemetryWorkerHandle>,157			FeeHistoryCache,158		),159	>,160	sc_service::Error,161>162where163	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,164	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>165		+ Send166		+ Sync167		+ 'static,168	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,169	ExecutorDispatch: NativeExecutionDispatch + 'static,170	BIQ: FnOnce(171		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,172		&Configuration,173		Option<TelemetryHandle>,174		&TaskManager,175	) -> Result<176		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,177		sc_service::Error,178	>,179{180	let _telemetry = config181		.telemetry_endpoints182		.clone()183		.filter(|x| !x.is_empty())184		.map(|endpoints| -> Result<_, sc_telemetry::Error> {185			let worker = TelemetryWorker::new(16)?;186			let telemetry = worker.handle().new_telemetry(endpoints);187			Ok((worker, telemetry))188		})189		.transpose()?;190191	let telemetry = config192		.telemetry_endpoints193		.clone()194		.filter(|x| !x.is_empty())195		.map(|endpoints| -> Result<_, sc_telemetry::Error> {196			let worker = TelemetryWorker::new(16)?;197			let telemetry = worker.handle().new_telemetry(endpoints);198			Ok((worker, telemetry))199		})200		.transpose()?;201202	let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(203		config.wasm_method,204		config.default_heap_pages,205		config.max_runtime_instances,206		config.runtime_cache_size,207	);208209	let (client, backend, keystore_container, task_manager) =210		sc_service::new_full_parts::<Block, RuntimeApi, _>(211			config,212			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),213			executor,214		)?;215	let client = Arc::new(client);216217	let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());218219	let telemetry = telemetry.map(|(worker, telemetry)| {220		task_manager221			.spawn_handle()222			.spawn("telemetry", None, worker.run());223		telemetry224	});225226	let select_chain = sc_consensus::LongestChain::new(backend.clone());227228	let transaction_pool = sc_transaction_pool::BasicPool::new_full(229		config.transaction_pool.clone(),230		config.role.is_authority().into(),231		config.prometheus_registry(),232		task_manager.spawn_essential_handle(),233		client.clone(),234	);235236	let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));237238	let frontier_backend = open_frontier_backend(config)?;239240	let import_queue = build_import_queue(241		client.clone(),242		config,243		telemetry.as_ref().map(|telemetry| telemetry.handle()),244		&task_manager,245	)?;246	let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));247248	let params = PartialComponents {249		backend,250		client,251		import_queue,252		keystore_container,253		task_manager,254		transaction_pool,255		select_chain,256		other: (257			telemetry,258			filter_pool,259			frontier_backend,260			telemetry_worker_handle,261			fee_history_cache,262		),263	};264265	Ok(params)266}267268async fn build_relay_chain_interface(269	polkadot_config: Configuration,270	parachain_config: &Configuration,271	telemetry_worker_handle: Option<TelemetryWorkerHandle>,272	task_manager: &mut TaskManager,273	collator_options: CollatorOptions,274) -> RelayChainResult<(275	Arc<(dyn RelayChainInterface + 'static)>,276	Option<CollatorPair>,277)> {278	match collator_options.relay_chain_rpc_url {279		Some(relay_chain_url) => Ok((280			Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>,281			None,282		)),283		None => build_inprocess_relay_chain(284			polkadot_config,285			parachain_config,286			telemetry_worker_handle,287			task_manager,288		),289	}290}291292/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.293///294/// This is the actual implementation that is abstract over the executor and the runtime api.295#[sc_tracing::logging::prefix_logs_with("Parachain")]296async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(297	parachain_config: Configuration,298	polkadot_config: Configuration,299	collator_options: CollatorOptions,300	id: ParaId,301	build_import_queue: BIQ,302	build_consensus: BIC,303) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>304where305	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,306	Runtime: RuntimeInstance + Send + Sync + 'static,307	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,308	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,309	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>310		+ Send311		+ Sync312		+ 'static,313	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>314		+ fp_rpc::EthereumRuntimeRPCApi<Block>315		+ sp_session::SessionKeys<Block>316		+ sp_block_builder::BlockBuilder<Block>317		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>318		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>319		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>320		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>321		+ sp_api::Metadata<Block>322		+ sp_offchain::OffchainWorkerApi<Block>323		+ cumulus_primitives_core::CollectCollationInfo<Block>,324	ExecutorDispatch: NativeExecutionDispatch + 'static,325	BIQ: FnOnce(326		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,327		&Configuration,328		Option<TelemetryHandle>,329		&TaskManager,330	) -> Result<331		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,332		sc_service::Error,333	>,334	BIC: FnOnce(335		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,336		Option<&Registry>,337		Option<TelemetryHandle>,338		&TaskManager,339		Arc<dyn RelayChainInterface>,340		Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,341		Arc<NetworkService<Block, Hash>>,342		SyncCryptoStorePtr,343		bool,344	) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,345{346	if matches!(parachain_config.role, Role::Light) {347		return Err("Light client not supported!".into());348	}349350	let parachain_config = prepare_node_config(parachain_config);351352	let params =353		new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;354	let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =355		params.other;356357	let client = params.client.clone();358	let backend = params.backend.clone();359	let mut task_manager = params.task_manager;360361	let (relay_chain_interface, collator_key) = build_relay_chain_interface(362		polkadot_config,363		&parachain_config,364		telemetry_worker_handle,365		&mut task_manager,366		collator_options.clone(),367	)368	.await369	.map_err(|e| match e {370		RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,371		s => s.to_string().into(),372	})?;373374	let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);375376	let force_authoring = parachain_config.force_authoring;377	let validator = parachain_config.role.is_authority();378	let prometheus_registry = parachain_config.prometheus_registry().cloned();379	let transaction_pool = params.transaction_pool.clone();380	let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);381382	let (network, system_rpc_tx, start_network) =383		sc_service::build_network(sc_service::BuildNetworkParams {384			config: &parachain_config,385			client: client.clone(),386			transaction_pool: transaction_pool.clone(),387			spawn_handle: task_manager.spawn_handle(),388			import_queue: import_queue.clone(),389			block_announce_validator_builder: Some(Box::new(|_| {390				Box::new(block_announce_validator)391			})),392			warp_sync: None,393		})?;394395	let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());396	let rpc_client = client.clone();397	let rpc_pool = transaction_pool.clone();398	let select_chain = params.select_chain.clone();399	let rpc_network = network.clone();400401	let rpc_frontier_backend = frontier_backend.clone();402403	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(404		task_manager.spawn_handle(),405		overrides_handle::<_, _, Runtime>(client.clone()),406		50,407		50,408	));409410	let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {411		let full_deps = unique_rpc::FullDeps {412			backend: rpc_frontier_backend.clone(),413			deny_unsafe,414			client: rpc_client.clone(),415			pool: rpc_pool.clone(),416			graph: rpc_pool.pool().clone(),417			// TODO: Unhardcode418			enable_dev_signer: false,419			filter_pool: filter_pool.clone(),420			network: rpc_network.clone(),421			select_chain: select_chain.clone(),422			is_authority: validator,423			// TODO: Unhardcode424			max_past_logs: 10000,425			block_data_cache: block_data_cache.clone(),426			fee_history_cache: fee_history_cache.clone(),427			// TODO: Unhardcode428			fee_history_limit: 2048,429		};430431		Ok(432			unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(433				full_deps,434				subscription_executor.clone(),435			),436		)437	});438439	task_manager.spawn_essential_handle().spawn(440		"frontier-mapping-sync-worker",441		None,442		MappingSyncWorker::new(443			client.import_notification_stream(),444			Duration::new(6, 0),445			client.clone(),446			backend.clone(),447			frontier_backend.clone(),448			SyncStrategy::Normal,449		)450		.for_each(|()| futures::future::ready(())),451	);452453	sc_service::spawn_tasks(sc_service::SpawnTasksParams {454		rpc_extensions_builder,455		client: client.clone(),456		transaction_pool: transaction_pool.clone(),457		task_manager: &mut task_manager,458		config: parachain_config,459		keystore: params.keystore_container.sync_keystore(),460		backend: backend.clone(),461		network: network.clone(),462		system_rpc_tx,463		telemetry: telemetry.as_mut(),464	})?;465466	let announce_block = {467		let network = network.clone();468		Arc::new(move |hash, data| network.announce_block(hash, data))469	};470471	let relay_chain_slot_duration = Duration::from_secs(6);472473	if validator {474		let parachain_consensus = build_consensus(475			client.clone(),476			prometheus_registry.as_ref(),477			telemetry.as_ref().map(|t| t.handle()),478			&task_manager,479			relay_chain_interface.clone(),480			transaction_pool,481			network,482			params.keystore_container.sync_keystore(),483			force_authoring,484		)?;485486		let spawner = task_manager.spawn_handle();487488		let params = StartCollatorParams {489			para_id: id,490			block_status: client.clone(),491			announce_block,492			client: client.clone(),493			task_manager: &mut task_manager,494			spawner,495			parachain_consensus,496			import_queue,497			collator_key: collator_key.expect("Command line arguments do not allow this. qed"),498			relay_chain_interface,499			relay_chain_slot_duration,500		};501502		start_collator(params).await?;503	} else {504		let params = StartFullNodeParams {505			client: client.clone(),506			announce_block,507			task_manager: &mut task_manager,508			para_id: id,509			import_queue,510			relay_chain_interface,511			relay_chain_slot_duration,512			collator_options,513		};514515		start_full_node(params)?;516	}517518	start_network.start_network();519520	Ok((task_manager, client))521}522523/// Build the import queue for the the parachain runtime.524pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(525	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,526	config: &Configuration,527	telemetry: Option<TelemetryHandle>,528	task_manager: &TaskManager,529) -> Result<530	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,531	sc_service::Error,532>533where534	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>535		+ Send536		+ Sync537		+ 'static,538	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>539		+ sp_block_builder::BlockBuilder<Block>540		+ sp_consensus_aura::AuraApi<Block, AuraId>541		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,542	ExecutorDispatch: NativeExecutionDispatch + 'static,543{544	let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;545546	cumulus_client_consensus_aura::import_queue::<547		sp_consensus_aura::sr25519::AuthorityPair,548		_,549		_,550		_,551		_,552		_,553		_,554	>(cumulus_client_consensus_aura::ImportQueueParams {555		block_import: client.clone(),556		client: client.clone(),557		create_inherent_data_providers: move |_, _| async move {558			let time = sp_timestamp::InherentDataProvider::from_system_time();559560			let slot =561				sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(562					*time,563					slot_duration,564				);565566			Ok((time, slot))567		},568		registry: config.prometheus_registry(),569		can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),570		spawner: &task_manager.spawn_essential_handle(),571		telemetry,572	})573	.map_err(Into::into)574}575576/// Start a normal parachain node.577pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(578	parachain_config: Configuration,579	polkadot_config: Configuration,580	collator_options: CollatorOptions,581	id: ParaId,582) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>583where584	Runtime: RuntimeInstance + Send + Sync + 'static,585	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,586	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,587	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>588		+ Send589		+ Sync590		+ 'static,591	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>592		+ fp_rpc::EthereumRuntimeRPCApi<Block>593		+ sp_session::SessionKeys<Block>594		+ sp_block_builder::BlockBuilder<Block>595		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>596		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>597		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>598		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>599		+ sp_api::Metadata<Block>600		+ sp_offchain::OffchainWorkerApi<Block>601		+ cumulus_primitives_core::CollectCollationInfo<Block>602		+ sp_consensus_aura::AuraApi<Block, AuraId>,603	ExecutorDispatch: NativeExecutionDispatch + 'static,604{605	start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(606		parachain_config,607		polkadot_config,608		collator_options,609		id,610		parachain_build_import_queue,611		|client,612		 prometheus_registry,613		 telemetry,614		 task_manager,615		 relay_chain_interface,616		 transaction_pool,617		 sync_oracle,618		 keystore,619		 force_authoring| {620			let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;621622			let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(623				task_manager.spawn_handle(),624				client.clone(),625				transaction_pool,626				prometheus_registry,627				telemetry.clone(),628			);629630			Ok(AuraConsensus::build::<631				sp_consensus_aura::sr25519::AuthorityPair,632				_,633				_,634				_,635				_,636				_,637				_,638			>(BuildAuraConsensusParams {639				proposer_factory,640				create_inherent_data_providers: move |_, (relay_parent, validation_data)| {641					let relay_chain_interface = relay_chain_interface.clone();642					async move {643						let parachain_inherent =644						cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(645							relay_parent,646							&relay_chain_interface,647							&validation_data,648							id,649						).await;650651						let time = sp_timestamp::InherentDataProvider::from_system_time();652653						let slot =654						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(655							*time,656							slot_duration,657						);658659						let parachain_inherent = parachain_inherent.ok_or_else(|| {660							Box::<dyn std::error::Error + Send + Sync>::from(661								"Failed to create parachain inherent",662							)663						})?;664						Ok((time, slot, parachain_inherent))665					}666				},667				block_import: client.clone(),668				para_client: client,669				backoff_authoring_blocks: Option::<()>::None,670				sync_oracle,671				keystore,672				force_authoring,673				slot_duration,674				// We got around 500ms for proposing675				block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),676				telemetry,677				max_block_proposal_slot_portion: None,678			}))679		},680	)681	.await682}683684fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(685	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,686	config: &Configuration,687	_: Option<TelemetryHandle>,688	task_manager: &TaskManager,689) -> Result<690	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,691	sc_service::Error,692>693where694	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>695		+ Send696		+ Sync697		+ 'static,698	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>699		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,700	ExecutorDispatch: NativeExecutionDispatch + 'static,701{702	Ok(sc_consensus_manual_seal::import_queue(703		Box::new(client.clone()),704		&task_manager.spawn_essential_handle(),705		config.prometheus_registry(),706	))707}708709/// Builds a new development service. This service uses instant seal, and mocks710/// the parachain inherent711pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(712	config: Configuration,713) -> sc_service::error::Result<TaskManager>714where715	Runtime: RuntimeInstance + Send + Sync + 'static,716	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,717	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,718	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>719		+ Send720		+ Sync721		+ 'static,722	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>723		+ fp_rpc::EthereumRuntimeRPCApi<Block>724		+ sp_session::SessionKeys<Block>725		+ sp_block_builder::BlockBuilder<Block>726		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>727		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>728		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>729		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>730		+ sp_api::Metadata<Block>731		+ sp_offchain::OffchainWorkerApi<Block>732		+ cumulus_primitives_core::CollectCollationInfo<Block>733		+ sp_consensus_aura::AuraApi<Block, AuraId>,734	ExecutorDispatch: NativeExecutionDispatch + 'static,735{736	use futures::Stream;737	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};738	use fc_consensus::FrontierBlockImport;739	use sc_client_api::HeaderBackend;740741	let sc_service::PartialComponents {742		client,743		backend,744		mut task_manager,745		import_queue,746		keystore_container,747		select_chain: maybe_select_chain,748		transaction_pool,749		other:750			(telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),751	} = new_partial::<RuntimeApi, ExecutorDispatch, _>(752		&config,753		dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,754	)?;755756	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(757		task_manager.spawn_handle(),758		overrides_handle::<_, _, Runtime>(client.clone()),759		50,760		50,761	));762763	let (network, system_rpc_tx, network_starter) =764		sc_service::build_network(sc_service::BuildNetworkParams {765			config: &config,766			client: client.clone(),767			transaction_pool: transaction_pool.clone(),768			spawn_handle: task_manager.spawn_handle(),769			import_queue,770			block_announce_validator_builder: None,771			warp_sync: None,772		})?;773774	if config.offchain_worker.enabled {775		sc_service::build_offchain_workers(776			&config,777			task_manager.spawn_handle(),778			client.clone(),779			network.clone(),780		);781	}782783	let prometheus_registry = config.prometheus_registry().cloned();784	let collator = config.role.is_authority();785786	let select_chain = maybe_select_chain.clone();787788	if collator {789		let block_import =790			FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());791792		let env = sc_basic_authorship::ProposerFactory::new(793			task_manager.spawn_handle(),794			client.clone(),795			transaction_pool.clone(),796			prometheus_registry.as_ref(),797			telemetry.as_ref().map(|x| x.handle()),798		);799800		let commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =801			Box::new(802				// This bit cribbed from the implementation of instant seal.803				transaction_pool804					.pool()805					.validated_pool()806					.import_notification_stream()807					.map(|_| EngineCommand::SealNewBlock {808						create_empty: true, // was false in Moonbeam809						finalize: false,810						parent_hash: None,811						sender: None,812					}),813			);814815		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;816		let client_set_aside_for_cidp = client.clone();817818		task_manager.spawn_essential_handle().spawn_blocking(819			"authorship_task",820			Some("block-authoring"),821			run_manual_seal(ManualSealParams {822				block_import,823				env,824				client: client.clone(),825				pool: transaction_pool.clone(),826				commands_stream,827				select_chain: select_chain.clone(),828				consensus_data_provider: None,829				create_inherent_data_providers: move |block: Hash, ()| {830					let current_para_block = client_set_aside_for_cidp831						.number(block)832						.expect("Header lookup should succeed")833						.expect("Header passed in as parent should be present in backend.");834835					let client_for_xcm = client_set_aside_for_cidp.clone();836					async move {837						let time = sp_timestamp::InherentDataProvider::from_system_time();838839						let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {840							current_para_block,841							relay_offset: 1000,842							relay_blocks_per_para_block: 2,843							xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(844								&*client_for_xcm,845								block,846								Default::default(),847								Default::default(),848							),849							raw_downward_messages: vec![],850							raw_horizontal_messages: vec![],851						};852853						let slot =854						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(855							*time,856							slot_duration,857						);858859						Ok((time, slot, mocked_parachain))860					}861				},862			}),863		);864	}865866	task_manager.spawn_essential_handle().spawn(867		"frontier-mapping-sync-worker",868		Some("block-authoring"),869		MappingSyncWorker::new(870			client.import_notification_stream(),871			Duration::new(6, 0),872			client.clone(),873			backend.clone(),874			frontier_backend.clone(),875			SyncStrategy::Normal,876		)877		.for_each(|()| futures::future::ready(())),878	);879880	let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());881	let rpc_client = client.clone();882	let rpc_pool = transaction_pool.clone();883	let rpc_network = network.clone();884	let rpc_frontier_backend = frontier_backend.clone();885	let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {886		let full_deps = unique_rpc::FullDeps {887			backend: rpc_frontier_backend.clone(),888			deny_unsafe,889			client: rpc_client.clone(),890			pool: rpc_pool.clone(),891			graph: rpc_pool.pool().clone(),892			// TODO: Unhardcode893			enable_dev_signer: false,894			filter_pool: filter_pool.clone(),895			network: rpc_network.clone(),896			select_chain: select_chain.clone(),897			is_authority: collator,898			// TODO: Unhardcode899			max_past_logs: 10000,900			block_data_cache: block_data_cache.clone(),901			fee_history_cache: fee_history_cache.clone(),902			// TODO: Unhardcode903			fee_history_limit: 2048,904		};905906		Ok(907			unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(908				full_deps,909				subscription_executor.clone(),910			),911		)912	});913914	sc_service::spawn_tasks(sc_service::SpawnTasksParams {915		network,916		client,917		keystore: keystore_container.sync_keystore(),918		task_manager: &mut task_manager,919		transaction_pool,920		rpc_extensions_builder,921		backend,922		system_rpc_tx,923		config,924		telemetry: None,925	})?;926927	network_starter.start_network();928	Ok(task_manager)929}
modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-// Original license
+// Original license:
 // This file is part of Substrate.
 
 // Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -216,11 +216,15 @@
 		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
 		.build_or_panic();
 	pub const Version: RuntimeVersion = VERSION;
-	pub const SS58Prefix: u8 = 42;
+	/*
+	255 - Quartz
+	42 - Opal
+	*/
+	pub const SS58Prefix: u8 = 255;
 }
 
 parameter_types! {
-	pub const ChainId: u64 = 8882;
+	pub const ChainId: u64 = 8881;
 }
 
 pub struct FixedFee;
modifiedtests/flipper-src/lib.rsdiffbeforeafterboth
--- a/tests/flipper-src/lib.rs
+++ b/tests/flipper-src/lib.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-// Original license
+// Original License
 // Copyright 2018-2020 Parity Technologies (UK) Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
modifiedtests/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth
--- a/tests/ink-types-node-runtime/src/calls.rs
+++ b/tests/ink-types-node-runtime/src/calls.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-// Original license
+// Original License
 // Copyright 2019 Parity Technologies (UK) Ltd.
 // This file is part of ink!.
 //
modifiedtests/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth
--- a/tests/ink-types-node-runtime/src/lib.rs
+++ b/tests/ink-types-node-runtime/src/lib.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-// Original license
+// Original License
 // Copyright 2018-2019 Parity Technologies (UK) Ltd.
 // This file is part of ink!.
 //
modifiedtests/loadtester-src/lib.rsdiffbeforeafterboth
--- a/tests/loadtester-src/lib.rs
+++ b/tests/loadtester-src/lib.rs
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+// Original License
 #![cfg_attr(not(feature = "std"), no_std)]
 
 use ink_lang as ink;
modifiedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
--- a/tests/src/xcmTransfer.test.ts
+++ b/tests/src/xcmTransfer.test.ts
@@ -34,7 +34,7 @@
 const KARURA_CHAIN = 2000;
 const KARURA_PORT = '9946';
 
-describe('Integration test: Exchanging OPL with Karura', () => {
+describe('Integration test: Exchanging QTZ with Karura', () => {
   let alice: IKeyringPair;
   
   before(async () => {
@@ -60,8 +60,8 @@
 
       const metadata =
       {
-        name: 'OPL',
-        symbol: 'OPL',
+        name: 'QTZ',
+        symbol: 'QTZ',
         decimals: 18,
         minimalBalance: 1,
       };
@@ -74,7 +74,7 @@
     }, karuraApiOptions);
   });
 
-  it('Should connect and send OPL to Karura', async () => {
+  it('Should connect and send QTZ to Karura', async () => {
     let balanceOnKaruraBefore: bigint;
     
     await usingApi(async (api) => {
@@ -141,7 +141,7 @@
     }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
   });
 
-  it('Should connect to Karura and send OPL back', async () => {
+  it('Should connect to Karura and send QTZ back', async () => {
     let balanceBefore: bigint;
     
     await usingApi(async (api) => {