Disable incoming light-client connections for minimal relay node (#2202)

When running with `--relay-chain-rpc-url` we received multiple reports
of high traffic that disappears when `--in-peers-light 0` is set. Indeed
it does not make much sense for light clients to connect to the minimal
node since it is not running the block announce protocol and the
request/response protocol for light clients.

This is intended to alleviate the traffic issues for now.

closes #1896
probably related https://github.com/paritytech/cumulus/issues/2563
This commit is contained in:
Sebastian Kunert
2023-11-07 17:21:24 +01:00
committed by GitHub
parent 44c7a5eb8c
commit 8ebb5c3319
@@ -19,7 +19,8 @@ use sp_runtime::traits::{Block as BlockT, NumberFor};
use sc_network::{ use sc_network::{
config::{ config::{
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig, NetworkConfiguration, NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake,
ProtocolId, SetConfig,
}, },
peer_store::PeerStore, peer_store::PeerStore,
NetworkService, NetworkService,
@@ -35,7 +36,7 @@ use std::{iter, sync::Arc};
/// Build the network service, the network status sinks and an RPC sender. /// Build the network service, the network status sinks and an RPC sender.
pub(crate) fn build_collator_network( pub(crate) fn build_collator_network(
config: &Configuration, config: &Configuration,
network_config: FullNetworkConfiguration, mut full_network_config: FullNetworkConfiguration,
spawn_handle: SpawnTaskHandle, spawn_handle: SpawnTaskHandle,
genesis_hash: Hash, genesis_hash: Hash,
best_header: Header, best_header: Header,
@@ -53,8 +54,12 @@ pub(crate) fn build_collator_network(
genesis_hash, genesis_hash,
); );
// Since this node has no syncing, we do not want light-clients to connect to it.
// Here we set any potential light-client slots to 0.
adjust_network_config_light_in_peers(&mut full_network_config.network_config);
let peer_store = PeerStore::new( let peer_store = PeerStore::new(
network_config full_network_config
.network_config .network_config
.boot_nodes .boot_nodes
.iter() .iter()
@@ -75,7 +80,7 @@ pub(crate) fn build_collator_network(
}) })
}, },
fork_id: None, fork_id: None,
network_config, network_config: full_network_config,
peer_store: peer_store_handle, peer_store: peer_store_handle,
genesis_hash, genesis_hash,
protocol_id, protocol_id,
@@ -114,6 +119,18 @@ pub(crate) fn build_collator_network(
Ok((network_service, network_starter, Box::new(SyncOracle {}))) Ok((network_service, network_starter, Box::new(SyncOracle {})))
} }
fn adjust_network_config_light_in_peers(config: &mut NetworkConfiguration) {
let light_client_in_peers = (config.default_peers_set.in_peers +
config.default_peers_set.out_peers)
.saturating_sub(config.default_peers_set_num_full);
if light_client_in_peers > 0 {
tracing::debug!(target: crate::LOG_TARGET, "Detected {light_client_in_peers} peer slots for light clients. Since this minimal node does support\
neither syncing nor light-client request/response, we are setting them to 0.");
}
config.default_peers_set.in_peers =
config.default_peers_set.in_peers.saturating_sub(light_client_in_peers);
}
struct SyncOracle; struct SyncOracle;
impl sp_consensus::SyncOracle for SyncOracle { impl sp_consensus::SyncOracle for SyncOracle {