mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 04:21:06 +00:00
Split peer slots between full and light nodes (#10688)
* Split peer slots between full and light nodes * Rustfmt * Oops, accidentally removed a comma * Remove else
This commit is contained in:
@@ -86,9 +86,12 @@ pub struct NetworkParams {
|
|||||||
#[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")]
|
#[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")]
|
||||||
pub out_peers: u32,
|
pub out_peers: u32,
|
||||||
|
|
||||||
/// Specify the maximum number of incoming connections we're accepting.
|
/// Maximum number of inbound full nodes peers.
|
||||||
#[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")]
|
#[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")]
|
||||||
pub in_peers: u32,
|
pub in_peers: u32,
|
||||||
|
/// Maximum number of inbound light nodes peers.
|
||||||
|
#[structopt(long = "in-peers-light", value_name = "COUNT", default_value = "100")]
|
||||||
|
pub in_peers_light: u32,
|
||||||
|
|
||||||
/// Disable mDNS discovery.
|
/// Disable mDNS discovery.
|
||||||
///
|
///
|
||||||
@@ -203,7 +206,7 @@ impl NetworkParams {
|
|||||||
boot_nodes,
|
boot_nodes,
|
||||||
net_config_path,
|
net_config_path,
|
||||||
default_peers_set: SetConfig {
|
default_peers_set: SetConfig {
|
||||||
in_peers: self.in_peers,
|
in_peers: self.in_peers + self.in_peers_light,
|
||||||
out_peers: self.out_peers,
|
out_peers: self.out_peers,
|
||||||
reserved_nodes: self.reserved_nodes.clone(),
|
reserved_nodes: self.reserved_nodes.clone(),
|
||||||
non_reserved_mode: if self.reserved_only {
|
non_reserved_mode: if self.reserved_only {
|
||||||
@@ -212,6 +215,7 @@ impl NetworkParams {
|
|||||||
NonReservedPeerMode::Accept
|
NonReservedPeerMode::Accept
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
default_peers_set_num_full: self.in_peers + self.out_peers,
|
||||||
listen_addresses,
|
listen_addresses,
|
||||||
public_addresses,
|
public_addresses,
|
||||||
extra_sets: Vec::new(),
|
extra_sets: Vec::new(),
|
||||||
|
|||||||
@@ -416,6 +416,11 @@ pub struct NetworkConfiguration {
|
|||||||
pub request_response_protocols: Vec<RequestResponseConfig>,
|
pub request_response_protocols: Vec<RequestResponseConfig>,
|
||||||
/// Configuration for the default set of nodes used for block syncing and transactions.
|
/// Configuration for the default set of nodes used for block syncing and transactions.
|
||||||
pub default_peers_set: SetConfig,
|
pub default_peers_set: SetConfig,
|
||||||
|
/// Number of substreams to reserve for full nodes for block syncing and transactions.
|
||||||
|
/// Any other slot will be dedicated to light nodes.
|
||||||
|
///
|
||||||
|
/// This value is implicitly capped to `default_set.out_peers + default_set.in_peers`.
|
||||||
|
pub default_peers_set_num_full: u32,
|
||||||
/// Configuration for extra sets of nodes.
|
/// Configuration for extra sets of nodes.
|
||||||
pub extra_sets: Vec<NonDefaultSetConfig>,
|
pub extra_sets: Vec<NonDefaultSetConfig>,
|
||||||
/// Client identifier. Sent over the wire for debugging purposes.
|
/// Client identifier. Sent over the wire for debugging purposes.
|
||||||
@@ -473,6 +478,7 @@ impl NetworkConfiguration {
|
|||||||
node_key: NodeKeyConfig,
|
node_key: NodeKeyConfig,
|
||||||
net_config_path: Option<PathBuf>,
|
net_config_path: Option<PathBuf>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let default_peers_set = SetConfig::default();
|
||||||
Self {
|
Self {
|
||||||
net_config_path,
|
net_config_path,
|
||||||
listen_addresses: Vec::new(),
|
listen_addresses: Vec::new(),
|
||||||
@@ -480,7 +486,8 @@ impl NetworkConfiguration {
|
|||||||
boot_nodes: Vec::new(),
|
boot_nodes: Vec::new(),
|
||||||
node_key,
|
node_key,
|
||||||
request_response_protocols: Vec::new(),
|
request_response_protocols: Vec::new(),
|
||||||
default_peers_set: Default::default(),
|
default_peers_set_num_full: default_peers_set.in_peers + default_peers_set.out_peers,
|
||||||
|
default_peers_set,
|
||||||
extra_sets: Vec::new(),
|
extra_sets: Vec::new(),
|
||||||
client_version: client_version.into(),
|
client_version: client_version.into(),
|
||||||
node_name: node_name.into(),
|
node_name: node_name.into(),
|
||||||
|
|||||||
@@ -166,13 +166,19 @@ pub struct Protocol<B: BlockT> {
|
|||||||
pending_messages: VecDeque<CustomMessageOutcome<B>>,
|
pending_messages: VecDeque<CustomMessageOutcome<B>>,
|
||||||
config: ProtocolConfig,
|
config: ProtocolConfig,
|
||||||
genesis_hash: B::Hash,
|
genesis_hash: B::Hash,
|
||||||
|
/// State machine that handles the list of in-progress requests. Only full node peers are
|
||||||
|
/// registered.
|
||||||
sync: ChainSync<B>,
|
sync: ChainSync<B>,
|
||||||
// All connected peers
|
// All connected peers. Contains both full and light node peers.
|
||||||
peers: HashMap<PeerId, Peer<B>>,
|
peers: HashMap<PeerId, Peer<B>>,
|
||||||
chain: Arc<dyn Client<B>>,
|
chain: Arc<dyn Client<B>>,
|
||||||
/// List of nodes for which we perform additional logging because they are important for the
|
/// List of nodes for which we perform additional logging because they are important for the
|
||||||
/// user.
|
/// user.
|
||||||
important_peers: HashSet<PeerId>,
|
important_peers: HashSet<PeerId>,
|
||||||
|
/// Value that was passed as part of the configuration. Used to cap the number of full nodes.
|
||||||
|
default_peers_set_num_full: usize,
|
||||||
|
/// Number of slots to allocate to light nodes.
|
||||||
|
default_peers_set_num_light: usize,
|
||||||
/// Used to report reputation changes.
|
/// Used to report reputation changes.
|
||||||
peerset_handle: sc_peerset::PeersetHandle,
|
peerset_handle: sc_peerset::PeersetHandle,
|
||||||
/// Handles opening the unique substream and sending and receiving raw messages.
|
/// Handles opening the unique substream and sending and receiving raw messages.
|
||||||
@@ -428,6 +434,12 @@ impl<B: BlockT> Protocol<B> {
|
|||||||
genesis_hash: info.genesis_hash,
|
genesis_hash: info.genesis_hash,
|
||||||
sync,
|
sync,
|
||||||
important_peers,
|
important_peers,
|
||||||
|
default_peers_set_num_full: network_config.default_peers_set_num_full as usize,
|
||||||
|
default_peers_set_num_light: {
|
||||||
|
let total = network_config.default_peers_set.out_peers +
|
||||||
|
network_config.default_peers_set.in_peers;
|
||||||
|
total.saturating_sub(network_config.default_peers_set_num_full) as usize
|
||||||
|
},
|
||||||
peerset_handle: peerset_handle.clone(),
|
peerset_handle: peerset_handle.clone(),
|
||||||
behaviour,
|
behaviour,
|
||||||
notification_protocols: network_config
|
notification_protocols: network_config
|
||||||
@@ -808,6 +820,21 @@ impl<B: BlockT> Protocol<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if status.roles.is_full() && self.sync.num_peers() >= self.default_peers_set_num_full {
|
||||||
|
debug!(target: "sync", "Too many full nodes, rejecting {}", who);
|
||||||
|
self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC);
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
|
||||||
|
if status.roles.is_light() &&
|
||||||
|
(self.peers.len() - self.sync.num_peers()) < self.default_peers_set_num_light
|
||||||
|
{
|
||||||
|
// Make sure that not all slots are occupied by light clients.
|
||||||
|
debug!(target: "sync", "Too many light nodes, rejecting {}", who);
|
||||||
|
self.behaviour.disconnect_peer(&who, HARDCODED_PEERSETS_SYNC);
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
|
|
||||||
let peer = Peer {
|
let peer = Peer {
|
||||||
info: PeerInfo {
|
info: PeerInfo {
|
||||||
roles: status.roles,
|
roles: status.roles,
|
||||||
|
|||||||
@@ -648,6 +648,11 @@ impl<B: BlockT> ChainSync<B> {
|
|||||||
self.downloaded_blocks
|
self.downloaded_blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the current number of peers stored within this state machine.
|
||||||
|
pub fn num_peers(&self) -> usize {
|
||||||
|
self.peers.len()
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle a new connected peer.
|
/// Handle a new connected peer.
|
||||||
///
|
///
|
||||||
/// Call this method whenever we connect to a new peer.
|
/// Call this method whenever we connect to a new peer.
|
||||||
|
|||||||
@@ -808,8 +808,7 @@ where
|
|||||||
let (handler, protocol_config) = StateRequestHandler::new(
|
let (handler, protocol_config) = StateRequestHandler::new(
|
||||||
&protocol_id,
|
&protocol_id,
|
||||||
client.clone(),
|
client.clone(),
|
||||||
config.network.default_peers_set.in_peers as usize +
|
config.network.default_peers_set_num_full as usize,
|
||||||
config.network.default_peers_set.out_peers as usize,
|
|
||||||
);
|
);
|
||||||
spawn_handle.spawn("state-request-handler", Some("networking"), handler.run());
|
spawn_handle.spawn("state-request-handler", Some("networking"), handler.run());
|
||||||
protocol_config
|
protocol_config
|
||||||
|
|||||||
Reference in New Issue
Block a user