Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[WIP do not merge] Companion for substrate #10514 #4701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions node/network/protocol/src/peer_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! All peersets and protocols used for parachains.

use sc_network::config::{NonDefaultSetConfig, SetConfig};
use sc_network::config::{NonDefaultSetConfig, NonReservedPeerMode, SetConfig};
use std::{
borrow::Cow,
ops::{Index, IndexMut},
Expand Down Expand Up @@ -52,40 +52,30 @@ impl PeerSet {
pub fn get_info(self, is_authority: IsAuthority) -> NonDefaultSetConfig {
let protocol = self.into_protocol_name();
let max_notification_size = 100 * 1024;

match self {
PeerSet::Validation => NonDefaultSetConfig {
notifications_protocol: protocol,
fallback_names: Vec::new(),
max_notification_size,
set_config: sc_network::config::SetConfig {
// we allow full nodes to connect to validators for gossip
// to ensure any `MIN_GOSSIP_PEERS` always include reserved peers
// we limit the amount of non-reserved slots to be less
// than `MIN_GOSSIP_PEERS` in total
in_peers: super::MIN_GOSSIP_PEERS as u32 / 2 - 1,
out_peers: super::MIN_GOSSIP_PEERS as u32 / 2 - 1,
reserved_nodes: Vec::new(),
non_reserved_mode: sc_network::config::NonReservedPeerMode::Accept,
},
let set_config = match self {
PeerSet::Validation => SetConfig {
// we allow full nodes to connect to validators for gossip
// to ensure any `MIN_GOSSIP_PEERS` always include reserved peers
// we limit the amount of non-reserved slots to be less
// than `MIN_GOSSIP_PEERS` in total
in_peers: super::MIN_GOSSIP_PEERS as u32 / 2 - 1,
out_peers: super::MIN_GOSSIP_PEERS as u32 / 2 - 1,
reserved_nodes: Vec::new(),
non_reserved_mode: NonReservedPeerMode::Accept,
},
PeerSet::Collation => NonDefaultSetConfig {
notifications_protocol: protocol,
fallback_names: Vec::new(),
max_notification_size,
set_config: SetConfig {
// Non-authority nodes don't need to accept incoming connections on this peer set:
in_peers: if is_authority == IsAuthority::Yes { 100 } else { 0 },
out_peers: 0,
reserved_nodes: Vec::new(),
non_reserved_mode: if is_authority == IsAuthority::Yes {
sc_network::config::NonReservedPeerMode::Accept
} else {
sc_network::config::NonReservedPeerMode::Deny
},
PeerSet::Collation => SetConfig {
// Non-authority nodes don't need to accept incoming connections on this peer set:
in_peers: if is_authority == IsAuthority::Yes { 100 } else { 0 },
out_peers: 0,
reserved_nodes: Vec::new(),
non_reserved_mode: if is_authority == IsAuthority::Yes {
NonReservedPeerMode::Accept
} else {
NonReservedPeerMode::Deny
},
},
}
};
NonDefaultSetConfig::new(protocol, max_notification_size).with_config(set_config)
}

/// Get the protocol name associated with each peer set as static str.
Expand Down Expand Up @@ -141,6 +131,6 @@ impl<T> IndexMut<PeerSet> for PerPeerSet<T> {
///
/// Should be used during network configuration (added to [`NetworkConfiguration::extra_sets`])
/// or shortly after startup to register the protocols with the network service.
pub fn peer_sets_info(is_authority: IsAuthority) -> Vec<sc_network::config::NonDefaultSetConfig> {
pub fn peer_sets_info(is_authority: IsAuthority) -> Vec<NonDefaultSetConfig> {
PeerSet::iter().map(|s| s.get_info(is_authority)).collect()
}