Do not disconnect from preferred peers when there is enough outbound#3914
Do not disconnect from preferred peers when there is enough outbound#3914ardocrat wants to merge 1 commit into
Conversation
ardocrat
commented
Jul 15, 2026
- check if peer is preferred after connection to not disconnect if its preferred
- add logging of reason to stop peer
…ound peers, add logging for peer stop reason
| )?; | ||
| if self.peers.enough_outbound_peers() { | ||
| peer.stop(); | ||
| if self.peers.enough_outbound_peers() |
There was a problem hiding this comment.
Peers::add_connected() still skips outbound peers when enough_outbound_peers() is true, so the preferred peer is not retained in the connected-peer map. Also, monitor_peers() only explicitly queues preferred peers while !enough_outbound, which can delay reconnects at full capacity. Could we fix the admission path here and handle reconnects in a follow-up?
There was a problem hiding this comment.
yes, also this method is called for inbound, so enough_outbound must be provided as optional check to skip
| Some(peer) => { | ||
| warn!("disconnecting peer {} ({})", peer_addr, reason); | ||
| peer.stop(); | ||
| peer.stop("disconnect_peer"); |
There was a problem hiding this comment.
Can we pass the existing reason to stop() here instead of replacing it with "disconnect_peer"?
| // Mark peer as defunct after ping failure. | ||
| let _ = self.update_state(p.info.addr, State::Defunct); | ||
| p.stop(); | ||
| p.stop("Error pinging"); |
There was a problem hiding this comment.
could we keep the new reason strings consistently lowercase and descriptive, e.g. ping error? They currently mix styles such as Error pinging, error broadcast, and clean peers.