Skip to content

Commit

Permalink
peer_store: Simplify to include only logs in the ban threshold
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Apr 5, 2024
1 parent 404e48c commit b4ff3ea
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions substrate/client/network/src/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,34 +242,21 @@ impl PeerStoreInner {
peer_info.add_reputation(change.value);
let is_banned_now = peer_info.is_banned();

// Banned -> Unbanned.
if is_banned_before && !is_banned_now {
log::info!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}. Unbanned.",
peer_id,
change.value,
peer_info.reputation,
change.reason,
);

return
}

// Unbanned -> Banned.
// Disconnect the peer if the reputation is crossing the ban threshold.
if !is_banned_before && is_banned_now {
log::warn!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}. Banned, disconnecting.",
peer_id,
change.value,
peer_info.reputation,
change.reason,
);

if is_banned_now {
self.protocols.iter().for_each(|handle| handle.disconnect_peer(peer_id));

// Log warning only when reputation crosses the ban threshold.
if !is_banned_before {
log::warn!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}. Banned, disconnecting.",
peer_id,
change.value,
peer_info.reputation,
change.reason,
);
}

return
}

Expand Down

0 comments on commit b4ff3ea

Please sign in to comment.