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

Logs: add extra debug log for negative rep changes #1205

Merged
merged 9 commits into from
Sep 1, 2023
28 changes: 12 additions & 16 deletions polkadot/node/subsystem-util/src/reputation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{collections::HashMap, time::Duration};

/// Default delay for sending reputation changes
pub const REPUTATION_CHANGE_INTERVAL: Duration = Duration::from_secs(30);
const LOG_TARGET: &'static str = "parachain::reputation-aggregator";

type BatchReputationChange = HashMap<PeerId, i32>;

Expand Down Expand Up @@ -75,6 +76,10 @@ impl ReputationAggregator {
peer_id: PeerId,
rep: UnifiedReputationChange,
) {
if rep.cost_or_benefit() < 0 {
gum::debug!(target: LOG_TARGET, peer = ?peer_id, ?rep, "Modify reputation");
}
sandreim marked this conversation as resolved.
Show resolved Hide resolved

if (self.send_immediately_if)(rep) {
self.single_send(sender, peer_id, rep).await;
} else {
Expand All @@ -97,21 +102,12 @@ impl ReputationAggregator {
}

fn add(&mut self, peer_id: PeerId, rep: UnifiedReputationChange) {
if self.by_peer.is_none() {
self.by_peer = Some(HashMap::new());
}
if let Some(ref mut by_peer) = self.by_peer {
add_reputation(by_peer, peer_id, rep)
}
let cost = rep.cost_or_benefit();
sandreim marked this conversation as resolved.
Show resolved Hide resolved
self
.by_peer
.get_or_insert(HashMap::new())
.entry(peer_id)
.and_modify(|v| *v = v.saturating_add(cost))
.or_insert(cost);
}
}

/// Add a reputation change to an existing collection.
pub fn add_reputation(
acc: &mut BatchReputationChange,
peer_id: PeerId,
rep: UnifiedReputationChange,
) {
let cost = rep.cost_or_benefit();
acc.entry(peer_id).and_modify(|v| *v = v.saturating_add(cost)).or_insert(cost);
}