From 6ba8599dda38c6146b5a028018450b126854b194 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 28 Mar 2022 15:35:23 -0500 Subject: [PATCH 1/4] allow score buckets to be set by the user and/or adjusted from the scoring thresholds --- protocols/gossipsub/src/metrics.rs | 52 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/protocols/gossipsub/src/metrics.rs b/protocols/gossipsub/src/metrics.rs index 574fbcfc341..3554e7227c8 100644 --- a/protocols/gossipsub/src/metrics.rs +++ b/protocols/gossipsub/src/metrics.rs @@ -49,13 +49,47 @@ pub struct Config { /// determined by users on the network. This limit permits a fixed amount of topics to allow, /// in-addition to the mesh topics. pub max_never_subscribed_topics: usize, + /// Buckets used for the score histograms. + pub score_buckets: Vec, +} + +impl Config { + pub fn buckets_using_scoring_thresholds(&mut self, params: &crate::PeerScoreThresholds) { + self.score_buckets = vec![ + params.graylist_threshold, + params.publish_threshold, + params.gossip_threshold, + params.gossip_threshold / 2.0, + params.gossip_threshold / 4.0, + 0.0, + 1.0, + 10.0, + 100.0, + ]; + } } impl Default for Config { fn default() -> Self { + // Some sensible defaults + let gossip_threshold = -4000.0; + let publish_threshold = -8000.0; + let graylist_threshold = -16000.0; + let score_buckets: Vec = vec![ + graylist_threshold, + publish_threshold, + gossip_threshold, + gossip_threshold / 2.0, + gossip_threshold / 4.0, + 0.0, + 1.0, + 10.0, + 100.0, + ]; Config { max_topics: DEFAULT_MAX_TOPICS, max_never_subscribed_topics: DEFAULT_MAX_NEVER_SUBSCRIBED_TOPICS, + score_buckets, } } } @@ -147,6 +181,7 @@ impl Metrics { let Config { max_topics, max_never_subscribed_topics, + score_buckets, } = config; macro_rules! register_family { @@ -224,24 +259,9 @@ impl Metrics { "topic_msg_recv_bytes", "Bytes received from gossip messages for each topic" ); - // TODO: Update default variables once a builder pattern is used. - let gossip_threshold = -4000.0; - let publish_threshold = -8000.0; - let greylist_threshold = -16000.0; - let histogram_buckets: Vec = vec![ - greylist_threshold, - publish_threshold, - gossip_threshold, - gossip_threshold / 2.0, - gossip_threshold / 4.0, - 0.0, - 1.0, - 10.0, - 100.0, - ]; let hist_builder = HistBuilder { - buckets: histogram_buckets, + buckets: score_buckets, }; let score_per_mesh: Family<_, _, HistBuilder> = Family::new_with_constructor(hist_builder); From eb2bb2c57334b1be705badd09704a5cb06bc572d Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 28 Mar 2022 15:38:15 -0500 Subject: [PATCH 2/4] add some docs --- protocols/gossipsub/src/metrics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/protocols/gossipsub/src/metrics.rs b/protocols/gossipsub/src/metrics.rs index 3554e7227c8..e813140f759 100644 --- a/protocols/gossipsub/src/metrics.rs +++ b/protocols/gossipsub/src/metrics.rs @@ -54,6 +54,7 @@ pub struct Config { } impl Config { + /// Create buckets for the score histograms based on score thresholds. pub fn buckets_using_scoring_thresholds(&mut self, params: &crate::PeerScoreThresholds) { self.score_buckets = vec![ params.graylist_threshold, From bc9f8eec7d30530dd2086496752f06e134146ca2 Mon Sep 17 00:00:00 2001 From: Diva M Date: Mon, 28 Mar 2022 15:39:50 -0500 Subject: [PATCH 3/4] initial CHANGELOG --- protocols/gossipsub/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 0782a4c942d..4c536be415f 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -4,6 +4,8 @@ - Fix gossipsub metric (see [PR 2558]). +- Allow the user to set the buckets for the score histogram, and to adjust them from the score thresholds. + [PR 2558]: https://github.com/libp2p/rust-libp2p/pull/2558 # 0.36.0 [2022-02-22] From c55d173982b28726c24c0c57e5fdb296fe30614b Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 8 Apr 2022 20:47:34 +0200 Subject: [PATCH 4/4] Update protocols/gossipsub/CHANGELOG.md --- protocols/gossipsub/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 4c536be415f..cf3376135de 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -4,9 +4,10 @@ - Fix gossipsub metric (see [PR 2558]). -- Allow the user to set the buckets for the score histogram, and to adjust them from the score thresholds. +- Allow the user to set the buckets for the score histogram, and to adjust them from the score thresholds. See [PR 2595]. [PR 2558]: https://github.com/libp2p/rust-libp2p/pull/2558 +[PR 2595]: https://github.com/libp2p/rust-libp2p/pull/2595 # 0.36.0 [2022-02-22]