Skip to content

Do not disconnect from preferred peers when there is enough outbound#3914

Open
ardocrat wants to merge 1 commit into
mimblewimble:stagingfrom
ardocrat:preferred_peers_priority
Open

Do not disconnect from preferred peers when there is enough outbound#3914
ardocrat wants to merge 1 commit into
mimblewimble:stagingfrom
ardocrat:preferred_peers_priority

Conversation

@ardocrat

Copy link
Copy Markdown
Contributor
  • 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
@wiesche89 wiesche89 self-requested a review July 15, 2026 15:39
Comment thread p2p/src/serv.rs
)?;
if self.peers.enough_outbound_peers() {
peer.stop();
if self.peers.enough_outbound_peers()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, also this method is called for inbound, so enough_outbound must be provided as optional check to skip

Comment thread p2p/src/peers.rs
Some(peer) => {
warn!("disconnecting peer {} ({})", peer_addr, reason);
peer.stop();
peer.stop("disconnect_peer");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the existing reason to stop() here instead of replacing it with "disconnect_peer"?

Comment thread p2p/src/peers.rs
// Mark peer as defunct after ping failure.
let _ = self.update_state(p.info.addr, State::Defunct);
p.stop();
p.stop("Error pinging");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants