git.delta.rocks / unique-network / refs/commits / 896d7c692dac

difftreelog

feat(collator-selection) interaction with configuration pallet

Fahrrader2022-12-27parent: #70abe57.patch.diff
in: master

17 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -24,7 +24,6 @@
 use serde_json::map::Map;
 
 use up_common::types::opaque::*;
-use up_common::constants::{GENESIS_LICENSE_BOND, SESSION_LENGTH};
 
 #[cfg(feature = "unique-runtime")]
 pub use unique_runtime as default_runtime;
@@ -196,9 +195,6 @@
 					.cloned()
 					.map(|(acc, _)| acc)
 					.collect(),
-				desired_collators: 10,
-				license_bond: GENESIS_LICENSE_BOND,
-				kick_threshold: SESSION_LENGTH,
 			},
 			session: SessionConfig {
 				keys: $initial_invulnerables
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// std18use std::sync::Arc;19use std::sync::Mutex;20use std::collections::BTreeMap;21use std::time::Duration;22use std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25	Stream, StreamExt,26	stream::select,27	task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38	ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41	prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;6162use polkadot_service::CollatorPair;6364// Frontier Imports65use fc_rpc_core::types::FilterPool;66use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6768use up_common::types::opaque::{69	AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block, BlockNumber,70};7172// RMRK73use up_data_structs::{74	RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,75	RmrkPartType, RmrkTheme,76};7778/// Unique native executor instance.79#[cfg(feature = "unique-runtime")]80pub struct UniqueRuntimeExecutor;8182#[cfg(feature = "quartz-runtime")]83/// Quartz native executor instance.84pub struct QuartzRuntimeExecutor;8586/// Opal native executor instance.87pub struct OpalRuntimeExecutor;8889#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]90pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;9192#[cfg(all(93	not(feature = "unique-runtime"),94	feature = "quartz-runtime",95	feature = "runtime-benchmarks"96))]97pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9899#[cfg(all(100	not(feature = "unique-runtime"),101	not(feature = "quartz-runtime"),102	feature = "runtime-benchmarks"103))]104pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;105106#[cfg(feature = "unique-runtime")]107impl NativeExecutionDispatch for UniqueRuntimeExecutor {108	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;109110	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {111		unique_runtime::api::dispatch(method, data)112	}113114	fn native_version() -> sc_executor::NativeVersion {115		unique_runtime::native_version()116	}117}118119#[cfg(feature = "quartz-runtime")]120impl NativeExecutionDispatch for QuartzRuntimeExecutor {121	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;122123	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {124		quartz_runtime::api::dispatch(method, data)125	}126127	fn native_version() -> sc_executor::NativeVersion {128		quartz_runtime::native_version()129	}130}131132impl NativeExecutionDispatch for OpalRuntimeExecutor {133	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;134135	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {136		opal_runtime::api::dispatch(method, data)137	}138139	fn native_version() -> sc_executor::NativeVersion {140		opal_runtime::native_version()141	}142}143144pub struct AutosealInterval {145	interval: Interval,146}147148impl AutosealInterval {149	pub fn new(config: &Configuration, interval: Duration) -> Self {150		let _tokio_runtime = config.tokio_handle.enter();151		let interval = tokio::time::interval(interval);152153		Self { interval }154	}155}156157impl Stream for AutosealInterval {158	type Item = tokio::time::Instant;159160	fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {161		self.interval.poll_tick(cx).map(Some)162	}163}164165pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(166	client: Arc<C>,167	config: &Configuration,168) -> Result<Arc<fc_db::Backend<Block>>, String> {169	let config_dir = config170		.base_path171		.as_ref()172		.map(|base_path| base_path.config_dir(config.chain_spec.id()))173		.unwrap_or_else(|| {174			BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())175		});176	let database_dir = config_dir.join("frontier").join("db");177178	Ok(Arc::new(fc_db::Backend::<Block>::new(179		client,180		&fc_db::DatabaseSettings {181			source: fc_db::DatabaseSource::RocksDb {182				path: database_dir,183				cache_size: 0,184			},185		},186	)?))187}188189type FullClient<RuntimeApi, ExecutorDispatch> =190	sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;191type FullBackend = sc_service::TFullBackend<Block>;192type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;193type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =194	TParachainBlockImport<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>;195196/// Starts a `ServiceBuilder` for a full service.197///198/// Use this macro if you don't actually need the full service, but just the builder in order to199/// be able to perform chain operations.200#[allow(clippy::type_complexity)]201pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(202	config: &Configuration,203	build_import_queue: BIQ,204) -> Result<205	PartialComponents<206		FullClient<RuntimeApi, ExecutorDispatch>,207		FullBackend,208		FullSelectChain,209		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,210		sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,211		(212			Option<Telemetry>,213			Option<FilterPool>,214			Arc<fc_db::Backend<Block>>,215			Option<TelemetryWorkerHandle>,216			FeeHistoryCache,217		),218	>,219	sc_service::Error,220>221where222	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,223	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>224		+ Send225		+ Sync226		+ 'static,227	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,228	ExecutorDispatch: NativeExecutionDispatch + 'static,229	BIQ: FnOnce(230		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,231		&Configuration,232		Option<TelemetryHandle>,233		&TaskManager,234	) -> Result<235		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,236		sc_service::Error,237	>,238{239	let _telemetry = config240		.telemetry_endpoints241		.clone()242		.filter(|x| !x.is_empty())243		.map(|endpoints| -> Result<_, sc_telemetry::Error> {244			let worker = TelemetryWorker::new(16)?;245			let telemetry = worker.handle().new_telemetry(endpoints);246			Ok((worker, telemetry))247		})248		.transpose()?;249250	let telemetry = config251		.telemetry_endpoints252		.clone()253		.filter(|x| !x.is_empty())254		.map(|endpoints| -> Result<_, sc_telemetry::Error> {255			let worker = TelemetryWorker::new(16)?;256			let telemetry = worker.handle().new_telemetry(endpoints);257			Ok((worker, telemetry))258		})259		.transpose()?;260261	let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(262		config.wasm_method,263		config.default_heap_pages,264		config.max_runtime_instances,265		config.runtime_cache_size,266	);267268	let (client, backend, keystore_container, task_manager) =269		sc_service::new_full_parts::<Block, RuntimeApi, _>(270			config,271			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),272			executor,273		)?;274	let client = Arc::new(client);275276	let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());277278	let telemetry = telemetry.map(|(worker, telemetry)| {279		task_manager280			.spawn_handle()281			.spawn("telemetry", None, worker.run());282		telemetry283	});284285	let select_chain = sc_consensus::LongestChain::new(backend.clone());286287	let transaction_pool = sc_transaction_pool::BasicPool::new_full(288		config.transaction_pool.clone(),289		config.role.is_authority().into(),290		config.prometheus_registry(),291		task_manager.spawn_essential_handle(),292		client.clone(),293	);294295	let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));296297	let frontier_backend = open_frontier_backend(client.clone(), config)?;298299	let import_queue = build_import_queue(300		client.clone(),301		config,302		telemetry.as_ref().map(|telemetry| telemetry.handle()),303		&task_manager,304	)?;305	let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));306307	let params = PartialComponents {308		backend,309		client,310		import_queue,311		keystore_container,312		task_manager,313		transaction_pool,314		select_chain,315		other: (316			telemetry,317			filter_pool,318			frontier_backend,319			telemetry_worker_handle,320			fee_history_cache,321		),322	};323324	Ok(params)325}326327async fn build_relay_chain_interface(328	polkadot_config: Configuration,329	parachain_config: &Configuration,330	telemetry_worker_handle: Option<TelemetryWorkerHandle>,331	task_manager: &mut TaskManager,332	collator_options: CollatorOptions,333	hwbench: Option<sc_sysinfo::HwBench>,334) -> RelayChainResult<(335	Arc<(dyn RelayChainInterface + 'static)>,336	Option<CollatorPair>,337)> {338	match collator_options.relay_chain_rpc_url {339		Some(relay_chain_url) => {340			build_minimal_relay_chain_node(polkadot_config, task_manager, relay_chain_url).await341		}342		None => build_inprocess_relay_chain(343			polkadot_config,344			parachain_config,345			telemetry_worker_handle,346			task_manager,347			hwbench,348		),349	}350}351352/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.353///354/// This is the actual implementation that is abstract over the executor and the runtime api.355#[sc_tracing::logging::prefix_logs_with("Parachain")]356async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(357	parachain_config: Configuration,358	polkadot_config: Configuration,359	collator_options: CollatorOptions,360	id: ParaId,361	build_import_queue: BIQ,362	build_consensus: BIC,363	hwbench: Option<sc_sysinfo::HwBench>,364) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>365where366	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,367	Runtime: RuntimeInstance + Send + Sync + 'static,368	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,369	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,370	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>371		+ Send372		+ Sync373		+ 'static,374	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>375		+ fp_rpc::EthereumRuntimeRPCApi<Block>376		+ fp_rpc::ConvertTransactionRuntimeApi<Block>377		+ sp_session::SessionKeys<Block>378		+ sp_block_builder::BlockBuilder<Block>379		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>380		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>381		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>382		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>383		+ rmrk_rpc::RmrkApi<384			Block,385			AccountId,386			RmrkCollectionInfo<AccountId>,387			RmrkInstanceInfo<AccountId>,388			RmrkResourceInfo,389			RmrkPropertyInfo,390			RmrkBaseInfo<AccountId>,391			RmrkPartType,392			RmrkTheme,393		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>394		+ sp_api::Metadata<Block>395		+ sp_offchain::OffchainWorkerApi<Block>396		+ cumulus_primitives_core::CollectCollationInfo<Block>,397	ExecutorDispatch: NativeExecutionDispatch + 'static,398	BIQ: FnOnce(399		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,400		&Configuration,401		Option<TelemetryHandle>,402		&TaskManager,403	) -> Result<404		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,405		sc_service::Error,406	>,407	BIC: FnOnce(408		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,409		Option<&Registry>,410		Option<TelemetryHandle>,411		&TaskManager,412		Arc<dyn RelayChainInterface>,413		Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,414		Arc<NetworkService<Block, Hash>>,415		SyncCryptoStorePtr,416		bool,417	) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,418{419	let parachain_config = prepare_node_config(parachain_config);420421	let params =422		new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;423	let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =424		params.other;425426	let client = params.client.clone();427	let backend = params.backend.clone();428	let mut task_manager = params.task_manager;429430	let (relay_chain_interface, collator_key) = build_relay_chain_interface(431		polkadot_config,432		&parachain_config,433		telemetry_worker_handle,434		&mut task_manager,435		collator_options.clone(),436		hwbench.clone(),437	)438	.await439	.map_err(|e| match e {440		RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,441		s => s.to_string().into(),442	})?;443444	let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);445446	let force_authoring = parachain_config.force_authoring;447	let validator = parachain_config.role.is_authority();448	let prometheus_registry = parachain_config.prometheus_registry().cloned();449	let transaction_pool = params.transaction_pool.clone();450	let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);451452	let (network, system_rpc_tx, tx_handler_controller, start_network) =453		sc_service::build_network(sc_service::BuildNetworkParams {454			config: &parachain_config,455			client: client.clone(),456			transaction_pool: transaction_pool.clone(),457			spawn_handle: task_manager.spawn_handle(),458			import_queue: import_queue.clone(),459			block_announce_validator_builder: Some(Box::new(|_| {460				Box::new(block_announce_validator)461			})),462			warp_sync: None,463		})?;464465	let rpc_client = client.clone();466	let rpc_pool = transaction_pool.clone();467	let select_chain = params.select_chain.clone();468	let rpc_network = network.clone();469470	let rpc_frontier_backend = frontier_backend.clone();471472	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(473		task_manager.spawn_handle(),474		overrides_handle::<_, _, Runtime>(client.clone()),475		50,476		50,477		prometheus_registry.clone(),478	));479480	task_manager.spawn_essential_handle().spawn(481		"frontier-mapping-sync-worker",482		None,483		MappingSyncWorker::new(484			client.import_notification_stream(),485			Duration::new(6, 0),486			client.clone(),487			backend.clone(),488			frontier_backend.clone(),489			3,490			0,491			SyncStrategy::Normal,492		)493		.for_each(|()| futures::future::ready(())),494	);495496	let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {497		let full_deps = unique_rpc::FullDeps {498			backend: rpc_frontier_backend.clone(),499			deny_unsafe,500			client: rpc_client.clone(),501			pool: rpc_pool.clone(),502			graph: rpc_pool.pool().clone(),503			// TODO: Unhardcode504			enable_dev_signer: false,505			filter_pool: filter_pool.clone(),506			network: rpc_network.clone(),507			select_chain: select_chain.clone(),508			is_authority: validator,509			// TODO: Unhardcode510			max_past_logs: 10000,511			block_data_cache: block_data_cache.clone(),512			fee_history_cache: fee_history_cache.clone(),513			// TODO: Unhardcode514			fee_history_limit: 2048,515		};516517		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(518			full_deps,519			subscription_task_executor,520		)521		.map_err(Into::into)522	});523524	sc_service::spawn_tasks(sc_service::SpawnTasksParams {525		rpc_builder,526		client: client.clone(),527		transaction_pool: transaction_pool.clone(),528		task_manager: &mut task_manager,529		config: parachain_config,530		keystore: params.keystore_container.sync_keystore(),531		backend: backend.clone(),532		network: network.clone(),533		system_rpc_tx,534		telemetry: telemetry.as_mut(),535		tx_handler_controller,536	})?;537538	if let Some(hwbench) = hwbench {539		sc_sysinfo::print_hwbench(&hwbench);540541		if let Some(ref mut telemetry) = telemetry {542			let telemetry_handle = telemetry.handle();543			task_manager.spawn_handle().spawn(544				"telemetry_hwbench",545				None,546				sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),547			);548		}549	}550551	let announce_block = {552		let network = network.clone();553		Arc::new(Box::new(move |hash, data| {554			network.announce_block(hash, data)555		}))556	};557558	let relay_chain_slot_duration = Duration::from_secs(6);559560	if validator {561		let parachain_consensus = build_consensus(562			client.clone(),563			prometheus_registry.as_ref(),564			telemetry.as_ref().map(|t| t.handle()),565			&task_manager,566			relay_chain_interface.clone(),567			transaction_pool,568			network,569			params.keystore_container.sync_keystore(),570			force_authoring,571		)?;572573		let spawner = task_manager.spawn_handle();574575		let params = StartCollatorParams {576			para_id: id,577			block_status: client.clone(),578			announce_block,579			client: client.clone(),580			task_manager: &mut task_manager,581			spawner,582			parachain_consensus,583			import_queue,584			collator_key: collator_key.expect("Command line arguments do not allow this. qed"),585			relay_chain_interface,586			relay_chain_slot_duration,587		};588589		start_collator(params).await?;590	} else {591		let params = StartFullNodeParams {592			client: client.clone(),593			announce_block,594			task_manager: &mut task_manager,595			para_id: id,596			import_queue,597			relay_chain_interface,598			relay_chain_slot_duration,599		};600601		start_full_node(params)?;602	}603604	start_network.start_network();605606	Ok((task_manager, client))607}608609/// Build the import queue for the the parachain runtime.610pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(611	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,612	config: &Configuration,613	telemetry: Option<TelemetryHandle>,614	task_manager: &TaskManager,615) -> Result<616	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,617	sc_service::Error,618>619where620	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>621		+ Send622		+ Sync623		+ 'static,624	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>625		+ sp_block_builder::BlockBuilder<Block>626		+ sp_consensus_aura::AuraApi<Block, AuraId>627		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,628	ExecutorDispatch: NativeExecutionDispatch + 'static,629{630	let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;631632	let block_import = ParachainBlockImport::new(client.clone());633634	cumulus_client_consensus_aura::import_queue::<635		sp_consensus_aura::sr25519::AuthorityPair,636		_,637		_,638		_,639		_,640		_,641	>(cumulus_client_consensus_aura::ImportQueueParams {642		block_import,643		client: client.clone(),644		create_inherent_data_providers: move |_, _| async move {645			let time = sp_timestamp::InherentDataProvider::from_system_time();646647			let slot =648				sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(649					*time,650					slot_duration,651				);652653			Ok((slot, time))654		},655		registry: config.prometheus_registry(),656		spawner: &task_manager.spawn_essential_handle(),657		telemetry,658	})659	.map_err(Into::into)660}661662/// Start a normal parachain node.663pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(664	parachain_config: Configuration,665	polkadot_config: Configuration,666	collator_options: CollatorOptions,667	id: ParaId,668	hwbench: Option<sc_sysinfo::HwBench>,669) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>670where671	Runtime: RuntimeInstance + Send + Sync + 'static,672	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,673	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,674	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>675		+ Send676		+ Sync677		+ 'static,678	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>679		+ fp_rpc::EthereumRuntimeRPCApi<Block>680		+ fp_rpc::ConvertTransactionRuntimeApi<Block>681		+ sp_session::SessionKeys<Block>682		+ sp_block_builder::BlockBuilder<Block>683		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>684		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>685		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>686		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>687		+ rmrk_rpc::RmrkApi<688			Block,689			AccountId,690			RmrkCollectionInfo<AccountId>,691			RmrkInstanceInfo<AccountId>,692			RmrkResourceInfo,693			RmrkPropertyInfo,694			RmrkBaseInfo<AccountId>,695			RmrkPartType,696			RmrkTheme,697		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>698		+ sp_api::Metadata<Block>699		+ sp_offchain::OffchainWorkerApi<Block>700		+ cumulus_primitives_core::CollectCollationInfo<Block>701		+ sp_consensus_aura::AuraApi<Block, AuraId>,702	ExecutorDispatch: NativeExecutionDispatch + 'static,703{704	start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(705		parachain_config,706		polkadot_config,707		collator_options,708		id,709		parachain_build_import_queue,710		|client,711		 prometheus_registry,712		 telemetry,713		 task_manager,714		 relay_chain_interface,715		 transaction_pool,716		 sync_oracle,717		 keystore,718		 force_authoring| {719			let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;720721			let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(722				task_manager.spawn_handle(),723				client.clone(),724				transaction_pool,725				prometheus_registry,726				telemetry.clone(),727			);728729			let block_import = ParachainBlockImport::new(client.clone());730731			Ok(AuraConsensus::build::<732				sp_consensus_aura::sr25519::AuthorityPair,733				_,734				_,735				_,736				_,737				_,738				_,739			>(BuildAuraConsensusParams {740				proposer_factory,741				create_inherent_data_providers: move |_, (relay_parent, validation_data)| {742					let relay_chain_interface = relay_chain_interface.clone();743					async move {744						let parachain_inherent =745						cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(746							relay_parent,747							&relay_chain_interface,748							&validation_data,749							id,750						).await;751752						let time = sp_timestamp::InherentDataProvider::from_system_time();753754						let slot =755						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(756							*time,757							slot_duration,758						);759760						let parachain_inherent = parachain_inherent.ok_or_else(|| {761							Box::<dyn std::error::Error + Send + Sync>::from(762								"Failed to create parachain inherent",763							)764						})?;765						Ok((slot, time, parachain_inherent))766					}767				},768				block_import,769				para_client: client,770				backoff_authoring_blocks: Option::<()>::None,771				sync_oracle,772				keystore,773				force_authoring,774				slot_duration,775				// We got around 500ms for proposing776				block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),777				telemetry,778				max_block_proposal_slot_portion: None,779			}))780		},781		hwbench,782	)783	.await784}785786fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(787	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,788	config: &Configuration,789	_: Option<TelemetryHandle>,790	task_manager: &TaskManager,791) -> Result<792	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,793	sc_service::Error,794>795where796	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>797		+ Send798		+ Sync799		+ 'static,800	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>801		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,802	ExecutorDispatch: NativeExecutionDispatch + 'static,803{804	Ok(sc_consensus_manual_seal::import_queue(805		Box::new(client.clone()),806		&task_manager.spawn_essential_handle(),807		config.prometheus_registry(),808	))809}810811/// Builds a new development service. This service uses instant seal, and mocks812/// the parachain inherent813pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(814	config: Configuration,815	autoseal_interval: Duration,816) -> sc_service::error::Result<TaskManager>817where818	Runtime: RuntimeInstance + Send + Sync + 'static,819	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,820	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,821	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>822		+ Send823		+ Sync824		+ 'static,825	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>826		+ fp_rpc::EthereumRuntimeRPCApi<Block>827		+ fp_rpc::ConvertTransactionRuntimeApi<Block>828		+ sp_session::SessionKeys<Block>829		+ sp_block_builder::BlockBuilder<Block>830		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>831		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>832		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>833		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>834		+ rmrk_rpc::RmrkApi<835			Block,836			AccountId,837			RmrkCollectionInfo<AccountId>,838			RmrkInstanceInfo<AccountId>,839			RmrkResourceInfo,840			RmrkPropertyInfo,841			RmrkBaseInfo<AccountId>,842			RmrkPartType,843			RmrkTheme,844		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>845		+ sp_api::Metadata<Block>846		+ sp_offchain::OffchainWorkerApi<Block>847		+ cumulus_primitives_core::CollectCollationInfo<Block>848		+ sp_consensus_aura::AuraApi<Block, AuraId>,849	ExecutorDispatch: NativeExecutionDispatch + 'static,850{851	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};852	use fc_consensus::FrontierBlockImport;853	use sc_client_api::HeaderBackend;854855	let sc_service::PartialComponents {856		client,857		backend,858		mut task_manager,859		import_queue,860		keystore_container,861		select_chain: maybe_select_chain,862		transaction_pool,863		other:864			(telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),865	} = new_partial::<RuntimeApi, ExecutorDispatch, _>(866		&config,867		dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,868	)?;869	let prometheus_registry = config.prometheus_registry().cloned();870871	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(872		task_manager.spawn_handle(),873		overrides_handle::<_, _, Runtime>(client.clone()),874		50,875		50,876		prometheus_registry.clone(),877	));878879	let (network, system_rpc_tx, tx_handler_controller, network_starter) =880		sc_service::build_network(sc_service::BuildNetworkParams {881			config: &config,882			client: client.clone(),883			transaction_pool: transaction_pool.clone(),884			spawn_handle: task_manager.spawn_handle(),885			import_queue,886			block_announce_validator_builder: None,887			warp_sync: None,888		})?;889890	if config.offchain_worker.enabled {891		sc_service::build_offchain_workers(892			&config,893			task_manager.spawn_handle(),894			client.clone(),895			network.clone(),896		);897	}898899	let collator = config.role.is_authority();900901	let select_chain = maybe_select_chain.clone();902903	if collator {904		let block_import =905			FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());906907		let env = sc_basic_authorship::ProposerFactory::new(908			task_manager.spawn_handle(),909			client.clone(),910			transaction_pool.clone(),911			prometheus_registry.as_ref(),912			telemetry.as_ref().map(|x| x.handle()),913		);914915		let transactions_commands_stream: Box<916			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,917		> = Box::new(918			transaction_pool919				.pool()920				.validated_pool()921				.import_notification_stream()922				.map(|_| EngineCommand::SealNewBlock {923					create_empty: true,924					finalize: false,925					parent_hash: None,926					sender: None,927				}),928		);929930		let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));931		let idle_commands_stream: Box<932			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,933		> = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {934			create_empty: true,935			finalize: false,936			parent_hash: None,937			sender: None,938		}));939940		let commands_stream = select(transactions_commands_stream, idle_commands_stream);941942		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;943		let client_set_aside_for_cidp = client.clone();944945		task_manager.spawn_essential_handle().spawn_blocking(946			"authorship_task",947			Some("block-authoring"),948			run_manual_seal(ManualSealParams {949				block_import,950				env,951				client: client.clone(),952				pool: transaction_pool.clone(),953				commands_stream,954				select_chain: select_chain.clone(),955				consensus_data_provider: None,956				create_inherent_data_providers: move |block: Hash, ()| {957					let current_para_block = client_set_aside_for_cidp958						.number(block)959						.expect("Header lookup should succeed")960						.expect("Header passed in as parent should be present in backend.");961962					let client_for_xcm = client_set_aside_for_cidp.clone();963					async move {964						let time = sp_timestamp::InherentDataProvider::from_system_time();965966						let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {967							current_para_block,968							relay_offset: 1000,969							relay_blocks_per_para_block: 2,970							para_blocks_per_relay_epoch: 0,971							xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(972								&*client_for_xcm,973								block,974								Default::default(),975								Default::default(),976							),977							relay_randomness_config: (),978							raw_downward_messages: vec![],979							raw_horizontal_messages: vec![],980						};981982						let slot =983						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(984							*time,985							slot_duration,986						);987988						Ok((time, slot, mocked_parachain))989					}990				},991			}),992		);993	}994995	task_manager.spawn_essential_handle().spawn(996		"frontier-mapping-sync-worker",997		Some("block-authoring"),998		MappingSyncWorker::new(999			client.import_notification_stream(),1000			Duration::new(6, 0),1001			client.clone(),1002			backend.clone(),1003			frontier_backend.clone(),1004			3,1005			0,1006			SyncStrategy::Normal,1007		)1008		.for_each(|()| futures::future::ready(())),1009	);10101011	let rpc_client = client.clone();1012	let rpc_pool = transaction_pool.clone();1013	let rpc_network = network.clone();1014	let rpc_frontier_backend = frontier_backend.clone();1015	let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1016		let full_deps = unique_rpc::FullDeps {1017			backend: rpc_frontier_backend.clone(),1018			deny_unsafe,1019			client: rpc_client.clone(),1020			pool: rpc_pool.clone(),1021			graph: rpc_pool.pool().clone(),1022			// TODO: Unhardcode1023			enable_dev_signer: false,1024			filter_pool: filter_pool.clone(),1025			network: rpc_network.clone(),1026			select_chain: select_chain.clone(),1027			is_authority: collator,1028			// TODO: Unhardcode1029			max_past_logs: 10000,1030			block_data_cache: block_data_cache.clone(),1031			fee_history_cache: fee_history_cache.clone(),1032			// TODO: Unhardcode1033			fee_history_limit: 2048,1034		};10351036		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1037			full_deps,1038			subscription_executor,1039		)1040		.map_err(Into::into)1041	});10421043	sc_service::spawn_tasks(sc_service::SpawnTasksParams {1044		network,1045		client,1046		keystore: keystore_container.sync_keystore(),1047		task_manager: &mut task_manager,1048		transaction_pool,1049		rpc_builder,1050		backend,1051		system_rpc_tx,1052		config,1053		telemetry: None,1054		tx_handler_controller,1055	})?;10561057	network_starter.start_network();1058	Ok(task_manager)1059}
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 std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25	Stream, StreamExt,26	stream::select,27	task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38	ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41	prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;6162use polkadot_service::CollatorPair;6364// Frontier Imports65use fc_rpc_core::types::FilterPool;66use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6768use up_common::types::opaque::{69	AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block, BlockNumber,70};7172// RMRK73use up_data_structs::{74	RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,75	RmrkPartType, RmrkTheme,76};7778/// Unique native executor instance.79#[cfg(feature = "unique-runtime")]80pub struct UniqueRuntimeExecutor;8182#[cfg(feature = "quartz-runtime")]83/// Quartz native executor instance.84pub struct QuartzRuntimeExecutor;8586/// Opal native executor instance.87pub struct OpalRuntimeExecutor;8889#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]90pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;9192#[cfg(all(93	not(feature = "unique-runtime"),94	feature = "quartz-runtime",95	feature = "runtime-benchmarks"96))]97pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9899#[cfg(all(100	not(feature = "unique-runtime"),101	not(feature = "quartz-runtime"),102	feature = "runtime-benchmarks"103))]104pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;105106#[cfg(feature = "unique-runtime")]107impl NativeExecutionDispatch for UniqueRuntimeExecutor {108	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;109110	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {111		unique_runtime::api::dispatch(method, data)112	}113114	fn native_version() -> sc_executor::NativeVersion {115		unique_runtime::native_version()116	}117}118119#[cfg(feature = "quartz-runtime")]120impl NativeExecutionDispatch for QuartzRuntimeExecutor {121	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;122123	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {124		quartz_runtime::api::dispatch(method, data)125	}126127	fn native_version() -> sc_executor::NativeVersion {128		quartz_runtime::native_version()129	}130}131132impl NativeExecutionDispatch for OpalRuntimeExecutor {133	type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;134135	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {136		opal_runtime::api::dispatch(method, data)137	}138139	fn native_version() -> sc_executor::NativeVersion {140		opal_runtime::native_version()141	}142}143144pub struct AutosealInterval {145	interval: Interval,146}147148impl AutosealInterval {149	pub fn new(config: &Configuration, interval: Duration) -> Self {150		let _tokio_runtime = config.tokio_handle.enter();151		let interval = tokio::time::interval(interval);152153		Self { interval }154	}155}156157impl Stream for AutosealInterval {158	type Item = tokio::time::Instant;159160	fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {161		self.interval.poll_tick(cx).map(Some)162	}163}164165pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(166	client: Arc<C>,167	config: &Configuration,168) -> Result<Arc<fc_db::Backend<Block>>, String> {169	let config_dir = config170		.base_path171		.as_ref()172		.map(|base_path| base_path.config_dir(config.chain_spec.id()))173		.unwrap_or_else(|| {174			BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())175		});176	let database_dir = config_dir.join("frontier").join("db");177178	Ok(Arc::new(fc_db::Backend::<Block>::new(179		client,180		&fc_db::DatabaseSettings {181			source: fc_db::DatabaseSource::RocksDb {182				path: database_dir,183				cache_size: 0,184			},185		},186	)?))187}188189type FullClient<RuntimeApi, ExecutorDispatch> =190	sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;191type FullBackend = sc_service::TFullBackend<Block>;192type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;193type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =194	TParachainBlockImport<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>;195196/// Starts a `ServiceBuilder` for a full service.197///198/// Use this macro if you don't actually need the full service, but just the builder in order to199/// be able to perform chain operations.200#[allow(clippy::type_complexity)]201pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(202	config: &Configuration,203	build_import_queue: BIQ,204) -> Result<205	PartialComponents<206		FullClient<RuntimeApi, ExecutorDispatch>,207		FullBackend,208		FullSelectChain,209		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,210		sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,211		(212			Option<Telemetry>,213			Option<FilterPool>,214			Arc<fc_db::Backend<Block>>,215			Option<TelemetryWorkerHandle>,216			FeeHistoryCache,217		),218	>,219	sc_service::Error,220>221where222	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,223	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>224		+ Send225		+ Sync226		+ 'static,227	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,228	ExecutorDispatch: NativeExecutionDispatch + 'static,229	BIQ: FnOnce(230		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,231		&Configuration,232		Option<TelemetryHandle>,233		&TaskManager,234	) -> Result<235		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,236		sc_service::Error,237	>,238{239	let _telemetry = config240		.telemetry_endpoints241		.clone()242		.filter(|x| !x.is_empty())243		.map(|endpoints| -> Result<_, sc_telemetry::Error> {244			let worker = TelemetryWorker::new(16)?;245			let telemetry = worker.handle().new_telemetry(endpoints);246			Ok((worker, telemetry))247		})248		.transpose()?;249250	let telemetry = config251		.telemetry_endpoints252		.clone()253		.filter(|x| !x.is_empty())254		.map(|endpoints| -> Result<_, sc_telemetry::Error> {255			let worker = TelemetryWorker::new(16)?;256			let telemetry = worker.handle().new_telemetry(endpoints);257			Ok((worker, telemetry))258		})259		.transpose()?;260261	let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(262		config.wasm_method,263		config.default_heap_pages,264		config.max_runtime_instances,265		config.runtime_cache_size,266	);267268	let (client, backend, keystore_container, task_manager) =269		sc_service::new_full_parts::<Block, RuntimeApi, _>(270			config,271			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),272			executor,273		)?;274	let client = Arc::new(client);275276	let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());277278	let telemetry = telemetry.map(|(worker, telemetry)| {279		task_manager280			.spawn_handle()281			.spawn("telemetry", None, worker.run());282		telemetry283	});284285	let select_chain = sc_consensus::LongestChain::new(backend.clone());286287	let transaction_pool = sc_transaction_pool::BasicPool::new_full(288		config.transaction_pool.clone(),289		config.role.is_authority().into(),290		config.prometheus_registry(),291		task_manager.spawn_essential_handle(),292		client.clone(),293	);294295	let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));296297	let frontier_backend = open_frontier_backend(client.clone(), config)?;298299	let import_queue = build_import_queue(300		client.clone(),301		config,302		telemetry.as_ref().map(|telemetry| telemetry.handle()),303		&task_manager,304	)?;305	let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));306307	let params = PartialComponents {308		backend,309		client,310		import_queue,311		keystore_container,312		task_manager,313		transaction_pool,314		select_chain,315		other: (316			telemetry,317			filter_pool,318			frontier_backend,319			telemetry_worker_handle,320			fee_history_cache,321		),322	};323324	Ok(params)325}326327async fn build_relay_chain_interface(328	polkadot_config: Configuration,329	parachain_config: &Configuration,330	telemetry_worker_handle: Option<TelemetryWorkerHandle>,331	task_manager: &mut TaskManager,332	collator_options: CollatorOptions,333	hwbench: Option<sc_sysinfo::HwBench>,334) -> RelayChainResult<(335	Arc<(dyn RelayChainInterface + 'static)>,336	Option<CollatorPair>,337)> {338	match collator_options.relay_chain_rpc_url {339		Some(relay_chain_url) => {340			build_minimal_relay_chain_node(polkadot_config, task_manager, relay_chain_url).await341		}342		None => build_inprocess_relay_chain(343			polkadot_config,344			parachain_config,345			telemetry_worker_handle,346			task_manager,347			hwbench,348		),349	}350}351352/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.353///354/// This is the actual implementation that is abstract over the executor and the runtime api.355#[sc_tracing::logging::prefix_logs_with("Parachain")]356async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(357	parachain_config: Configuration,358	polkadot_config: Configuration,359	collator_options: CollatorOptions,360	id: ParaId,361	build_import_queue: BIQ,362	build_consensus: BIC,363	hwbench: Option<sc_sysinfo::HwBench>,364) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>365where366	sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,367	Runtime: RuntimeInstance + Send + Sync + 'static,368	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,369	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,370	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>371		+ Send372		+ Sync373		+ 'static,374	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>375		+ fp_rpc::EthereumRuntimeRPCApi<Block>376		+ fp_rpc::ConvertTransactionRuntimeApi<Block>377		+ sp_session::SessionKeys<Block>378		+ sp_block_builder::BlockBuilder<Block>379		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>380		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>381		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>382		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>383		+ rmrk_rpc::RmrkApi<384			Block,385			AccountId,386			RmrkCollectionInfo<AccountId>,387			RmrkInstanceInfo<AccountId>,388			RmrkResourceInfo,389			RmrkPropertyInfo,390			RmrkBaseInfo<AccountId>,391			RmrkPartType,392			RmrkTheme,393		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>394		+ sp_api::Metadata<Block>395		+ sp_offchain::OffchainWorkerApi<Block>396		+ cumulus_primitives_core::CollectCollationInfo<Block>,397	ExecutorDispatch: NativeExecutionDispatch + 'static,398	BIQ: FnOnce(399		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,400		&Configuration,401		Option<TelemetryHandle>,402		&TaskManager,403	) -> Result<404		sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,405		sc_service::Error,406	>,407	BIC: FnOnce(408		Arc<FullClient<RuntimeApi, ExecutorDispatch>>,409		Option<&Registry>,410		Option<TelemetryHandle>,411		&TaskManager,412		Arc<dyn RelayChainInterface>,413		Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,414		Arc<NetworkService<Block, Hash>>,415		SyncCryptoStorePtr,416		bool,417	) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,418{419	let parachain_config = prepare_node_config(parachain_config);420421	let params =422		new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(&parachain_config, build_import_queue)?;423	let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =424		params.other;425426	let client = params.client.clone();427	let backend = params.backend.clone();428	let mut task_manager = params.task_manager;429430	let (relay_chain_interface, collator_key) = build_relay_chain_interface(431		polkadot_config,432		&parachain_config,433		telemetry_worker_handle,434		&mut task_manager,435		collator_options.clone(),436		hwbench.clone(),437	)438	.await439	.map_err(|e| match e {440		RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,441		s => s.to_string().into(),442	})?;443444	let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);445446	let force_authoring = parachain_config.force_authoring;447	let validator = parachain_config.role.is_authority();448	let prometheus_registry = parachain_config.prometheus_registry().cloned();449	let transaction_pool = params.transaction_pool.clone();450	let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue);451452	let (network, system_rpc_tx, tx_handler_controller, start_network) =453		sc_service::build_network(sc_service::BuildNetworkParams {454			config: &parachain_config,455			client: client.clone(),456			transaction_pool: transaction_pool.clone(),457			spawn_handle: task_manager.spawn_handle(),458			import_queue: import_queue.clone(),459			block_announce_validator_builder: Some(Box::new(|_| {460				Box::new(block_announce_validator)461			})),462			warp_sync: None,463		})?;464465	let rpc_client = client.clone();466	let rpc_pool = transaction_pool.clone();467	let select_chain = params.select_chain.clone();468	let rpc_network = network.clone();469470	let rpc_frontier_backend = frontier_backend.clone();471472	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(473		task_manager.spawn_handle(),474		overrides_handle::<_, _, Runtime>(client.clone()),475		50,476		50,477		prometheus_registry.clone(),478	));479480	task_manager.spawn_essential_handle().spawn(481		"frontier-mapping-sync-worker",482		None,483		MappingSyncWorker::new(484			client.import_notification_stream(),485			Duration::new(6, 0),486			client.clone(),487			backend.clone(),488			frontier_backend.clone(),489			3,490			0,491			SyncStrategy::Normal,492		)493		.for_each(|()| futures::future::ready(())),494	);495496	let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {497		let full_deps = unique_rpc::FullDeps {498			backend: rpc_frontier_backend.clone(),499			deny_unsafe,500			client: rpc_client.clone(),501			pool: rpc_pool.clone(),502			graph: rpc_pool.pool().clone(),503			// TODO: Unhardcode504			enable_dev_signer: false,505			filter_pool: filter_pool.clone(),506			network: rpc_network.clone(),507			select_chain: select_chain.clone(),508			is_authority: validator,509			// TODO: Unhardcode510			max_past_logs: 10000,511			block_data_cache: block_data_cache.clone(),512			fee_history_cache: fee_history_cache.clone(),513			// TODO: Unhardcode514			fee_history_limit: 2048,515		};516517		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(518			full_deps,519			subscription_task_executor,520		)521		.map_err(Into::into)522	});523524	sc_service::spawn_tasks(sc_service::SpawnTasksParams {525		rpc_builder,526		client: client.clone(),527		transaction_pool: transaction_pool.clone(),528		task_manager: &mut task_manager,529		config: parachain_config,530		keystore: params.keystore_container.sync_keystore(),531		backend: backend.clone(),532		network: network.clone(),533		system_rpc_tx,534		telemetry: telemetry.as_mut(),535		tx_handler_controller,536	})?;537538	if let Some(hwbench) = hwbench {539		sc_sysinfo::print_hwbench(&hwbench);540541		if let Some(ref mut telemetry) = telemetry {542			let telemetry_handle = telemetry.handle();543			task_manager.spawn_handle().spawn(544				"telemetry_hwbench",545				None,546				sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),547			);548		}549	}550551	let announce_block = {552		let network = network.clone();553		Arc::new(Box::new(move |hash, data| {554			network.announce_block(hash, data)555		}))556	};557558	let relay_chain_slot_duration = Duration::from_secs(6);559560	if validator {561		let parachain_consensus = build_consensus(562			client.clone(),563			prometheus_registry.as_ref(),564			telemetry.as_ref().map(|t| t.handle()),565			&task_manager,566			relay_chain_interface.clone(),567			transaction_pool,568			network,569			params.keystore_container.sync_keystore(),570			force_authoring,571		)?;572573		let spawner = task_manager.spawn_handle();574575		let params = StartCollatorParams {576			para_id: id,577			block_status: client.clone(),578			announce_block,579			client: client.clone(),580			task_manager: &mut task_manager,581			spawner,582			parachain_consensus,583			import_queue,584			collator_key: collator_key.expect("Command line arguments do not allow this. qed"),585			relay_chain_interface,586			relay_chain_slot_duration,587		};588589		start_collator(params).await?;590	} else {591		let params = StartFullNodeParams {592			client: client.clone(),593			announce_block,594			task_manager: &mut task_manager,595			para_id: id,596			import_queue,597			relay_chain_interface,598			relay_chain_slot_duration,599		};600601		start_full_node(params)?;602	}603604	start_network.start_network();605606	Ok((task_manager, client))607}608609/// Build the import queue for the the parachain runtime.610pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(611	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,612	config: &Configuration,613	telemetry: Option<TelemetryHandle>,614	task_manager: &TaskManager,615) -> Result<616	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,617	sc_service::Error,618>619where620	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>621		+ Send622		+ Sync623		+ 'static,624	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>625		+ sp_block_builder::BlockBuilder<Block>626		+ sp_consensus_aura::AuraApi<Block, AuraId>627		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,628	ExecutorDispatch: NativeExecutionDispatch + 'static,629{630	let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;631632	let block_import = ParachainBlockImport::new(client.clone());633634	cumulus_client_consensus_aura::import_queue::<635		sp_consensus_aura::sr25519::AuthorityPair,636		_,637		_,638		_,639		_,640		_,641	>(cumulus_client_consensus_aura::ImportQueueParams {642		block_import,643		client: client.clone(),644		create_inherent_data_providers: move |_, _| async move {645			let time = sp_timestamp::InherentDataProvider::from_system_time();646647			let slot =648				sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(649					*time,650					slot_duration,651				);652653			Ok((slot, time))654		},655		registry: config.prometheus_registry(),656		spawner: &task_manager.spawn_essential_handle(),657		telemetry,658	})659	.map_err(Into::into)660}661662/// Start a normal parachain node.663pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(664	parachain_config: Configuration,665	polkadot_config: Configuration,666	collator_options: CollatorOptions,667	id: ParaId,668	hwbench: Option<sc_sysinfo::HwBench>,669) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>670where671	Runtime: RuntimeInstance + Send + Sync + 'static,672	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,673	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,674	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>675		+ Send676		+ Sync677		+ 'static,678	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>679		+ fp_rpc::EthereumRuntimeRPCApi<Block>680		+ fp_rpc::ConvertTransactionRuntimeApi<Block>681		+ sp_session::SessionKeys<Block>682		+ sp_block_builder::BlockBuilder<Block>683		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>684		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>685		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>686		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>687		+ rmrk_rpc::RmrkApi<688			Block,689			AccountId,690			RmrkCollectionInfo<AccountId>,691			RmrkInstanceInfo<AccountId>,692			RmrkResourceInfo,693			RmrkPropertyInfo,694			RmrkBaseInfo<AccountId>,695			RmrkPartType,696			RmrkTheme,697		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>698		+ sp_api::Metadata<Block>699		+ sp_offchain::OffchainWorkerApi<Block>700		+ cumulus_primitives_core::CollectCollationInfo<Block>701		+ sp_consensus_aura::AuraApi<Block, AuraId>,702	ExecutorDispatch: NativeExecutionDispatch + 'static,703{704	start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(705		parachain_config,706		polkadot_config,707		collator_options,708		id,709		parachain_build_import_queue,710		|client,711		 prometheus_registry,712		 telemetry,713		 task_manager,714		 relay_chain_interface,715		 transaction_pool,716		 sync_oracle,717		 keystore,718		 force_authoring| {719			let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;720721			let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(722				task_manager.spawn_handle(),723				client.clone(),724				transaction_pool,725				prometheus_registry,726				telemetry.clone(),727			);728729			let block_import = ParachainBlockImport::new(client.clone());730731			Ok(AuraConsensus::build::<732				sp_consensus_aura::sr25519::AuthorityPair,733				_,734				_,735				_,736				_,737				_,738				_,739			>(BuildAuraConsensusParams {740				proposer_factory,741				create_inherent_data_providers: move |_, (relay_parent, validation_data)| {742					let relay_chain_interface = relay_chain_interface.clone();743					async move {744						let parachain_inherent =745						cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(746							relay_parent,747							&relay_chain_interface,748							&validation_data,749							id,750						).await;751752						let time = sp_timestamp::InherentDataProvider::from_system_time();753754						let slot =755						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(756							*time,757							slot_duration,758						);759760						let parachain_inherent = parachain_inherent.ok_or_else(|| {761							Box::<dyn std::error::Error + Send + Sync>::from(762								"Failed to create parachain inherent",763							)764						})?;765						Ok((slot, time, parachain_inherent))766					}767				},768				block_import,769				para_client: client,770				backoff_authoring_blocks: Option::<()>::None,771				sync_oracle,772				keystore,773				force_authoring,774				slot_duration,775				// We got around 500ms for proposing776				block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),777				telemetry,778				max_block_proposal_slot_portion: None,779			}))780		},781		hwbench,782	)783	.await784}785786fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(787	client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,788	config: &Configuration,789	_: Option<TelemetryHandle>,790	task_manager: &TaskManager,791) -> Result<792	sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,793	sc_service::Error,794>795where796	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>797		+ Send798		+ Sync799		+ 'static,800	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>801		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,802	ExecutorDispatch: NativeExecutionDispatch + 'static,803{804	Ok(sc_consensus_manual_seal::import_queue(805		Box::new(client.clone()),806		&task_manager.spawn_essential_handle(),807		config.prometheus_registry(),808	))809}810811/// Builds a new development service. This service uses instant seal, and mocks812/// the parachain inherent813pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(814	config: Configuration,815	autoseal_interval: Duration,816) -> sc_service::error::Result<TaskManager>817where818	Runtime: RuntimeInstance + Send + Sync + 'static,819	<Runtime as RuntimeInstance>::CrossAccountId: Serialize,820	for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,821	RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>822		+ Send823		+ Sync824		+ 'static,825	RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>826		+ fp_rpc::EthereumRuntimeRPCApi<Block>827		+ fp_rpc::ConvertTransactionRuntimeApi<Block>828		+ sp_session::SessionKeys<Block>829		+ sp_block_builder::BlockBuilder<Block>830		+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>831		+ sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>832		+ up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>833		+ app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>834		+ rmrk_rpc::RmrkApi<835			Block,836			AccountId,837			RmrkCollectionInfo<AccountId>,838			RmrkInstanceInfo<AccountId>,839			RmrkResourceInfo,840			RmrkPropertyInfo,841			RmrkBaseInfo<AccountId>,842			RmrkPartType,843			RmrkTheme,844		> + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>845		+ sp_api::Metadata<Block>846		+ sp_offchain::OffchainWorkerApi<Block>847		+ cumulus_primitives_core::CollectCollationInfo<Block>848		+ sp_consensus_aura::AuraApi<Block, AuraId>,849	ExecutorDispatch: NativeExecutionDispatch + 'static,850{851	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};852	use fc_consensus::FrontierBlockImport;853	use sc_client_api::HeaderBackend;854855	let sc_service::PartialComponents {856		client,857		backend,858		mut task_manager,859		import_queue,860		keystore_container,861		select_chain: maybe_select_chain,862		transaction_pool,863		other:864			(telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),865	} = new_partial::<RuntimeApi, ExecutorDispatch, _>(866		&config,867		dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,868	)?;869	let prometheus_registry = config.prometheus_registry().cloned();870871	let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(872		task_manager.spawn_handle(),873		overrides_handle::<_, _, Runtime>(client.clone()),874		50,875		50,876		prometheus_registry.clone(),877	));878879	let (network, system_rpc_tx, tx_handler_controller, network_starter) =880		sc_service::build_network(sc_service::BuildNetworkParams {881			config: &config,882			client: client.clone(),883			transaction_pool: transaction_pool.clone(),884			spawn_handle: task_manager.spawn_handle(),885			import_queue,886			block_announce_validator_builder: None,887			warp_sync: None,888		})?;889890	if config.offchain_worker.enabled {891		sc_service::build_offchain_workers(892			&config,893			task_manager.spawn_handle(),894			client.clone(),895			network.clone(),896		);897	}898899	let collator = config.role.is_authority();900901	let select_chain = maybe_select_chain.clone();902903	if collator {904		let block_import =905			FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());906907		let env = sc_basic_authorship::ProposerFactory::new(908			task_manager.spawn_handle(),909			client.clone(),910			transaction_pool.clone(),911			prometheus_registry.as_ref(),912			telemetry.as_ref().map(|x| x.handle()),913		);914915		let transactions_commands_stream: Box<916			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,917		> = Box::new(918			transaction_pool919				.pool()920				.validated_pool()921				.import_notification_stream()922				.map(|_| EngineCommand::SealNewBlock {923					create_empty: true,924					finalize: false, // todo:collator finalize true925					parent_hash: None,926					sender: None,927				}),928		);929930		let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));931		let idle_commands_stream: Box<932			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,933		> = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {934			create_empty: true,935			finalize: false, // todo:collator finalize true936			parent_hash: None,937			sender: None,938		}));939940		let commands_stream = select(transactions_commands_stream, idle_commands_stream);941942		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;943		let client_set_aside_for_cidp = client.clone();944945		task_manager.spawn_essential_handle().spawn_blocking(946			"authorship_task",947			Some("block-authoring"),948			run_manual_seal(ManualSealParams {949				block_import,950				env,951				client: client.clone(),952				pool: transaction_pool.clone(),953				commands_stream,954				select_chain: select_chain.clone(),955				consensus_data_provider: None,956				create_inherent_data_providers: move |block: Hash, ()| {957					let current_para_block = client_set_aside_for_cidp958						.number(block)959						.expect("Header lookup should succeed")960						.expect("Header passed in as parent should be present in backend.");961962					let client_for_xcm = client_set_aside_for_cidp.clone();963					async move {964						let time = sp_timestamp::InherentDataProvider::from_system_time();965966						let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {967							current_para_block,968							relay_offset: 1000,969							relay_blocks_per_para_block: 2,970							para_blocks_per_relay_epoch: 0,971							xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(972								&*client_for_xcm,973								block,974								Default::default(),975								Default::default(),976							),977							relay_randomness_config: (),978							raw_downward_messages: vec![],979							raw_horizontal_messages: vec![],980						};981982						let slot =983						sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(984							*time,985							slot_duration,986						);987988						Ok((time, slot, mocked_parachain))989					}990				},991			}),992		);993	}994995	task_manager.spawn_essential_handle().spawn(996		"frontier-mapping-sync-worker",997		Some("block-authoring"),998		MappingSyncWorker::new(999			client.import_notification_stream(),1000			Duration::new(6, 0),1001			client.clone(),1002			backend.clone(),1003			frontier_backend.clone(),1004			3,1005			0,1006			SyncStrategy::Normal,1007		)1008		.for_each(|()| futures::future::ready(())),1009	);10101011	let rpc_client = client.clone();1012	let rpc_pool = transaction_pool.clone();1013	let rpc_network = network.clone();1014	let rpc_frontier_backend = frontier_backend.clone();1015	let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1016		let full_deps = unique_rpc::FullDeps {1017			backend: rpc_frontier_backend.clone(),1018			deny_unsafe,1019			client: rpc_client.clone(),1020			pool: rpc_pool.clone(),1021			graph: rpc_pool.pool().clone(),1022			// TODO: Unhardcode1023			enable_dev_signer: false,1024			filter_pool: filter_pool.clone(),1025			network: rpc_network.clone(),1026			select_chain: select_chain.clone(),1027			is_authority: collator,1028			// TODO: Unhardcode1029			max_past_logs: 10000,1030			block_data_cache: block_data_cache.clone(),1031			fee_history_cache: fee_history_cache.clone(),1032			// TODO: Unhardcode1033			fee_history_limit: 2048,1034		};10351036		unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1037			full_deps,1038			subscription_executor,1039		)1040		.map_err(Into::into)1041	});10421043	sc_service::spawn_tasks(sc_service::SpawnTasksParams {1044		network,1045		client,1046		keystore: keystore_container.sync_keystore(),1047		task_manager: &mut task_manager,1048		transaction_pool,1049		rpc_builder,1050		backend,1051		system_rpc_tx,1052		config,1053		telemetry: None,1054		tx_handler_controller,1055	})?;10561057	network_starter.start_network();1058	Ok(task_manager)1059}
modifiedpallets/collator-selection/Cargo.tomldiffbeforeafterboth
--- a/pallets/collator-selection/Cargo.toml
+++ b/pallets/collator-selection/Cargo.toml
@@ -25,6 +25,7 @@
 frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
 pallet-authorship = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
 pallet-session = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
+pallet-configuration = { default-features = false, path = "../configuration" }
 
 frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
 
modifiedpallets/collator-selection/src/lib.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/lib.rs
+++ b/pallets/collator-selection/src/lib.rs
@@ -105,16 +105,15 @@
 		},
 		BoundedVec, PalletId,
 	};
