diff --git a/src/lib_gossipsub/gossipsub_intf.ml b/src/lib_gossipsub/gossipsub_intf.ml index d20d33b54c9ea47c7b1bc1e3faf1ab2feab8c74c..572d0adb843523f83025d3498c32adfc8b4c381e 100644 --- a/src/lib_gossipsub/gossipsub_intf.ml +++ b/src/lib_gossipsub/gossipsub_intf.ml @@ -163,10 +163,16 @@ type ('topic, 'span) topic_score_parameters = (* N.B.: unlike the Go/Rust implementations, scores are not refreshed in an asynchronous loop but rather in the heartbeat. Hence, we do not have the [decay_interval] parameter. - Scores are refreshed and decayed every [score_cleanup_ticks] heartbeats (see [limits]). *) + Scores are refreshed and decayed every [score_cleanup_ticks] heartbeats (see [limits]). + + TODO: https://gitlab.com/tezos/tezos/-/issues/5545 + We did not implement P6, aka IP colocation factor *) type ('topic, 'span) score_parameters = { topics : ('topic, 'span) topic_score_parameters; (** Per-topic score parameters. *) + topic_score_cap : float option; + (** An optional cap on the total positive contribution of topics to the score of the peer. + If not equal to [None], must be non-negative. *) behaviour_penalty_weight : float; (** P7: The weight of the score associated to the behaviour penalty. This parameter must be negative. *) diff --git a/src/lib_gossipsub/peers_score.ml b/src/lib_gossipsub/peers_score.ml index e892f67d2b7e62628022d509b11bac52fc7a1a8e..4e81d391695fcc5e46e54a388f992edd95b50070 100644 --- a/src/lib_gossipsub/peers_score.ml +++ b/src/lib_gossipsub/peers_score.ml @@ -178,7 +178,11 @@ struct else 0.0 let float ps = - let topic_scores = topic_scores ps in + let topic_scores = + match ps.parameters.topic_score_cap with + | None -> topic_scores ps + | Some cap -> Float.min cap (topic_scores ps) + in let p5 = p5 ps in let p7 = p7 ps in topic_scores +. p5 +. p7 diff --git a/src/lib_gossipsub/test/test_gossipsub.ml b/src/lib_gossipsub/test/test_gossipsub.ml index 9a1067f074909b52158d5b05d720a98df6e1339c..458cc6fb834f888865ecb03ef8751d18a8f80819 100644 --- a/src/lib_gossipsub/test/test_gossipsub.ml +++ b/src/lib_gossipsub/test/test_gossipsub.ml @@ -51,6 +51,7 @@ let per_topic_score_parameters = let score_parameters = { topics = per_topic_score_parameters; + topic_score_cap = Some 3600.; behaviour_penalty_weight = ~-.10.0; behaviour_penalty_threshold = 0.0; behaviour_penalty_decay = 0.2; diff --git a/src/lib_gossipsub/tezos_gossipsub.ml b/src/lib_gossipsub/tezos_gossipsub.ml index da5dedf0dbd129fca5965a34b909ca9fa1de7490..6e88f1ab12b63ffdb83507657787bf7d33cf5f7d 100644 --- a/src/lib_gossipsub/tezos_gossipsub.ml +++ b/src/lib_gossipsub/tezos_gossipsub.ml @@ -260,6 +260,7 @@ module Make (C : AUTOMATON_CONFIG) : | Topic_score_parameters_family {all_topics; parameters; weights = _} -> Seq.map parameters all_topics |> Seq.iter check_per_topic_score_parameters) ; + Option.iter (fun cap -> assert (cap >= 0.0)) sp.topic_score_cap ; assert (sp.behaviour_penalty_weight <= 0.0) ; assert (sp.behaviour_penalty_threshold >= 0.0) ; assert_in_unit_interval sp.behaviour_penalty_decay ;