Skip to content

Commit a3730cd

Browse files
committed
Gossipsub scoring improvements (#2391)
* Tweak gossipsub parameters for improved scoring * Modify gossip history * Update settings * Make mesh window constant * Decrease the mesh message deliveries weight * Fmt
1 parent 3e147f9 commit a3730cd

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

beacon_node/eth2_libp2p/src/behaviour/gossipsub_scoring_parameters.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ const VOLUNTARY_EXIT_WEIGHT: f64 = 0.05;
1717
const PROPOSER_SLASHING_WEIGHT: f64 = 0.05;
1818
const ATTESTER_SLASHING_WEIGHT: f64 = 0.05;
1919

20+
/// The time window (seconds) that we expect messages to be forwarded to us in the mesh.
21+
const MESH_MESSAGE_DELIVERIES_WINDOW: u64 = 2;
22+
23+
// Const as this is used in the peer manager to prevent gossip from disconnecting peers.
24+
pub const GREYLIST_THRESHOLD: f64 = -16000.0;
25+
26+
/// Builds the peer score thresholds.
27+
pub fn lighthouse_gossip_thresholds() -> PeerScoreThresholds {
28+
PeerScoreThresholds {
29+
gossip_threshold: -4000.0,
30+
publish_threshold: -8000.0,
31+
graylist_threshold: GREYLIST_THRESHOLD,
32+
accept_px_threshold: 100.0,
33+
opportunistic_graft_threshold: 5.0,
34+
}
35+
}
36+
2037
pub struct PeerScoreSettings<TSpec: EthSpec> {
2138
slot: Duration,
2239
epoch: Duration,
@@ -75,7 +92,7 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
7592
decay_to_zero: self.decay_to_zero,
7693
retain_score: self.epoch * 100,
7794
app_specific_weight: 1.0,
78-
ip_colocation_factor_threshold: 3.0,
95+
ip_colocation_factor_threshold: 8.0, // Allow up to 8 nodes per IP
7996
behaviour_penalty_threshold: 6.0,
8097
behaviour_penalty_decay: self.score_parameter_decay(self.epoch * 10),
8198
..Default::default()
@@ -313,10 +330,10 @@ impl<TSpec: EthSpec> PeerScoreSettings<TSpec> {
313330
cap_factor * t_params.mesh_message_deliveries_threshold
314331
};
315332
t_params.mesh_message_deliveries_activation = activation_window;
316-
t_params.mesh_message_deliveries_window = Duration::from_secs(2);
333+
t_params.mesh_message_deliveries_window =
334+
Duration::from_secs(MESH_MESSAGE_DELIVERIES_WINDOW);
317335
t_params.mesh_failure_penalty_decay = t_params.mesh_message_deliveries_decay;
318-
t_params.mesh_message_deliveries_weight = -self.max_positive_score
319-
/ (t_params.topic_weight * t_params.mesh_message_deliveries_threshold.powi(2));
336+
t_params.mesh_message_deliveries_weight = -t_params.topic_weight;
320337
t_params.mesh_failure_penalty_weight = t_params.mesh_message_deliveries_weight;
321338
if decay_slots >= current_slot.as_u64() {
322339
t_params.mesh_message_deliveries_threshold = 0.0;

beacon_node/eth2_libp2p/src/behaviour/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::behaviour::gossipsub_scoring_parameters::PeerScoreSettings;
1+
use crate::behaviour::gossipsub_scoring_parameters::{
2+
lighthouse_gossip_thresholds, PeerScoreSettings,
3+
};
24
use crate::discovery::{subnet_predicate, Discovery, DiscoveryEvent, TARGET_SUBNET_PEERS};
35
use crate::peer_manager::{
46
score::ReportSource, ConnectionDirection, PeerManager, PeerManagerEvent,
@@ -19,7 +21,7 @@ use libp2p::{
1921
gossipsub::{
2022
subscription_filter::{MaxCountSubscriptionFilter, WhitelistSubscriptionFilter},
2123
Gossipsub as BaseGossipsub, GossipsubEvent, IdentTopic as Topic, MessageAcceptance,
22-
MessageAuthenticity, MessageId, PeerScoreThresholds,
24+
MessageAuthenticity, MessageId,
2325
},
2426
identify::{Identify, IdentifyConfig, IdentifyEvent},
2527
swarm::{
@@ -42,10 +44,9 @@ use std::{
4244
};
4345
use types::{ChainSpec, EnrForkId, EthSpec, SignedBeaconBlock, Slot, SubnetId};
4446

45-
mod gossipsub_scoring_parameters;
47+
pub mod gossipsub_scoring_parameters;
4648

4749
const MAX_IDENTIFY_ADDRESSES: usize = 10;
48-
pub const GOSSIPSUB_GREYLIST_THRESHOLD: f64 = -16000.0;
4950

5051
/// Identifier of requests sent by a peer.
5152
pub type PeerRequestId = (ConnectionId, SubstreamId);
@@ -222,13 +223,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
222223
let active_validators = TSpec::minimum_validator_count();
223224
let current_slot = Slot::new(0);
224225

225-
let thresholds = PeerScoreThresholds {
226-
gossip_threshold: -4000.0,
227-
publish_threshold: -8000.0,
228-
graylist_threshold: GOSSIPSUB_GREYLIST_THRESHOLD,
229-
accept_px_threshold: 100.0,
230-
opportunistic_graft_threshold: 5.0,
231-
};
226+
let thresholds = lighthouse_gossip_thresholds();
232227

233228
let score_settings = PeerScoreSettings::new(chain_spec, &config.gs_config);
234229

beacon_node/eth2_libp2p/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ use sha2::{Digest, Sha256};
1414
use std::path::PathBuf;
1515
use std::time::Duration;
1616

17+
/// The maximum transmit size of gossip messages in bytes.
1718
pub const GOSSIP_MAX_SIZE: usize = 1_048_576;
19+
/// This is a constant to be used in discovery. The lower bound of the gossipsub mesh.
20+
pub const MESH_N_LOW: usize = 6;
1821

1922
// We treat uncompressed messages as invalid and never use the INVALID_SNAPPY_DOMAIN as in the
2023
// specification. We leave it here for posterity.
2124
// const MESSAGE_DOMAIN_INVALID_SNAPPY: [u8; 4] = [0, 0, 0, 0];
2225
const MESSAGE_DOMAIN_VALID_SNAPPY: [u8; 4] = [1, 0, 0, 0];
23-
pub const MESH_N_LOW: usize = 6;
2426

2527
#[derive(Clone, Debug, Serialize, Deserialize)]
2628
#[serde(default)]
@@ -138,8 +140,8 @@ impl Default for Config {
138140
.mesh_n_high(12)
139141
.gossip_lazy(6)
140142
.fanout_ttl(Duration::from_secs(60))
141-
.history_length(6)
142-
.max_messages_per_rpc(Some(10))
143+
.history_length(12)
144+
.max_messages_per_rpc(Some(500)) // Responses to IWANT can be quite large
143145
.history_gossip(3)
144146
.validate_messages() // require validation before propagation
145147
.validation_mode(ValidationMode::Anonymous)

beacon_node/eth2_libp2p/src/peer_manager/score.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! As the logic develops this documentation will advance.
66
//!
77
//! The scoring algorithms are currently experimental.
8-
use crate::behaviour::GOSSIPSUB_GREYLIST_THRESHOLD;
8+
use crate::behaviour::gossipsub_scoring_parameters::GREYLIST_THRESHOLD as GOSSIPSUB_GREYLIST_THRESHOLD;
99
use serde::Serialize;
1010
use std::time::Instant;
1111
use strum::AsRefStr;

0 commit comments

Comments
 (0)