Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 77f1089

Browse files
authored
Show reputation changes when dropping peer (#7655)
* Show reputation changes when dropping peer * Print all
1 parent e4ae38b commit 77f1089

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

client/peerset/src/lib.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl PeersetHandle {
103103
pub fn set_reserved_only(&self, reserved: bool) {
104104
let _ = self.tx.unbounded_send(Action::SetReservedOnly(reserved));
105105
}
106-
106+
107107
/// Set reserved peers to the new set.
108108
pub fn set_reserved_peers(&self, peer_ids: HashSet<PeerId>) {
109109
let _ = self.tx.unbounded_send(Action::SetReservedPeers(peer_ids));
@@ -252,7 +252,7 @@ impl Peerset {
252252
fn on_remove_reserved_peer(&mut self, peer_id: PeerId) {
253253
self.on_remove_from_priority_group(RESERVED_NODES, peer_id);
254254
}
255-
255+
256256
fn on_set_reserved_peers(&mut self, peer_ids: HashSet<PeerId>) {
257257
self.on_set_priority_group(RESERVED_NODES, peer_ids);
258258
}
@@ -357,8 +357,18 @@ impl Peerset {
357357
);
358358
}
359359
},
360-
peersstate::Peer::NotConnected(mut peer) => peer.add_reputation(change.value),
361-
peersstate::Peer::Unknown(peer) => peer.discover().add_reputation(change.value),
360+
peersstate::Peer::NotConnected(mut peer) => {
361+
trace!(target: "peerset", "Report {}: {:+} to {}. Reason: {}",
362+
peer_id, change.value, peer.reputation(), change.reason
363+
);
364+
peer.add_reputation(change.value)
365+
},
366+
peersstate::Peer::Unknown(peer) => {
367+
trace!(target: "peerset", "Discover {}: {:+}. Reason: {}",
368+
peer_id, change.value, change.reason
369+
);
370+
peer.discover().add_reputation(change.value)
371+
},
362372
}
363373
}
364374

@@ -555,15 +565,15 @@ impl Peerset {
555565
/// Must only be called after the PSM has either generated a `Connect` message with this
556566
/// `PeerId`, or accepted an incoming connection with this `PeerId`.
557567
pub fn dropped(&mut self, peer_id: PeerId) {
558-
trace!(target: "peerset", "Dropping {:?}", peer_id);
559-
560568
// We want reputations to be up-to-date before adjusting them.
561569
self.update_time();
562570

563571
match self.data.peer(&peer_id) {
564572
peersstate::Peer::Connected(mut entry) => {
565573
// Decrease the node's reputation so that we don't try it again and again and again.
566574
entry.add_reputation(DISCONNECT_REPUTATION_CHANGE);
575+
trace!(target: "peerset", "Dropping {}: {:+} to {}",
576+
peer_id, DISCONNECT_REPUTATION_CHANGE, entry.reputation());
567577
entry.disconnect();
568578
}
569579
peersstate::Peer::NotConnected(_) | peersstate::Peer::Unknown(_) =>

0 commit comments

Comments
 (0)