-	use frame_system::{pallet_prelude::*, Config as SystemConfig};
+	use frame_system::pallet_prelude::*;
 	use pallet_session::SessionManager;
-	use sp_runtime::{
-		Perbill,
-		traits::{One, Convert},
+	use sp_runtime::{Perbill, traits::Convert};
+	use pallet_configuration::{
+		CollatorSelectionDesiredCollatorsOverride as DesiredCollators,
+		CollatorSelectionLicenseBondOverride as LicenseBond,
+		CollatorSelectionKickThresholdOverride as KickThreshold, BalanceOf,
 	};
 	use sp_staking::SessionIndex;
-
-	type BalanceOf<T> =
-		<<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
 
 	/// A convertor from collators id. Since this pallet does not have stash/controller, this is
 	/// just identity.
@@ -127,13 +126,10 @@
 
 	/// Configure the pallet by specifying the parameters and types on which it depends.
 	#[pallet::config]
-	pub trait Config: frame_system::Config {
+	pub trait Config: frame_system::Config + pallet_configuration::Config {
 		/// Overarching event type.
 		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
 
-		/// The currency mechanism.
-		type Currency: ReservableCurrency<Self::AccountId>;
-
 		/// Origin that can dictate updating parameters of this pallet.
 		type UpdateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
 
@@ -176,8 +172,8 @@
 
 	/// The (community) collation license holders.
 	#[pallet::storage]
-	#[pallet::getter(fn licenses)]
-	pub type Licenses<T: Config> =
+	#[pallet::getter(fn license_deposit_of)]
+	pub type LicenseDepositOf<T: Config> =
 		StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf<T>, ValueQuery>;
 
 	/// The (community, limited) collation candidates.
@@ -185,40 +181,16 @@
 	#[pallet::getter(fn candidates)]
 	pub type Candidates<T: Config> =
 		StorageValue<_, BoundedVec<T::AccountId, T::MaxCollators>, ValueQuery>;
-
-	/// Collator will be kicked if it does not produce a block within the threshold (does not apply to invulnerables).
-	///
-	/// Should be a multiple of session or things will get inconsistent. todo:collator reword?
-	#[pallet::storage]
-	#[pallet::getter(fn kick_threshold)]
-	pub type KickThreshold<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
 
 	/// Last block authored by collator.
 	#[pallet::storage]
 	#[pallet::getter(fn last_authored_block)]
 	pub type LastAuthoredBlock<T: Config> =
 		StorageMap<_, Twox64Concat, T::AccountId, T::BlockNumber, ValueQuery>;
-
-	/// Desired number of candidates.
-	///
-	/// This should ideally always be less than [`Config::MaxCollators`] for weights to be correct.
-	#[pallet::storage]
-	#[pallet::getter(fn desired_collators)]
-	pub type DesiredCollators<T> = StorageValue<_, u32, ValueQuery>;
 
-	/// Fixed amount to deposit to become a collator.
-	///
-	/// When a collator calls `leave_intent` they immediately receive the deposit back.
-	#[pallet::storage]
-	#[pallet::getter(fn license_bond)]
-	pub type LicenseBond<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;
-
 	#[pallet::genesis_config]
 	pub struct GenesisConfig<T: Config> {
 		pub invulnerables: Vec<T::AccountId>,
-		pub license_bond: BalanceOf<T>,
-		pub kick_threshold: T::BlockNumber,
-		pub desired_collators: u32,
 	}
 
 	#[cfg(feature = "std")]
@@ -226,9 +198,6 @@
 		fn default() -> Self {
 			Self {
 				invulnerables: Default::default(),
-				license_bond: Default::default(),
-				kick_threshold: T::BlockNumber::one(),
-				desired_collators: Default::default(),
 			}
 		}
 	}
@@ -248,14 +217,7 @@
 			let bounded_invulnerables =
 				BoundedVec::<_, T::MaxCollators>::try_from(self.invulnerables.clone())
 					.expect("genesis invulnerables are more than T::MaxCollators");
-			assert!(
-				T::MaxCollators::get() >= self.desired_collators,
-				"genesis desired_collators are more than T::MaxCollators",
-			);
-
-			<DesiredCollators<T>>::put(self.desired_collators);
-			<LicenseBond<T>>::put(self.license_bond);
-			<KickThreshold<T>>::put(self.kick_threshold);
+			
 			<Invulnerables<T>>::put(bounded_invulnerables);
 		}
 	}
