Skip to content

Commit

Permalink
re-revert optimistic peer reconnect (#1010)
Browse files Browse the repository at this point in the history
@xgreenx was right, we already do the peer reconnect on on
[PeerDisconnect](https://github.com/FuelLabs/fuel-core/blob/master/crates/services/p2p/src/peer_manager.rs#L72)
  • Loading branch information
leviathanbeak committed Feb 13, 2023
1 parent 361877c commit e54050a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
9 changes: 1 addition & 8 deletions crates/services/p2p/src/p2p_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,9 @@ impl<Codec: NetworkCodec> FuelP2PService<Codec> {
}
return Some(FuelP2PEvent::PeerDisconnected(peer_id))
}
PeerInfoEvent::TooManyPeers {
peer_to_disconnect,
peer_to_connect,
} => {
PeerInfoEvent::TooManyPeers { peer_to_disconnect } => {
// disconnect the surplus peer
let _ = self.swarm.disconnect_peer_id(peer_to_disconnect);
// reconnect the reserved peer
if let Some(peer_id) = peer_to_connect {
let _ = self.swarm.dial(peer_id);
}
}
},
FuelBehaviourEvent::RequestResponse(req_res_event) => match req_res_event {
Expand Down
9 changes: 0 additions & 9 deletions crates/services/p2p/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub enum PeerInfoEvent {
},
TooManyPeers {
peer_to_disconnect: PeerId,
peer_to_connect: Option<PeerId>,
},
ReconnectToPeer(PeerId),
PeerIdentified {
Expand Down Expand Up @@ -596,13 +595,6 @@ impl PeerManager {
.filter(|peer_id| !self.reserved_connected_peers.contains_key(peer_id))
}

fn find_disconnected_reserved_peer(&self) -> Option<PeerId> {
self.reserved_peers
.iter()
.find(|peer_id| self.reserved_connected_peers.contains_key(peer_id))
.cloned()
}

/// Handles the first connnection established with a Peer
fn handle_initial_connection(&mut self, peer_id: PeerId) {
let non_reserved_peers_connected = self.non_reserved_connected_peers.len();
Expand All @@ -614,7 +606,6 @@ impl PeerManager {
// Too many peers already connected, disconnect the Peer with the first priority.
self.pending_events.push_front(PeerInfoEvent::TooManyPeers {
peer_to_disconnect: peer_id,
peer_to_connect: self.find_disconnected_reserved_peer(),
});

// early exit, we don't want to report new peer connection
Expand Down

0 comments on commit e54050a

Please sign in to comment.