pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError> {
	let telemetry = config
		.telemetry_endpoints
		.clone()
		.filter(|x| !x.is_empty())
		.map(|endpoints| -> Result<_, sc_telemetry::Error> {
			let worker = TelemetryWorker::new(16)?;
			let telemetry = worker.handle().new_telemetry(endpoints);
			Ok((worker, telemetry))
		})
		.transpose()?;

	let (client, backend, keystore_container, mut task_manager, on_demand) =
		sc_service::new_light_parts::<Block, RuntimeApi, Executor>(
			&config,
			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
		)?;

	let mut telemetry = telemetry.map(|(worker, telemetry)| {
		task_manager.spawn_handle().spawn("telemetry", worker.run());
		telemetry
	});

	config
		.network
		.extra_sets
		.push(sc_finality_grandpa::grandpa_peers_set_config());

	let select_chain = sc_consensus::LongestChain::new(backend.clone());

	let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
		config.transaction_pool.clone(),
		config.prometheus_registry(),
		task_manager.spawn_essential_handle(),
		client.clone(),
		on_demand.clone(),
	));

	let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
		client.clone(),
		&(client.clone() as Arc<_>),
		select_chain,
		telemetry.as_ref().map(|x| x.handle()),
	)?;

	let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration();

	let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _, _>(ImportQueueParams {
		block_import: grandpa_block_import.clone(),
		justification_import: Some(Box::new(grandpa_block_import)),
		client: client.clone(),
		create_inherent_data_providers: move |_, ()| async move {
			let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

			let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
				*timestamp,
				slot_duration,
			);

			Ok((timestamp, slot))
		},
		spawner: &task_manager.spawn_essential_handle(),
		can_author_with: sp_consensus::NeverCanAuthor,
		registry: config.prometheus_registry(),
		check_for_equivocation: Default::default(),
		telemetry: telemetry.as_ref().map(|x| x.handle()),
	})?;

	let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams {
		config: &config,
		client: client.clone(),
		transaction_pool: transaction_pool.clone(),
		spawn_handle: task_manager.spawn_handle(),
		import_queue,
		on_demand: Some(on_demand.clone()),
		block_announce_validator_builder: None,
	})?;

	if config.offchain_worker.enabled {
		sc_service::build_offchain_workers(&config, task_manager.spawn_handle(), client.clone(), network.clone());
	}

	let enable_grandpa = !config.disable_grandpa;
	if enable_grandpa {
		let name = config.network.node_name.clone();

		let config = sc_finality_grandpa::Config {
			gossip_duration: std::time::Duration::from_millis(333),
			justification_period: 512,
			name: Some(name),
			observer_enabled: false,
			keystore: None,
			local_role: config.role.clone(),
			telemetry: telemetry.as_ref().map(|x| x.handle()),
		};

		task_manager.spawn_handle().spawn_blocking(
			"grandpa-observer",
			sc_finality_grandpa::run_grandpa_observer(config, grandpa_link, network.clone())?,
		);
	}

	sc_service::spawn_tasks(sc_service::SpawnTasksParams {
		remote_blockchain: Some(backend.remote_blockchain()),
		transaction_pool,
		task_manager: &mut task_manager,
		on_demand: Some(on_demand),
		rpc_extensions_builder: Box::new(|_, _| ()),
		config,
		client,
		keystore: keystore_container.sync_keystore(),
		backend,
		network,
		system_rpc_tx,
		telemetry: telemetry.as_mut(),
	})?;

	network_starter.start_network();
	Ok(task_manager)
}
/// Builds a new service for a light client.
Builds a new service for a light client.
Builds a new service for a light client .
pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError> {
	let telemetry = config
		.telemetry_endpoints
		.clone()
		.filter(|x| !x.is_empty())
		.map(|endpoints| -> Result<_, sc_telemetry::Error> {
			let worker = TelemetryWorker::new(16)?;
			let telemetry = worker.handle().new_telemetry(endpoints);
			Ok((worker, telemetry))
		})
		.transpose()?;
	let (client, backend, keystore_container, mut task_manager, on_demand) =
		sc_service::new_light_parts::<Block, RuntimeApi, Executor>(
			&config,
			telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
		)?;
	let mut telemetry = telemetry.map(|(worker, telemetry)| {
		task_manager.spawn_handle().spawn("telemetry", worker.run());
		telemetry
	});
	config
		.network
		.extra_sets
		.push(sc_finality_grandpa::grandpa_peers_set_config());
	let select_chain = sc_consensus::LongestChain::new(backend.clone());
	let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
		config.transaction_pool.clone(),
		config.prometheus_registry(),
		task_manager.spawn_essential_handle(),
		client.clone(),
		on_demand.clone(),
	));
	let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
		client.clone(),
		&(client.clone() as Arc<_>),
		select_chain,
		telemetry.as_ref().map(|x| x.handle()),
	)?;
	let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration();
	let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _, _>(ImportQueueParams {
		block_import: grandpa_block_import.clone(),
		justification_import: Some(Box::new(grandpa_block_import)),
		client: client.clone(),
		create_inherent_data_providers: move |_, ()| async move {
			let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
			let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
				*timestamp,
				slot_duration,
			);
			Ok((timestamp, slot))
		},
		spawner: &task_manager.spawn_essential_handle(),
		can_author_with: sp_consensus::NeverCanAuthor,
		registry: config.prometheus_registry(),
		check_for_equivocation: Default::default(),
		telemetry: telemetry.as_ref().map(|x| x.handle()),
	})?;
	let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams {
		config: &config,
		client: client.clone(),
		transaction_pool: transaction_pool.clone(),
		spawn_handle: task_manager.spawn_handle(),
		import_queue,
		on_demand: Some(on_demand.clone()),
		block_announce_validator_builder: None,
	})?;
	if config.offchain_worker.enabled {
		sc_service::build_offchain_workers(&config, task_manager.spawn_handle(), client.clone(), network.clone());
	}
	let enable_grandpa = !config.disable_grandpa;
	if enable_grandpa {
		let name = config.network.node_name.clone();
		let config = sc_finality_grandpa::Config {
			gossip_duration: std::time::Duration::from_millis(333),
			justification_period: 512,
			name: Some(name),
			observer_enabled: false,
			keystore: None,
			local_role: config.role.clone(),
			telemetry: telemetry.as_ref().map(|x| x.handle()),
		};
		task_manager.spawn_handle().spawn_blocking(
			"grandpa-observer",
			sc_finality_grandpa::run_grandpa_observer(config, grandpa_link, network.clone())?,
		);
	}
	sc_service::spawn_tasks(sc_service::SpawnTasksParams {
		remote_blockchain: Some(backend.remote_blockchain()),
		transaction_pool,
		task_manager: &mut task_manager,
		on_demand: Some(on_demand),
		rpc_extensions_builder: Box::new(|_, _| ()),
		config,
		client,
		keystore: keystore_container.sync_keystore(),
		backend,
		network,
		system_rpc_tx,
		telemetry: telemetry.as_mut(),
	})?;
	network_starter.start_network();
	Ok(task_manager)
}
pub fn new_light ( mut config : Configuration ) -> Result < TaskManager , ServiceError > { let telemetry = config . telemetry_endpoints . clone ( ) . filter ( | x | ! x . is_empty ( ) ) . map ( | endpoints | -> Result < _ , sc_telemetry :: Error > { let worker = TelemetryWorker :: new ( 16 ) ? ; let telemetry = worker . handle ( ) . new_telemetry ( endpoints ) ; Ok ( ( worker , telemetry ) ) } ) . transpose ( ) ? ; let ( client , backend , keystore_container , mut task_manager , on_demand ) = sc_service :: new_light_parts :: < Block , RuntimeApi , Executor > ( & config , telemetry . as_ref ( ) . map ( | ( _ , telemetry ) | telemetry . handle ( ) ) , ) ? ; let mut telemetry = telemetry . map ( | ( worker , telemetry ) | { task_manager . spawn_handle ( ) . spawn ( " " , worker . run ( ) ) ; telemetry } ) ; config . network . extra_sets . push ( sc_finality_grandpa :: grandpa_peers_set_config ( ) ) ; let select_chain = sc_consensus :: LongestChain :: new ( backend . clone ( ) ) ; let transaction_pool = Arc :: new ( sc_transaction_pool :: BasicPool :: new_light ( config . transaction_pool . clone ( ) , config . prometheus_registry ( ) , task_manager . spawn_essential_handle ( ) , client . clone ( ) , on_demand . clone ( ) , ) ) ; let ( grandpa_block_import , grandpa_link ) = sc_finality_grandpa :: block_import ( client . clone ( ) , & ( client . clone ( ) as Arc < _ > ) , select_chain , telemetry . as_ref ( ) . map ( | x | x . handle ( ) ) , ) ? ; let slot_duration = sc_consensus_aura :: slot_duration ( & * client ) ? . slot_duration ( ) ; let import_queue = sc_consensus_aura :: import_queue :: < AuraPair , _ , _ , _ , _ , _ , _ > ( ImportQueueParams { block_import : grandpa_block_import . clone ( ) , justification_import : Some ( Box :: new ( grandpa_block_import ) ) , client : client . clone ( ) , create_inherent_data_providers : move | _ , ( ) | async move { let timestamp = sp_timestamp :: InherentDataProvider :: from_system_time ( ) ; let slot = sp_consensus_aura :: inherents :: InherentDataProvider :: from_timestamp_and_duration ( * timestamp , slot_duration , ) ; Ok ( ( timestamp , slot ) ) } , spawner : & task_manager . spawn_essential_handle ( ) , can_author_with : sp_consensus :: NeverCanAuthor , registry : config . prometheus_registry ( ) , check_for_equivocation : Default :: default ( ) , telemetry : telemetry . as_ref ( ) . map ( | x | x . handle ( ) ) , } ) ? ; let ( network , system_rpc_tx , network_starter ) = sc_service :: build_network ( sc_service :: BuildNetworkParams { config : & config , client : client . clone ( ) , transaction_pool : transaction_pool . clone ( ) , spawn_handle : task_manager . spawn_handle ( ) , import_queue , on_demand : Some ( on_demand . clone ( ) ) , block_announce_validator_builder : None , } ) ? ; if config . offchain_worker . enabled { sc_service :: build_offchain_workers ( & config , task_manager . spawn_handle ( ) , client . clone ( ) , network . clone ( ) ) ; } let enable_grandpa = ! config . disable_grandpa ; if enable_grandpa { let name = config . network . node_name . clone ( ) ; let config = sc_finality_grandpa :: Config { gossip_duration : std :: time :: Duration :: from_millis ( 333 ) , justification_period : 512 , name : Some ( name ) , observer_enabled : false , keystore : None , local_role : config . role . clone ( ) , telemetry : telemetry . as_ref ( ) . map ( | x | x . handle ( ) ) , } ; task_manager . spawn_handle ( ) . spawn_blocking ( " " , sc_finality_grandpa :: run_grandpa_observer ( config , grandpa_link , network . clone ( ) ) ? , ) ; } sc_service :: spawn_tasks ( sc_service :: SpawnTasksParams { remote_blockchain : Some ( backend . remote_blockchain ( ) ) , transaction_pool , task_manager : & mut task_manager , on_demand : Some ( on_demand ) , rpc_extensions_builder : Box :: new ( | _ , _ | ( ) ) , config , client , keystore : keystore_container . sync_keystore ( ) , backend , network , system_rpc_tx , telemetry : telemetry . as_mut ( ) , } ) ? ; network_starter . start_network ( ) ; Ok ( task_manager ) }
Builds a new service for a light client.
Builds a new service for a light client .
config
Configuration
config
Configuration