pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError> {
    let (client, backend, keystore_container, mut task_manager, on_demand) =
        sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;

    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_handle(),
        client.clone(),
        on_demand.clone(),
    ));

    let (grandpa_block_import, _) = sc_finality_grandpa::block_import(
        client.clone(),
        &(client.clone() as Arc<_>),
        select_chain.clone(),
    )?;

    let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
        grandpa_block_import.clone(),
        client.clone(),
    );

    let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
        sc_consensus_aura::slot_duration(&*client)?,
        aura_block_import,
        Some(Box::new(grandpa_block_import)),
        client.clone(),
        InherentDataProviders::new(),
        &task_manager.spawn_handle(),
        config.prometheus_registry(),
        sp_consensus::NeverCanAuthor,
    )?;

    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: Some(on_demand.clone()),
            block_announce_validator_builder: None,
        })?;

    if config.offchain_worker.enabled {
        #[cfg(feature = "light-client")]
        {
            sp_keystore::SyncCryptoStore::sr25519_generate_new(
                &*keystore,
                runtime::client::KEY_TYPE,
                Some("//Alice"),
            )
            .expect("Creating key with account Alice should succeed.");
        }

        sc_service::build_offchain_workers(
            &config,
            backend.clone(),
            task_manager.spawn_handle(),
            client.clone(),
            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,
        network_status_sinks,
        system_rpc_tx,
    })?;

    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 (client, backend, keystore_container, mut task_manager, on_demand) =
        sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
    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_handle(),
        client.clone(),
        on_demand.clone(),
    ));
    let (grandpa_block_import, _) = sc_finality_grandpa::block_import(
        client.clone(),
        &(client.clone() as Arc<_>),
        select_chain.clone(),
    )?;
    let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
        grandpa_block_import.clone(),
        client.clone(),
    );
    let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
        sc_consensus_aura::slot_duration(&*client)?,
        aura_block_import,
        Some(Box::new(grandpa_block_import)),
        client.clone(),
        InherentDataProviders::new(),
        &task_manager.spawn_handle(),
        config.prometheus_registry(),
        sp_consensus::NeverCanAuthor,
    )?;
    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: Some(on_demand.clone()),
            block_announce_validator_builder: None,
        })?;
    if config.offchain_worker.enabled {
        #[cfg(feature = "light-client")]
        {
            sp_keystore::SyncCryptoStore::sr25519_generate_new(
                &*keystore,
                runtime::client::KEY_TYPE,
                Some("//Alice"),
            )
            .expect("Creating key with account Alice should succeed.");
        }
        sc_service::build_offchain_workers(
            &config,
            backend.clone(),
            task_manager.spawn_handle(),
            client.clone(),
            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,
        network_status_sinks,
        system_rpc_tx,
    })?;
    network_starter.start_network();
    Ok(task_manager)
}
pub fn new_light ( mut config : Configuration ) -> Result < TaskManager , ServiceError > { let ( client , backend , keystore_container , mut task_manager , on_demand ) = sc_service :: new_light_parts :: < Block , RuntimeApi , Executor > ( & config ) ? ; 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_handle ( ) , client . clone ( ) , on_demand . clone ( ) , ) ) ; let ( grandpa_block_import , _ ) = sc_finality_grandpa :: block_import ( client . clone ( ) , & ( client . clone ( ) as Arc < _ > ) , select_chain . clone ( ) , ) ? ; let aura_block_import = sc_consensus_aura :: AuraBlockImport :: < _ , _ , _ , AuraPair > :: new ( grandpa_block_import . clone ( ) , client . clone ( ) , ) ; let import_queue = sc_consensus_aura :: import_queue :: < _ , _ , _ , AuraPair , _ , _ > ( sc_consensus_aura :: slot_duration ( & * client ) ? , aura_block_import , Some ( Box :: new ( grandpa_block_import ) ) , client . clone ( ) , InherentDataProviders :: new ( ) , & task_manager . spawn_handle ( ) , config . prometheus_registry ( ) , sp_consensus :: NeverCanAuthor , ) ? ; 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 : Some ( on_demand . clone ( ) ) , block_announce_validator_builder : None , } ) ? ; if config . offchain_worker . enabled { # [ cfg ( feature " " ) ] { sp_keystore :: SyncCryptoStore :: sr25519_generate_new ( & * keystore , runtime :: client :: KEY_TYPE , Some ( " " ) , ) . expect ( " " ) ; } sc_service :: build_offchain_workers ( & config , backend . clone ( ) , task_manager . spawn_handle ( ) , client . clone ( ) , 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 , network_status_sinks , system_rpc_tx , } ) ? ; 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