Skip to content

Commit 03be2b5

Browse files
committed
Ensure disconnecting peers are added to the peerdb (#2451)
1 parent a3730cd commit 03be2b5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

beacon_node/eth2_libp2p/src/peer_manager/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
319319
self.network_globals
320320
.peers
321321
.write()
322-
.notify_disconnecting(&peer_id, true);
322+
.notify_disconnecting(peer_id, true);
323323
return;
324324
}
325325

@@ -339,7 +339,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
339339
self.network_globals
340340
.peers
341341
.write()
342-
.notify_disconnecting(&peer_id, false);
342+
.notify_disconnecting(peer_id, false);
343343
return;
344344
}
345345

@@ -1023,7 +1023,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
10231023

10241024
let mut peer_db = self.network_globals.peers.write();
10251025
for peer_id in disconnecting_peers {
1026-
peer_db.notify_disconnecting(&peer_id, false);
1026+
peer_db.notify_disconnecting(peer_id, false);
10271027
self.events.push(PeerManagerEvent::DisconnectPeer(
10281028
peer_id,
10291029
GoodbyeReason::TooManyPeers,

beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
475475

476476
/// Notifies the peer manager that the peer is undergoing a normal disconnect. Optionally tag
477477
/// the peer to be banned after the disconnect.
478-
pub fn notify_disconnecting(&mut self, peer_id: &PeerId, to_ban_afterwards: bool) {
479-
if let Some(info) = self.peers.get_mut(peer_id) {
480-
info.disconnecting(to_ban_afterwards);
481-
}
478+
pub fn notify_disconnecting(&mut self, peer_id: PeerId, to_ban_afterwards: bool) {
479+
self.peers
480+
.entry(peer_id)
481+
.or_default()
482+
.disconnecting(to_ban_afterwards);
482483
}
483484

484485
/// Marks a peer to be disconnected and then banned.

0 commit comments

Comments
 (0)