Skip to content

Commit

Permalink
Disable incoming light-client connections for minimal relay node (#2202)
Browse files Browse the repository at this point in the history
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 paritytech/cumulus#2563
  • Loading branch information
skunert authored Nov 7, 2023
1 parent 44c7a5e commit 8ebb5c3
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cumulus/client/relay-chain-minimal-node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use sp_runtime::traits::{Block as BlockT, NumberFor};

use sc_network::{
config::{
NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake, ProtocolId, SetConfig,
NetworkConfiguration, NonDefaultSetConfig, NonReservedPeerMode, NotificationHandshake,
ProtocolId, SetConfig,
},
peer_store::PeerStore,
NetworkService,
Expand All @@ -35,7 +36,7 @@ use std::{iter, sync::Arc};
/// Build the network service, the network status sinks and an RPC sender.
pub(crate) fn build_collator_network(
config: &Configuration,
network_config: FullNetworkConfiguration,
mut full_network_config: FullNetworkConfiguration,
spawn_handle: SpawnTaskHandle,
genesis_hash: Hash,
best_header: Header,
Expand All @@ -53,8 +54,12 @@ pub(crate) fn build_collator_network(
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(
network_config
full_network_config
.network_config
.boot_nodes
.iter()
Expand All @@ -75,7 +80,7 @@ pub(crate) fn build_collator_network(
})
},
fork_id: None,
network_config,
network_config: full_network_config,
peer_store: peer_store_handle,
genesis_hash,
protocol_id,
Expand Down Expand Up @@ -114,6 +119,18 @@ pub(crate) fn build_collator_network(
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;

impl sp_consensus::SyncOracle for SyncOracle {
Expand Down

0 comments on commit 8ebb5c3

Please sign in to comment.