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

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

    let select_chain = 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 finality_proof_import = grandpa_block_import.clone();

    let (babe_block_import, babe_link) = sc_consensus_babe::block_import(
        sc_consensus_babe::Config::get_or_compute(&*client)?,
        grandpa_block_import,
        client.clone(),
    )?;
    let inherent_data_providers = InherentDataProviders::new();

    // FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
    let import_queue = sc_consensus_babe::import_queue(
        babe_link,
        babe_block_import,
        Some(Box::new(finality_proof_import)),
        client.clone(),
        select_chain.clone(),
        inherent_data_providers.clone(),
        &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 {
        sc_service::build_offchain_workers(
            &config, backend.clone(), task_manager.spawn_handle(), client.clone(), network.clone(),
        );
    }

    let light_deps = crate::rpc::LightDeps {
        remote_blockchain: backend.remote_blockchain(),
        fetcher: on_demand.clone(),
        client: client.clone(),
        pool: transaction_pool.clone(),
    };

    let rpc_extensions = crate::rpc::create_light(light_deps);

    let _ = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
        on_demand: Some(on_demand),
        remote_blockchain: Some(backend.remote_blockchain()),
        rpc_extensions_builder: Box::new(sc_service::NoopRpcExtensionBuilder(rpc_extensions)),
        task_manager: &mut task_manager,
        config,
        keystore: keystore.sync_keystore(),
        backend,
        transaction_pool,
        client,
        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, mut task_manager, on_demand) =
        sc_service::new_light_parts::<Block, RuntimeApi, BitCountryExecutor>(&config)?;
    config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config());
    let select_chain = 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 finality_proof_import = grandpa_block_import.clone();
    let (babe_block_import, babe_link) = sc_consensus_babe::block_import(
        sc_consensus_babe::Config::get_or_compute(&*client)?,
        grandpa_block_import,
        client.clone(),
    )?;
    let inherent_data_providers = InherentDataProviders::new();
    // FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
    let import_queue = sc_consensus_babe::import_queue(
        babe_link,
        babe_block_import,
        Some(Box::new(finality_proof_import)),
        client.clone(),
        select_chain.clone(),
        inherent_data_providers.clone(),
        &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 {
        sc_service::build_offchain_workers(
            &config, backend.clone(), task_manager.spawn_handle(), client.clone(), network.clone(),
        );
    }
    let light_deps = crate::rpc::LightDeps {
        remote_blockchain: backend.remote_blockchain(),
        fetcher: on_demand.clone(),
        client: client.clone(),
        pool: transaction_pool.clone(),
    };
    let rpc_extensions = crate::rpc::create_light(light_deps);
    let _ = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
        on_demand: Some(on_demand),
        remote_blockchain: Some(backend.remote_blockchain()),
        rpc_extensions_builder: Box::new(sc_service::NoopRpcExtensionBuilder(rpc_extensions)),
        task_manager: &mut task_manager,
        config,
        keystore: keystore.sync_keystore(),
        backend,
        transaction_pool,
        client,
        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 , mut task_manager , on_demand ) = sc_service :: new_light_parts :: < Block , RuntimeApi , BitCountryExecutor > ( & config ) ? ; config . network . extra_sets . push ( sc_finality_grandpa :: grandpa_peers_set_config ( ) ) ; let select_chain = 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 finality_proof_import = grandpa_block_import . clone ( ) ; let ( babe_block_import , babe_link ) = sc_consensus_babe :: block_import ( sc_consensus_babe :: Config :: get_or_compute ( & * client ) ? , grandpa_block_import , client . clone ( ) , ) ? ; let inherent_data_providers = InherentDataProviders :: new ( ) ; // FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`. let import_queue = sc_consensus_babe :: import_queue ( babe_link , babe_block_import , Some ( Box :: new ( finality_proof_import ) ) , client . clone ( ) , select_chain . clone ( ) , inherent_data_providers . clone ( ) , & 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 { sc_service :: build_offchain_workers ( & config , backend . clone ( ) , task_manager . spawn_handle ( ) , client . clone ( ) , network . clone ( ) , ) ; } let light_deps = crate :: rpc :: LightDeps { remote_blockchain : backend . remote_blockchain ( ) , fetcher : on_demand . clone ( ) , client : client . clone ( ) , pool : transaction_pool . clone ( ) , } ; let rpc_extensions = crate :: rpc :: create_light ( light_deps ) ; let _ = sc_service :: spawn_tasks ( sc_service :: SpawnTasksParams { on_demand : Some ( on_demand ) , remote_blockchain : Some ( backend . remote_blockchain ( ) ) , rpc_extensions_builder : Box :: new ( sc_service :: NoopRpcExtensionBuilder ( rpc_extensions ) ) , task_manager : & mut task_manager , config , keystore : keystore . sync_keystore ( ) , backend , transaction_pool , client , 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