mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 02:21:03 +00:00
Optimize the peerset a bit (#8416)
* Only allocate slots for the relevant peer set * Do a pre-check before calling has_free_outgoing_slot * Oops, fix infinite loop
This commit is contained in:
@@ -283,6 +283,11 @@ impl PeersState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if there is a free outgoing slot available related to this set.
|
||||
pub fn has_free_outgoing_slot(&self, set: usize) -> bool {
|
||||
self.sets[set].num_out < self.sets[set].max_out
|
||||
}
|
||||
|
||||
/// Add a node to the list of nodes that don't occupy slots.
|
||||
///
|
||||
/// Has no effect if the node was already in the group.
|
||||
@@ -506,9 +511,7 @@ impl<'a> NotConnectedPeer<'a> {
|
||||
|
||||
// Note that it is possible for num_out to be strictly superior to the max, in case we were
|
||||
// connected to reserved node then marked them as not reserved.
|
||||
if self.state.sets[self.set].num_out >= self.state.sets[self.set].max_out
|
||||
&& !is_no_slot_occupy
|
||||
{
|
||||
if !self.state.has_free_outgoing_slot(self.set) && !is_no_slot_occupy {
|
||||
return Err(self);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user