Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peer_store: Warn only on reputation crossing the ban threshold #4000

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions substrate/client/network/src/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,37 @@ impl PeerStoreInner {

fn report_peer(&mut self, peer_id: PeerId, change: ReputationChange) {
let peer_info = self.peers.entry(peer_id).or_default();

let is_banned_before = peer_info.is_banned();
peer_info.add_reputation(change.value);
let is_banned_now = peer_info.is_banned();

if peer_info.reputation < BANNED_THRESHOLD {
if is_banned_now {
self.protocols.iter().for_each(|handle| handle.disconnect_peer(peer_id));

log::warn!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}. Banned, disconnecting.",
peer_id,
change.value,
peer_info.reputation,
change.reason,
);
} else {
log::trace!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}.",
peer_id,
change.value,
peer_info.reputation,
change.reason,
);
// 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
}
}

log::trace!(
target: LOG_TARGET,
"Report {}: {:+} to {}. Reason: {}.{}",
peer_id,
change.value,
peer_info.reputation,
change.reason,
if is_banned_now { " Banned, disconnecting." } else { "" },
);
}

fn set_peer_role(&mut self, peer_id: &PeerId, role: ObservedRole) {
Expand Down
Loading