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:
Pierre Krieger
2021-03-22 17:51:57 +01:00
committed by GitHub
parent 80ba1f2cda
commit 3edfdead0f
2 changed files with 63 additions and 48 deletions
+6 -3
View File
@@ -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);
}