/// Builds a new service for a full client.
Builds a new service for a full client.
Builds a new service for a full client .
pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError> {
	let sc_service::PartialComponents {
		client,
		backend,
		mut task_manager,
		import_queue,
		mut keystore_container,
		select_chain,
		transaction_pool,
		other: (block_import, grandpa_link, mut telemetry),
	} = new_partial(&config)?;
	let (network, network_status_sinks, 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: None,
			warp_sync,
			block_announce_validator_builder: None,
		})?;
	if config.offchain_worker.enabled {
		sc_service::build_offchain_workers(
			&config,
			backend.clone(),
			task_manager.spawn_handle(),
			client.clone(),
			network.clone(),
		);
	}
	let is_authority = config.role.is_authority();
	let prometheus_registry = config.prometheus_registry().cloned();
	sc_service::spawn_tasks(sc_service::SpawnTasksParams {
		network: network.clone(),
		client: client.clone(),
		keystore: keystore_container.sync_keystore(),
		task_manager: &mut task_manager,
		transaction_pool: transaction_pool.clone(),
		rpc_extensions_builder: Box::new(|_, _| ()),
		on_demand: None,
		remote_blockchain: None,
		backend,
		telemetry,
		//network_status_sinks,
		system_rpc_tx,
		config,
	})?;
	if is_authority {
		let proposer = sc_basic_authorship::ProposerFactory::new(
			task_manager.spawn_handle(),
			client.clone(),
			transaction_pool,
			prometheus_registry.as_ref(),
		);
		let can_author_with =
			sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
		// Parameter details:
		//   https://substrate.dev/rustdocs/v3.0.0/sc_consensus_pow/fn.start_mining_worker.html
		// Also refer to kulupu config:
		//   https://github.com/kulupu/kulupu/blob/master/src/service.rs
		let (_worker, worker_task) = sc_consensus_pow::start_mining_worker(
			Box::new(pow_block_import),
			client,
			select_chain,
			MinimalSha3Algorithm,
			proposer,
			network,
			None,
			inherent_data_providers,
			// time to wait for a new block before starting to mine a new one
			Duration::from_secs(10),
			// how long to take to actually build the block (i.e. executing extrinsics)
			Duration::from_secs(10),
			can_author_with,
		);
		task_manager
			.spawn_essential_handle()
			.spawn_blocking("pow", worker_task);
		// Start Mining
		let mut nonce: U256 = U256::from(0);
		thread::spawn(move || loop {
			let worker = _worker.clone();
			let metadata = worker.lock().metadata();
			if let Some(metadata) = metadata {
				let compute = Compute {
					difficulty: metadata.difficulty,
					pre_hash: metadata.pre_hash,
					nonce,
				};
				let seal = compute.compute();
				if hash_meets_difficulty(&seal.work, seal.difficulty) {
					nonce = U256::from(0);
					let mut worker = worker.lock();
					worker.submit(seal.encode());
				} else {
					nonce = nonce.saturating_add(U256::from(1));
					if nonce == U256::MAX {
						nonce = U256::from(0);
					}
				}
			} else {
				thread::sleep(Duration::new(1, 0));
			}
		});
	}
	network_starter.start_network();
	Ok(task_manager)
}
pub fn new_full ( mut config : Configuration ) -> Result < TaskManager , ServiceError > { let sc_service :: PartialComponents { client , backend , mut task_manager , import_queue , mut keystore_container , select_chain , transaction_pool , other : ( block_import , grandpa_link , mut telemetry ) , } = new_partial ( & config ) ? ; let ( network , network_status_sinks , 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 : None , warp_sync , block_announce_validator_builder : None , } ) ? ; if config . offchain_worker . enabled { sc_service :: build_offchain_workers ( & config , backend . clone ( ) , task_manager . spawn_handle ( ) , client . clone ( ) , network . clone ( ) , ) ; } let is_authority = config . role . is_authority ( ) ; let prometheus_registry = config . prometheus_registry ( ) . cloned ( ) ; sc_service :: spawn_tasks ( sc_service :: SpawnTasksParams { network : network . clone ( ) , client : client . clone ( ) , keystore : keystore_container . sync_keystore ( ) , task_manager : & mut task_manager , transaction_pool : transaction_pool . clone ( ) , rpc_extensions_builder : Box :: new ( | _ , _ | ( ) ) , on_demand : None , remote_blockchain : None , backend , telemetry , //network_status_sinks, system_rpc_tx , config , } ) ? ; if is_authority { let proposer = sc_basic_authorship :: ProposerFactory :: new ( task_manager . spawn_handle ( ) , client . clone ( ) , transaction_pool , prometheus_registry . as_ref ( ) , ) ; let can_author_with = sp_consensus :: CanAuthorWithNativeVersion :: new ( client . executor ( ) . clone ( ) ) ; // Parameter details: //   https://substrate.dev/rustdocs/v3.0.0/sc_consensus_pow/fn.start_mining_worker.html // Also refer to kulupu config: //   https://github.com/kulupu/kulupu/blob/master/src/service.rs let ( _worker , worker_task ) = sc_consensus_pow :: start_mining_worker ( Box :: new ( pow_block_import ) , client , select_chain , MinimalSha3Algorithm , proposer , network , None , inherent_data_providers , // time to wait for a new block before starting to mine a new one Duration :: from_secs ( 10 ) , // how long to take to actually build the block (i.e. executing extrinsics) Duration :: from_secs ( 10 ) , can_author_with , ) ; task_manager . spawn_essential_handle ( ) . spawn_blocking ( " " , worker_task ) ; // Start Mining let mut nonce : U256 = U256 :: from ( 0 ) ; thread :: spawn ( move | | loop { let worker = _worker . clone ( ) ; let metadata = worker . lock ( ) . metadata ( ) ; if let Some ( metadata ) = metadata { let compute = Compute { difficulty : metadata . difficulty , pre_hash : metadata . pre_hash , nonce , } ; let seal = compute . compute ( ) ; if hash_meets_difficulty ( & seal . work , seal . difficulty ) { nonce = U256 :: from ( 0 ) ; let mut worker = worker . lock ( ) ; worker . submit ( seal . encode ( ) ) ; } else { nonce = nonce . saturating_add ( U256 :: from ( 1 ) ) ; if nonce == U256 :: MAX { nonce = U256 :: from ( 0 ) ; } } } else { thread :: sleep ( Duration :: new ( 1 , 0 ) ) ; } } ) ; } network_starter . start_network ( ) ; Ok ( task_manager ) }
Builds a new service for a full client.
Builds a new service for a full client .
config
Configuration