@@ -263,15 +225,6 @@
 	#[pallet::event]
 	#[pallet::generate_deposit(pub(super) fn deposit_event)]
 	pub enum Event<T: Config> {
-		NewDesiredCollators {
-			desired_collators: u32,
-		},
-		NewLicenseBond {
-			bond_amount: BalanceOf<T>,
-		},
-		NewKickThreshold {
-			length_in_blocks: T::BlockNumber,
-		},
 		InvulnerableAdded {
 			invulnerable: T::AccountId,
 		},
@@ -383,51 +336,6 @@
 			Ok(().into())
 		}
 
-		/// Set the ideal number of collators. If lowering this number,
-		/// then the number of running collators could be higher than this figure.
-		/// Aside from that edge case, there should be no other way to have more collators than the desired number.
-		#[pallet::weight(T::WeightInfo::set_desired_collators())]
-		pub fn set_desired_collators(origin: OriginFor<T>, max: u32) -> DispatchResultWithPostInfo {
-			T::UpdateOrigin::ensure_origin(origin)?;
-			// we trust origin calls, this is just a for more accurate benchmarking
-			if max > T::MaxCollators::get() {
-				log::warn!("max > T::MaxCollators; you might need to run benchmarks again");
-			}
-			<DesiredCollators<T>>::put(max);
-			Self::deposit_event(Event::NewDesiredCollators {
-				desired_collators: max,
-			});
-			Ok(().into())
-		}
-
-		/// Set the candidacy bond amount.
-		#[pallet::weight(T::WeightInfo::set_license_bond())]
-		pub fn set_license_bond(
-			origin: OriginFor<T>,
-			bond: BalanceOf<T>,
-		) -> DispatchResultWithPostInfo {
-			T::UpdateOrigin::ensure_origin(origin)?;
-			<LicenseBond<T>>::put(bond);
-			Self::deposit_event(Event::NewLicenseBond { bond_amount: bond });
-			Ok(().into())
-		}
-
-		/// Set the length of the kick threshold.
-		/// Note that if the length is not a multiple of the session period, it might get inconsistent.
-		#[pallet::weight(T::WeightInfo::set_license_bond())] // todo:collator weight
-		pub fn set_kick_threshold(
-			origin: OriginFor<T>,
-			kick_threshold: T::BlockNumber,
-		) -> DispatchResultWithPostInfo {
-			T::UpdateOrigin::ensure_origin(origin)?;
-			// todo:collator insert something to guarantee consistency?
-			<KickThreshold<T>>::put(kick_threshold);
-			Self::deposit_event(Event::NewKickThreshold {
-				length_in_blocks: kick_threshold,
-			});
-			Ok(().into())
-		}
-
 		/// Purchase a license on block collation for this account.
 		/// It does not make it a collator candidate, use `onboard` afterward. The account must
 		/// (a) already have registered session keys and (b) be able to reserve the `LicenseBond`.
