Skip to content

Commit 6e729d9

Browse files
fix: only apply and log p3 and p6 when they are not zero
Pull-Request: #6097.
1 parent 37040ee commit 6e729d9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

protocols/gossipsub/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Remove `Rpc` from the public API.
44
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)
5+
- Fix applying P3 and P6 Score penalties when their weight is zero
6+
See [PR 6097](https://github.com/libp2p/rust-libp2p/pull/6097)
57

68
## 0.49.0
79

protocols/gossipsub/src/peer_score.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ impl PeerScore {
311311
if topic_stats.mesh_message_deliveries_active
312312
&& topic_stats.mesh_message_deliveries
313313
< topic_params.mesh_message_deliveries_threshold
314+
&& topic_params.mesh_message_deliveries_weight != 0.0
314315
{
315316
let deficit = topic_params.mesh_message_deliveries_threshold
316317
- topic_stats.mesh_message_deliveries;
317318
let p3 = deficit * deficit;
318-
topic_score += p3 * topic_params.mesh_message_deliveries_weight;
319+
let penalty = p3 * topic_params.mesh_message_deliveries_weight;
320+
321+
topic_score += penalty;
319322
#[cfg(feature = "metrics")]
320323
report
321324
.penalties
@@ -324,7 +327,7 @@ impl PeerScore {
324327
peer=%peer_id,
325328
%topic,
326329
%deficit,
327-
penalty=%topic_score,
330+
penalty=%penalty,
328331
"[Penalty] The peer has a mesh deliveries deficit and will be penalized"
329332
);
330333
}
@@ -367,7 +370,9 @@ impl PeerScore {
367370
// addr. It is quadratic, and the weight is negative (validated by
368371
// peer_score_params.validate()).
369372
if let Some(peers_in_ip) = self.peer_ips.get(ip).map(|peers| peers.len()) {
370-
if (peers_in_ip as f64) > self.params.ip_colocation_factor_threshold {
373+
if (peers_in_ip as f64) > self.params.ip_colocation_factor_threshold
374+
&& self.params.ip_colocation_factor_weight != 0.0
375+
{
371376
let surplus = (peers_in_ip as f64) - self.params.ip_colocation_factor_threshold;
372377
let p6 = surplus * surplus;
373378
#[cfg(feature = "metrics")]

0 commit comments

Comments
 (0)