Skip to content

Commit 6227d9f

Browse files
committed
Don't disconnect peer in DHT if there's an active connection
1 parent 256f012 commit 6227d9f

File tree

1 file changed

+13
-1
lines changed
  • beacon_node/lighthouse_network/src/discovery

1 file changed

+13
-1
lines changed

beacon_node/lighthouse_network/src/discovery/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use libp2p::identity::{Keypair, PublicKey};
1818
use enr::{ATTESTATION_BITFIELD_ENR_KEY, ETH2_ENR_KEY, SYNC_COMMITTEE_BITFIELD_ENR_KEY};
1919
use futures::prelude::*;
2020
use futures::stream::FuturesUnordered;
21+
use libp2p::connection_limits::Exceeded;
2122
use libp2p::multiaddr::Protocol;
2223
use libp2p::swarm::behaviour::{DialFailure, FromSwarm};
2324
use libp2p::swarm::THandlerInEvent;
@@ -1156,8 +1157,19 @@ impl<E: EthSpec> Discovery<E> {
11561157
fn on_dial_failure(&mut self, peer_id: Option<PeerId>, error: &DialError) {
11571158
if let Some(peer_id) = peer_id {
11581159
match error {
1160+
DialError::Denied { cause } => {
1161+
if self.network_globals.peers.read().is_connected(&peer_id) {
1162+
// There's an active connection, so we don’t disconnect the peer.
1163+
// Lighthouse dials to a peer twice using TCP and QUIC (if QUIC is not
1164+
// disabled). Usually, one establishes a connection, and the other fails
1165+
// because the peer allows only one connection per peer.
1166+
return;
1167+
}
1168+
// set peer as disconnected in discovery DHT
1169+
debug!(self.log, "Marking peer disconnected in DHT"; "peer_id" => %peer_id, "error" => %ClearDialError(error));
1170+
self.disconnect_peer(&peer_id);
1171+
}
11591172
DialError::LocalPeerId { .. }
1160-
| DialError::Denied { .. }
11611173
| DialError::NoAddresses
11621174
| DialError::Transport(_)
11631175
| DialError::WrongPeerId { .. } => {

0 commit comments

Comments
 (0)