Module network_service

Source
Expand description

Background network service.

The NetworkService manages background tasks dedicated to connecting to other nodes. Importantly, its design is oriented towards the particular use case of the light client.

The NetworkService spawns one background task (using PlatformRef::spawn_task) for each active connection.

The objective of the NetworkService in general is to try stay connected as much as possible to the nodes of the peer-to-peer network of the chain, and maintain open substreams with them in order to send out requests (e.g. block requests) and notifications (e.g. block announces).

Connectivity to the network is performed in the background as an implementation detail of the service. The public API only allows emitting requests and notifications towards the already-connected nodes.

After a NetworkService is created, one can add chains using NetworkService::add_chain. If all references to a NetworkServiceChain are destroyed, the chain is automatically purged.

An important part of the API is the list of channel receivers of Event returned by NetworkServiceChain::subscribe. These channels inform the foreground about updates to the network connectivity.

Structs§

CallProofRequestConfig
Description of a call proof request that can be sent to a peer.
ChainId
Identifier of a chain added through ChainNetwork::add_chain.
Config
Configuration for a NetworkService.
ConfigChain
See NetworkService::add_chain.
EncodedMerkleProof
Undecoded but valid Merkle proof.
NetworkService
NetworkServiceChain
PeerId
Identifier of a node of the network.

Enums§

BanSeverity
Severity of a ban. See NetworkServiceChain::ban_and_disconnect.
BlocksRequestError
Error returned by NetworkServiceChain::blocks_request.
CallProofRequestError
Error returned by NetworkServiceChain::call_proof_request.
Event
Event that can happen on the network service.
QueueNotificationError
Error potentially returned when queueing a notification.
Role
Role a node reports playing on the network.
StorageProofRequestError
Error returned by NetworkServiceChain::storage_proof_request.
WarpSyncRequestError
Error returned by NetworkServiceChain::grandpa_warp_sync_request.