@@ -438,7 +346,7 @@
 			// register_as_candidate
 			let who = ensure_signed(origin)?;
 
-			if Licenses::<T>::contains_key(&who) {
+			if LicenseDepositOf::<T>::contains_key(&who) {
 				return Err(Error::<T>::AlreadyHoldingLicense.into());
 			}
 
@@ -449,10 +357,10 @@
 				Error::<T>::ValidatorNotRegistered
 			);
 
-			let deposit = Self::license_bond();
+			let deposit = <LicenseBond<T>>::get();
 
 			T::Currency::reserve(&who, deposit)?;
-			Licenses::<T>::insert(who.clone(), deposit);
+			LicenseDepositOf::<T>::insert(who.clone(), deposit);
 
 			Self::deposit_event(Event::LicenseObtained {
 				account_id: who,
@@ -471,12 +379,15 @@
 			let who = ensure_signed(origin)?;
 
 			// ensure the user obtained the license.
-			ensure!(Licenses::<T>::contains_key(&who), Error::<T>::NoLicense);
+			ensure!(
+				LicenseDepositOf::<T>::contains_key(&who),
+				Error::<T>::NoLicense
+			);
 			// ensure we are below limit.
 			let length = <Candidates<T>>::decode_len().unwrap_or_default()
 				+ <Invulnerables<T>>::decode_len().unwrap_or_default();
 			ensure!(
-				(length as u32) < Self::desired_collators(),
+				(length as u32) < <DesiredCollators<T>>::get(),
 				Error::<T>::TooManyCandidates
 			);
 			ensure!(
@@ -495,7 +406,7 @@
 						// First authored block is current block plus kick threshold to handle session delay
 						<LastAuthoredBlock<T>>::insert(
 							who.clone(),
-							frame_system::Pallet::<T>::block_number() + Self::kick_threshold(),
+							frame_system::Pallet::<T>::block_number() + <KickThreshold<T>>::get(),
 						);
 						Ok(candidates.len())
 					}
@@ -594,7 +505,7 @@
 		/// Removes a candidate if they exist and sends them back their deposit, optionally slashed.
 		fn try_release_license(who: &T::AccountId, should_slash: bool) -> DispatchResult {
 			let mut deposit_returned = BalanceOf::<T>::default();
-			Licenses::<T>::try_mutate_exists(who, |deposit| -> DispatchResult {
+			LicenseDepositOf::<T>::try_mutate_exists(who, |deposit| -> DispatchResult {
 				if let Some(deposit) = deposit.take() {
 					if should_slash {
 						let slashed = T::SlashRatio::get() * deposit;
@@ -640,7 +551,7 @@
 			candidates: BoundedVec<T::AccountId, T::MaxCollators>,
 		) -> BoundedVec<T::AccountId, T::MaxCollators> {
 			let now = frame_system::Pallet::<T>::block_number();
-			let kick_threshold = Self::kick_threshold();
+			let kick_threshold = <KickThreshold<T>>::get();
 			candidates
 				.into_iter()
 				.filter_map(|c| {
modifiedpallets/collator-selection/src/mock.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -63,6 +63,7 @@
 		Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
 		CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},
 		Authorship: pallet_authorship::{Pallet, Call, Storage, Inherent},
+		Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>},
 	}
 );
 
@@ -200,13 +201,38 @@
 	type WeightInfo = ();
 }
 
+parameter_types! {
+	pub const MaxCollators: u32 = 5;
+	pub const LicenseBond: u64 = 10;
+	pub const KickThreshold: u64 = 10;
+	// the following values do not matter and are meaningless, etc.
+	pub const DefaultWeightToFeeCoefficient: u32 = 100_000;
+	pub const DefaultMinGasPrice: u64 = 100_000;
+	pub const MaxXcmAllowedLocations: u32 = 16;
+	pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);
+	pub const DayRelayBlocks: u32 = 1;
+}
+
+impl pallet_configuration::Config for Test {
+	type RuntimeEvent = RuntimeEvent;
+	type Currency = Balances;
+	type DefaultCollatorSelectionMaxCollators = MaxCollators;
+	type DefaultCollatorSelectionKickThreshold = KickThreshold;
+	type DefaultCollatorSelectionLicenseBond = LicenseBond;
+	// the following we don't care about
+	type DefaultWeightToFeeCoefficient = DefaultWeightToFeeCoefficient;
+	type DefaultMinGasPrice = DefaultMinGasPrice;
+	type MaxXcmAllowedLocations = MaxXcmAllowedLocations;
+	type AppPromotionDailyRate = AppPromotionDailyRate;
+	type DayRelayBlocks = DayRelayBlocks;
+}
+
 ord_parameter_types! {
 	pub const RootAccount: u64 = 777;
 }
 
 parameter_types! {
 	pub const PotId: PalletId = PalletId(*b"PotStake");
-	pub const MaxCollators: u32 = 20;
 	pub const MaxAuthorities: u32 = 100_000;
 	pub const SlashRatio: Perbill = Perbill::one();
 }
@@ -224,7 +250,6 @@
 
 impl Config for Test {
 	type RuntimeEvent = RuntimeEvent;
-	type Currency = Balances;
 	type UpdateOrigin = EnsureSignedBy<RootAccount, u64>;
 	type PotId = PotId;
 	type MaxCollators = MaxCollators;
@@ -257,9 +282,6 @@
 		})
 		.collect::<Vec<_>>();
 	let collator_selection = collator_selection::GenesisConfig::<Test> {
-		desired_collators: 5,
-		license_bond: 10,
-		kick_threshold: 10,
 		invulnerables,
 	};
 	let session = pallet_session::GenesisConfig::<Test> { keys };
modifiedpallets/collator-selection/src/tests.rsdiffbeforeafterboth
--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -36,8 +36,14 @@
 	assert_noop, assert_ok,
 	traits::{Currency, GenesisBuild, OnInitialize},
 };
+use frame_system::RawOrigin;
 use pallet_balances::Error as BalancesError;
 use sp_runtime::traits::BadOrigin;
+use pallet_configuration::{
+	CollatorSelectionDesiredCollatorsOverride as DesiredCollators,
+	CollatorSelectionKickThresholdOverride as KickThreshold,
+	CollatorSelectionLicenseBondOverride as LicenseBond,
+};
 
 fn get_license_and_onboard(account_id: <Test as frame_system::Config>::AccountId) {
 	assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(
@@ -51,8 +57,8 @@
 #[test]
 fn basic_setup_works() {
 	new_test_ext().execute_with(|| {
-		assert_eq!(CollatorSelection::desired_collators(), 5);
-		assert_eq!(CollatorSelection::license_bond(), 10);
+		assert_eq!(<DesiredCollators<Test>>::get(), 5);
+		assert_eq!(<LicenseBond<Test>>::get(), 10);
 
 		assert!(CollatorSelection::candidates().is_empty());
 		assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]);
@@ -122,18 +128,21 @@
 fn set_desired_collators_works() {
 	new_test_ext().execute_with(|| {
 		// given
-		assert_eq!(CollatorSelection::desired_collators(), 5);
+		assert_eq!(<DesiredCollators<Test>>::get(), 5);
 
 		// can set
-		assert_ok!(CollatorSelection::set_desired_collators(
-			RuntimeOrigin::signed(RootAccount::get()),
-			7
+		assert_ok!(Configuration::set_collator_selection_desired_collators(
+			RawOrigin::Root.into(),
+			Some(7)
 		));
-		assert_eq!(CollatorSelection::desired_collators(), 7);
+		assert_eq!(<DesiredCollators<Test>>::get(), 7);
 
 		// rejects bad origin
 		assert_noop!(
-			CollatorSelection::set_desired_collators(RuntimeOrigin::signed(1), 8),
+			Configuration::set_collator_selection_desired_collators(
+				RuntimeOrigin::signed(1),
+				Some(8)
+			),
 			BadOrigin
 		);
 	});
@@ -143,18 +152,18 @@
 fn set_license_bond() {
 	new_test_ext().execute_with(|| {
 		// given
-		assert_eq!(CollatorSelection::license_bond(), 10);
+		assert_eq!(<LicenseBond<Test>>::get(), 10);
 
 		// can set
-		assert_ok!(CollatorSelection::set_license_bond(
-			RuntimeOrigin::signed(RootAccount::get()),
-			7
+		assert_ok!(Configuration::set_collator_selection_license_bond(
+			RawOrigin::Root.into(),
+			Some(7)
 		));
-		assert_eq!(CollatorSelection::license_bond(), 7);
+		assert_eq!(<LicenseBond<Test>>::get(), 7);
 
 		// rejects bad origin.
 		assert_noop!(
-			CollatorSelection::set_license_bond(RuntimeOrigin::signed(1), 8),
+			Configuration::set_collator_selection_license_bond(RuntimeOrigin::signed(1), Some(8)),
 			BadOrigin
 		);
 	});
@@ -179,7 +188,7 @@
 fn cannot_onboard_candidate_if_too_many() {
 	new_test_ext().execute_with(|| {
 		// reset desired candidates
-		<crate::DesiredCollators<Test>>::put(0);
+		<pallet_configuration::CollatorSelectionDesiredCollatorsOverride<Test>>::put(0);
 
 		// can still get a license.
 		assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(4)));
@@ -191,7 +200,7 @@
 		);
 
 		// reset desired candidates to invulnerables + 1
-		<crate::DesiredCollators<Test>>::put(3);
+		<pallet_configuration::CollatorSelectionDesiredCollatorsOverride<Test>>::put(3);
 		assert_ok!(CollatorSelection::onboard(RuntimeOrigin::signed(4)));
 
 		// but no more.
@@ -236,7 +245,7 @@
 	new_test_ext().execute_with(|| {
 		// can add 3 as candidate
 		get_license_and_onboard(3);
-		assert_eq!(CollatorSelection::licenses(3), 10);
+		assert_eq!(CollatorSelection::license_deposit_of(3), 10);
 		assert_eq!(CollatorSelection::candidates(), vec![3]);
 		assert_eq!(CollatorSelection::last_authored_block(3), 10);
 		assert_eq!(Balances::free_balance(3), 90);
@@ -257,8 +266,8 @@
 fn becoming_candidate_works() {
 	new_test_ext().execute_with(|| {
 		// given
-		assert_eq!(CollatorSelection::desired_collators(), 5);
-		assert_eq!(CollatorSelection::license_bond(), 10);
+		assert_eq!(<DesiredCollators<Test>>::get(), 5);
+		assert_eq!(<LicenseBond<Test>>::get(), 10);
 		assert_eq!(CollatorSelection::candidates(), Vec::new());
 		assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]);
 
@@ -315,7 +324,7 @@
 		));
 		// should exclude from candidates, but not revoke the license
 		assert_eq!(CollatorSelection::candidates(), vec![]);
-		assert_eq!(CollatorSelection::licenses(3), 10);
+		assert_eq!(CollatorSelection::license_deposit_of(3), 10);
 		assert_eq!(Balances::free_balance(3), 90);
 	});
 }
@@ -503,7 +512,7 @@
 		assert_eq!(SessionHandlerCollators::get(), vec![1, 2, 3, 4]);
 
 		assert_eq!(CollatorSelection::candidates(), vec![4]);
-		assert_eq!(CollatorSelection::kick_threshold(), 10);
+		assert_eq!(<KickThreshold<Test>>::get(), 10);
 		assert_eq!(CollatorSelection::last_authored_block(4), 20);
 
 		initialize_to_block(30);
@@ -524,9 +533,6 @@
 	let invulnerables = vec![1, 1];
 
 	let collator_selection = collator_selection::GenesisConfig::<Test> {
-		desired_collators: 5,
-		license_bond: 10,
-		kick_threshold: 10,
 		invulnerables,
 	};
 	// collator selection must be initialized before session.
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
--- a/pallets/configuration/src/lib.rs
+++ b/pallets/configuration/src/lib.rs
@@ -36,15 +36,24 @@
 mod pallet {
 	use super::*;
 	use frame_support::{
-		traits::Get,
-		pallet_prelude::{StorageValue, ValueQuery, DispatchResult, OptionQuery},
-		BoundedVec,
+		traits::{Get, ReservableCurrency, Currency},
+		pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType, OptionQuery},
+		BoundedVec, log,
 	};
-	use frame_system::{pallet_prelude::OriginFor, ensure_root};
+	use frame_system::{pallet_prelude::OriginFor, ensure_root, Config as SystemConfig};
 	use xcm::v1::MultiLocation;
 
+	pub type BalanceOf<T> =
+		<<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
+
 	#[pallet::config]
 	pub trait Config: frame_system::Config {
+		/// Overarching event type.
+		type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
+
+		/// The currency mechanism.
+		type Currency: ReservableCurrency<Self::AccountId>;
+
 		#[pallet::constant]
 		type DefaultWeightToFeeCoefficient: Get<u32>;
 
@@ -57,6 +66,27 @@
 		type AppPromotionDailyRate: Get<Perbill>;
 		#[pallet::constant]
 		type DayRelayBlocks: Get<Self::BlockNumber>;
+
+		#[pallet::constant]
+		type DefaultCollatorSelectionMaxCollators: Get<u32>;
+		#[pallet::constant]
+		type DefaultCollatorSelectionLicenseBond: Get<BalanceOf<Self>>;
+		#[pallet::constant]
+		type DefaultCollatorSelectionKickThreshold: Get<Self::BlockNumber>;
+	}
+
+	#[pallet::event]
+	#[pallet::generate_deposit(pub(super) fn deposit_event)]
+	pub enum Event<T: Config> {
+		NewDesiredCollators {
+			desired_collators: Option<u32>,
+		},
+		NewCollatorLicenseBond {
+			bond_cost: Option<BalanceOf<T>>,
+		},
+		NewCollatorKickThreshold {
+			length_in_blocks: Option<T::BlockNumber>,
+		},
 	}
 
 	#[pallet::error]
@@ -85,6 +115,27 @@
 	pub type AppPromomotionConfigurationOverride<T: Config> =
 		StorageValue<Value = AppPromotionConfiguration<T::BlockNumber>, QueryKind = ValueQuery>;
 
+	#[pallet::storage]
+	pub type CollatorSelectionDesiredCollatorsOverride<T: Config> = StorageValue<
+		Value = u32,
+		QueryKind = ValueQuery,
+		OnEmpty = T::DefaultCollatorSelectionMaxCollators,
+	>;
+
+	#[pallet::storage]
+	pub type CollatorSelectionLicenseBondOverride<T: Config> = StorageValue<
+		Value = BalanceOf<T>,
+		QueryKind = ValueQuery,
+		OnEmpty = T::DefaultCollatorSelectionLicenseBond,
+	>;
+
+	#[pallet::storage]
+	pub type CollatorSelectionKickThresholdOverride<T: Config> = StorageValue<
+		Value = T::BlockNumber,
+		QueryKind = ValueQuery,
+		OnEmpty = T::DefaultCollatorSelectionKickThreshold,
+	>;
+
 	#[pallet::call]
 	impl<T: Config> Pallet<T> {
 		#[pallet::weight(T::DbWeight::get().writes(1))]
@@ -144,6 +195,55 @@
 
 			Ok(())
 		}
+
+		#[pallet::weight(T::DbWeight::get().writes(1))]
+		pub fn set_collator_selection_desired_collators(
+			origin: OriginFor<T>,
+			max: Option<u32>,
+		) -> DispatchResult {
+			ensure_root(origin)?;
+			if let Some(max) = max {
+				// we trust origin calls, this is just a for more accurate benchmarking
+				if max > T::DefaultCollatorSelectionMaxCollators::get() {
+					log::warn!("max > T::DefaultCollatorSelectionMaxCollators; you might need to run benchmarks again");
+				}
+				<CollatorSelectionDesiredCollatorsOverride<T>>::set(max);
+			} else {
+				<CollatorSelectionDesiredCollatorsOverride<T>>::kill();
+			}
+			Self::deposit_event(Event::NewDesiredCollators { desired_collators: max });
+			Ok(())
+		}
+
+		#[pallet::weight(T::DbWeight::get().writes(1))]
+		pub fn set_collator_selection_license_bond(
+			origin: OriginFor<T>,
+			amount: Option<BalanceOf<T>>,
+		) -> DispatchResult {
+			ensure_root(origin)?;
+			if let Some(amount) = amount {
+				<CollatorSelectionLicenseBondOverride<T>>::set(amount);
+			} else {
+				<CollatorSelectionLicenseBondOverride<T>>::kill();
+			}
+			Self::deposit_event(Event::NewCollatorLicenseBond { bond_cost: amount });
+			Ok(())
+		}
+
+		#[pallet::weight(T::DbWeight::get().writes(1))]
+		pub fn set_collator_selection_kick_threshold(
+			origin: OriginFor<T>,
+			threshold: Option<T::BlockNumber>,
+		) -> DispatchResult {
+			ensure_root(origin)?;
+			if let Some(threshold) = threshold {
+				<CollatorSelectionKickThresholdOverride<T>>::set(threshold);
+			} else {
+				<CollatorSelectionKickThresholdOverride<T>>::kill();
+			}
+			Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold });
+			Ok(())
+		}
 	}
 
 	#[pallet::pallet]
modifiedprimitives/common/src/constants.rsdiffbeforeafterboth
--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -46,6 +46,8 @@
 pub const EXISTENTIAL_DEPOSIT: u128 = 0;
 /// Amount of Balance reserved for candidate registration.
 pub const GENESIS_LICENSE_BOND: u128 = 1_000_000_000_000 * UNIQUE;
+/// Amount of maximum collators for Collator Selection.
+pub const MAX_COLLATORS: u32 = 10;
 /// How long a periodic session lasts in blocks.
 pub const SESSION_LENGTH: BlockNumber = HOURS;
 
modifiedruntime/common/config/pallets/collator_selection.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/collator_selection.rs
+++ b/runtime/common/config/pallets/collator_selection.rs
@@ -17,14 +17,14 @@
 use frame_support::{parameter_types, PalletId};
 use frame_system::EnsureRoot;
 use crate::{
-	AccountId, BlockNumber, Runtime, RuntimeEvent, Balances, Aura, Session, SessionKeys,
-	CollatorSelection, config::pallets::TreasuryAccountId,
+	AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent, Aura, Session, SessionKeys,
+	CollatorSelection, Treasury,
+	config::pallets::{MaxCollators, SessionPeriod, TreasuryAccountId},
 };
 use sp_runtime::Perbill;
-use up_common::constants::*;
+use up_common::constants::{UNIQUE, MILLIUNIQUE};
 
 parameter_types! {
-	pub const SessionPeriod: BlockNumber = SESSION_LENGTH;
 	pub const SessionOffset: BlockNumber = 0;
 }
 
@@ -55,13 +55,11 @@
 
 parameter_types! {
 	pub const PotId: PalletId = PalletId(*b"PotStake");
-	pub const MaxCollators: u32 = 10;
 	pub const SlashRatio: Perbill = Perbill::from_percent(100);
 }
 
 impl pallet_collator_selection::Config for Runtime {
 	type RuntimeEvent = RuntimeEvent;
-	type Currency = Balances;
 	// We allow root only to execute privileged collator selection operations.
 	type UpdateOrigin = EnsureRoot<AccountId>;
 	type TreasuryAccountId = TreasuryAccountId;
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -25,7 +25,7 @@
 	},
 	Runtime, RuntimeEvent, RuntimeCall, Balances,
 };
-use frame_support::traits::{ConstU32, ConstU64};
+use frame_support::traits::{ConstU32, ConstU64, ConstU128};
 use up_common::{
 	types::{AccountId, Balance, BlockNumber},
 	constants::*,
@@ -104,11 +104,20 @@
 
 parameter_types! {
 	pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);
+	pub const MaxCollators: u32 = MAX_COLLATORS;
+	pub const SessionPeriod: BlockNumber = SESSION_LENGTH;
 	pub const DayRelayBlocks: BlockNumber = RELAY_DAYS;
 }
+
 impl pallet_configuration::Config for Runtime {
+	type RuntimeEvent = RuntimeEvent;
+	type Currency = Balances;
 	type DefaultWeightToFeeCoefficient = ConstU32<{ up_common::constants::WEIGHT_TO_FEE_COEFF }>;
 	type DefaultMinGasPrice = ConstU64<{ up_common::constants::MIN_GAS_PRICE }>;
+	type DefaultCollatorSelectionMaxCollators = MaxCollators;
+	type DefaultCollatorSelectionKickThreshold = SessionPeriod;
+	type DefaultCollatorSelectionLicenseBond =
+		ConstU128<{ up_common::constants::GENESIS_LICENSE_BOND }>;
 	type MaxXcmAllowedLocations = ConstU32<16>;
 	type AppPromotionDailyRate = AppPromotionDailyRate;
 	type DayRelayBlocks = DayRelayBlocks;
modifiedruntime/common/construct_runtime/mod.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -69,7 +69,7 @@
                 // #[runtimes(opal)]
                 // Scheduler: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 62,
 
-                Configuration: pallet_configuration::{Pallet, Call, Storage} = 63,
+                Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>} = 63,
 
                 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,
                 // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,
modifiedruntime/common/maintenance.rsdiffbeforeafterboth
--- a/runtime/common/maintenance.rs
+++ b/runtime/common/maintenance.rs
@@ -85,6 +85,12 @@
 					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
 				}
 
+				#[cfg(feature = "collator-selection")]
+				RuntimeCall::CollatorSelection(_)
+				| RuntimeCall::Authorship(_)
+				| RuntimeCall::Session(_)
+				| RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
+
 				#[cfg(feature = "pallet-test-utils")]
 				RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
 
@@ -110,7 +116,7 @@
 	) -> TransactionValidity {
 		if Maintenance::is_enabled() {
 			match call {
-				RuntimeCall::EVM(_) | RuntimeCall::Ethereum(_) | RuntimeCall::EvmMigration(_) => {
+				RuntimeCall::EVM(_) | RuntimeCall::Ethereum(_) | RuntimeCall::DataManagement(_) => {
 					Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
 				}
 				_ => Ok(ValidTransaction::default()),
modifiedruntime/common/mod.rsdiffbeforeafterboth
--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -186,13 +186,9 @@
 		#[cfg(feature = "collator-selection")]
 		{
 			use frame_support::{BoundedVec, storage::migration};
-			use sp_runtime::{
-				traits::{OpaqueKeys, Saturating},
-				RuntimeAppPublic,
-			};
+			use sp_runtime::{traits::OpaqueKeys, RuntimeAppPublic};
 			use pallet_session::SessionManager;
-			use up_common::constants::{GENESIS_LICENSE_BOND, SESSION_LENGTH};
-			use crate::config::pallets::collator_selection::MaxCollators;
+			use crate::config::pallets::MaxCollators;
 
 			let mut weight = <Runtime as frame_system::Config>::DbWeight::get().reads(1);
 
@@ -241,9 +237,6 @@
 				.expect("Existing collators/invulnerables are more than MaxCollators");
 
 				<pallet_collator_selection::Invulnerables<Runtime>>::put(bounded_invulnerables);
-				<pallet_collator_selection::KickThreshold<Runtime>>::put(SESSION_LENGTH);
-				<pallet_collator_selection::DesiredCollators<Runtime>>::put(MaxCollators::get());
-				<pallet_collator_selection::LicenseBond<Runtime>>::put(GENESIS_LICENSE_BOND);
 
 				let keys = invulnerables
 					.into_iter()
modifiedruntime/common/tests/mod.rsdiffbeforeafterboth
--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -64,9 +64,6 @@
 
 	let cfg = GenesisConfig {
 		collator_selection: CollatorSelectionConfig {
-			desired_collators: 2,
-			license_bond: 10,
-			kick_threshold: 10,
 			invulnerables,
 		},
 		session: SessionConfig { keys },
modifiedtests/src/collatorSelection.seqtest.tsdiffbeforeafterboth
--- a/tests/src/collatorSelection.seqtest.ts
+++ b/tests/src/collatorSelection.seqtest.ts
@@ -17,8 +17,6 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {usingPlaygrounds, expect, itSub, Pallets, requirePalletsOrSkip} from './util';
 
-const MAX_INVULNERABLES = 10;
-
 async function resetInvulnerables() {
   await usingPlaygrounds(async (helper, privateKey) => {
     const superuser = await privateKey('//Alice');
@@ -31,7 +29,7 @@
       
       let nonce = await helper.chain.getNonce(alice.address);
       // In case there are too many invulnerables already, remove some of them, leaving space for Alice and Bob.
-      if (invulnerables.length + 2 >= MAX_INVULNERABLES) {
+      if (invulnerables.length + 2 >= helper.collatorSelection.maxCollators()) {
         await Promise.all([
           helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.removeInvulnerable', [invulnerables.pop()], true, {nonce: nonce++}),
           helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.removeInvulnerable', [invulnerables.pop()], true, {nonce: nonce++}),
@@ -409,7 +407,7 @@
         // 28 non-functioning collators, teehee.
         
         const invulnerablesLength = (await helper.collatorSelection.getInvulnerables()).length;
-        const invulnerablesUntilLimit = MAX_INVULNERABLES - invulnerablesLength;
+        const invulnerablesUntilLimit = helper.collatorSelection.maxCollators() - invulnerablesLength;
         const newInvulnerables = await helper.arrange.createAccounts(Array(invulnerablesUntilLimit).fill(10n), superuser);
         const [lastInvulnerable] = await helper.arrange.createAccounts([10n], superuser);
 
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -65,6 +65,7 @@
   arrange: ArrangeGroup;
   wait: WaitGroup;
   admin: AdminGroup;
+  session: SessionGroup;
   testUtils: TestUtilGroup;
 
   constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {
@@ -75,6 +76,7 @@
     this.wait = new WaitGroup(this);
     this.admin = new AdminGroup(this);
     this.testUtils = new TestUtilGroup(this);
+    this.session = new SessionGroup(this);
   }
 
   async connect(wsEndpoint: string, _listeners?: any): Promise<void> {
@@ -456,14 +458,14 @@
     console.log(`Waiting for ${sessionCount} new session${sessionCount > 1 ? 's' : ''}.` 
       + ' This might take a while -- check SessionPeriod in pallet_session::Config for session time.');
 
-    const expectedSessionIndex = await this.helper.session.getIndex() + sessionCount;
+    const expectedSessionIndex = await (this.helper as DevUniqueHelper).session.getIndex() + sessionCount;
     let currentSessionIndex = -1;
 
     while (currentSessionIndex < expectedSessionIndex) {
       // eslint-disable-next-line no-async-promise-executor
       currentSessionIndex = await this.withTimeout(new Promise(async (resolve) => {
         await this.newBlocks(1);
-        const res = this.helper.session.getIndex();
+        const res = await (this.helper as DevUniqueHelper).session.getIndex();
         resolve(res);
       }), blockTimeout, 'The chain has stopped producing blocks!');
     }
@@ -552,6 +554,36 @@
   }
 }
 
+class SessionGroup {
+  helper: ChainHelperBase;
+
+  constructor(helper: ChainHelperBase) {
+    this.helper = helper;
+  }
+  
+  //todo:collator documentation
+  async getIndex(): Promise<number> {
+    return (await this.helper.callRpc('api.query.session.currentIndex')).toNumber();
+  }
+
+  newSessions(sessionCount = 1, blockTimeout = 24000): Promise<void> {
+    return (this.helper as DevUniqueHelper).wait.newSessions(sessionCount, blockTimeout);
+  }
+
+  setOwnKeys(signer: TSigner, key: string) {
+    return this.helper.executeExtrinsic(
+      signer,
+      'api.tx.session.setKeys', 
+      [key, '0x0'],
+      true,
+    );
+  }
+
+  setOwnKeysFromAddress(signer: TSigner) {
+    return this.setOwnKeys(signer, '0x' + Buffer.from(signer.addressRaw).toString('hex'));
+  }
+}
+
 class TestUtilGroup {
   helper: DevUniqueHelper;
 
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -45,7 +45,6 @@
 import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';
 import type {Vec} from '@polkadot/types-codec';
 import {FrameSystemEventRecord} from '@polkadot/types/lookup';
-import {DevUniqueHelper} from './unique.dev';
 
 export class CrossAccountId implements ICrossAccountId {
   Substrate?: TSubstrateAccount;
@@ -376,7 +375,6 @@
   children: ChainHelperBase[];
   address: AddressGroup;
   chain: ChainGroup;
-  session: SessionGroup;
 
   constructor(logger?: ILogger, helperBase?: any) {
     this.helperBase = helperBase;
@@ -392,7 +390,6 @@
     this.children = [];
     this.address = new AddressGroup(this);
     this.chain = new ChainGroup(this);
-    this.session = new SessionGroup(this);
   }
 
   clone(helperCls: ChainHelperBaseConstructor, options: {[key: string]: any} = {}) {
@@ -2642,30 +2639,6 @@
       blocksNum,
       options,
     }) as T;
-  }
-}
-
-class SessionGroup extends HelperGroup<ChainHelperBase> {
-  //todo:collator documentation
-  async getIndex(): Promise<number> {
-    return (await this.helper.callRpc('api.query.session.currentIndex')).toNumber();
-  }
-
-  newSessions(sessionCount = 1, blockTimeout = 24000): Promise<void> {
-    return (this.helper as DevUniqueHelper).wait.newSessions(sessionCount, blockTimeout);
-  }
-
-  setOwnKeys(signer: TSigner, key: string) {
-    return this.helper.executeExtrinsic(
-      signer,
-      'api.tx.session.setKeys', 
-      [key, '0x0'],
-      true,
-    );
-  }
-
-  setOwnKeysFromAddress(signer: TSigner) {
-    return this.setOwnKeys(signer, '0x' + Buffer.from(signer.addressRaw).toString('hex'));
   }
 }
 
@@ -2683,12 +2656,21 @@
     return (await this.helper.callRpc('api.query.collatorSelection.invulnerables')).map((x: any) => x.toHuman());
   }
 
+  /** and also total max invulnerables */
+  maxCollators(): number {
+    return (this.helper.getApi().consts.configuration.defaultCollatorSelectionMaxCollators.toJSON() as number);
+  }
+
+  async getDesiredCollators(): Promise<number> {
+    return (await this.helper.callRpc('api.query.configuration.collatorSelectionDesiredCollatorsOverride')).toNumber();
+  }
+
   setLicenseBond(signer: TSigner, amount: bigint) {
-    return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.setLicenseBond', [amount]);
+    return this.helper.executeExtrinsic(signer, 'api.tx.configuration.setCollatorSelectionLicenseBond', [amount]);
   }
 
   async getLicenseBond(): Promise<bigint> {
-    return (await this.helper.callRpc('api.query.collatorSelection.licenseBond')).toBigInt();
+    return (await this.helper.callRpc('api.query.configuration.collatorSelectionLicenseBondOverride')).toBigInt();
   }
 
   obtainLicense(signer: TSigner) {
@@ -2704,7 +2686,7 @@
   }
 
   async hasLicense(address: string): Promise<bigint> {
-    return (await this.helper.callRpc('api.query.collatorSelection.licenses', [address])).toBigInt();
+    return (await this.helper.callRpc('api.query.collatorSelection.licenseDepositOf', [address])).toBigInt();
   }
 
   onboard(signer: TSigner) {