Skip to content

Commit d30ba97

Browse files
authored
Use the mesh_n value from NetworkLoad for PeerScoreSettings (#5013)
* Build `gs_config` and use the `mesh_n` config for `PeerScoreSettings` * Remove unused imports * Merge branch 'unstable' into peer-score-settings # Conflicts: # beacon_node/lighthouse_network/src/config.rs # beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs # beacon_node/lighthouse_network/src/service/mod.rs
1 parent 7e49f82 commit d30ba97

File tree

4 files changed

+19
-40
lines changed

4 files changed

+19
-40
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ pub struct Config {
6969
/// Target number of connected peers.
7070
pub target_peers: usize,
7171

72-
/// Gossipsub configuration parameters.
73-
#[serde(skip)]
74-
pub gs_config: gossipsub::Config,
75-
7672
/// Discv5 configuration parameters.
7773
#[serde(skip)]
7874
pub discv5_config: discv5::Config,
@@ -278,12 +274,6 @@ impl Default for Config {
278274
.join(DEFAULT_BEACON_NODE_DIR)
279275
.join(DEFAULT_NETWORK_DIR);
280276

281-
// Note: Using the default config here. Use `gossipsub_config` function for getting
282-
// Lighthouse specific configuration for gossipsub.
283-
let gs_config = gossipsub::ConfigBuilder::default()
284-
.build()
285-
.expect("valid gossipsub configuration");
286-
287277
// Discv5 Unsolicited Packet Rate Limiter
288278
let filter_rate_limiter = Some(
289279
discv5::RateLimiterBuilder::new()
@@ -336,7 +326,6 @@ impl Default for Config {
336326
enr_quic6_port: None,
337327
enr_tcp6_port: None,
338328
target_peers: 100,
339-
gs_config,
340329
discv5_config,
341330
boot_nodes_enr: vec![],
342331
boot_nodes_multiaddr: vec![],

beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::types::{GossipEncoding, GossipKind, GossipTopic};
22
use crate::{error, TopicHash};
3-
use gossipsub::{
4-
Config as GossipsubConfig, IdentTopic as Topic, PeerScoreParams, PeerScoreThresholds,
5-
TopicScoreParams,
6-
};
3+
use gossipsub::{IdentTopic as Topic, PeerScoreParams, PeerScoreThresholds, TopicScoreParams};
74
use std::cmp::max;
85
use std::collections::HashMap;
96
use std::marker::PhantomData;
@@ -54,7 +51,7 @@ pub struct PeerScoreSettings<E: EthSpec> {
5451
}
5552

5653
impl<E: EthSpec> PeerScoreSettings<E> {
57-
pub fn new(chain_spec: &ChainSpec, gs_config: &GossipsubConfig) -> PeerScoreSettings<E> {
54+
pub fn new(chain_spec: &ChainSpec, mesh_n: usize) -> PeerScoreSettings<E> {
5855
let slot = Duration::from_secs(chain_spec.seconds_per_slot);
5956
let beacon_attestation_subnet_weight = 1.0 / chain_spec.attestation_subnet_count as f64;
6057
let max_positive_score = (MAX_IN_MESH_SCORE + MAX_FIRST_MESSAGE_DELIVERIES_SCORE)
@@ -72,7 +69,7 @@ impl<E: EthSpec> PeerScoreSettings<E> {
7269
max_positive_score,
7370
decay_interval: max(Duration::from_secs(1), slot),
7471
decay_to_zero: 0.01,
75-
mesh_n: gs_config.mesh_n(),
72+
mesh_n,
7673
max_committees_per_slot: chain_spec.max_committees_per_slot,
7774
target_committee_size: chain_spec.target_committee_size,
7875
target_aggregators_per_committee: chain_spec.target_aggregators_per_committee as usize,

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
140140
) -> error::Result<(Self, Arc<NetworkGlobals<E>>)> {
141141
let log = log.new(o!("service"=> "libp2p"));
142142

143-
let mut config = ctx.config.clone();
143+
let config = ctx.config.clone();
144144
trace!(log, "Libp2p Service starting");
145145
// initialise the node's ID
146146
let local_keypair = utils::load_private_key(&config, &log);
@@ -180,7 +180,19 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
180180
.eth2()
181181
.expect("Local ENR must have a fork id");
182182

183-
let score_settings = PeerScoreSettings::new(ctx.chain_spec, &config.gs_config);
183+
let gossipsub_config_params = GossipsubConfigParams {
184+
message_domain_valid_snappy: ctx.chain_spec.message_domain_valid_snappy,
185+
gossip_max_size: ctx.chain_spec.gossip_max_size as usize,
186+
};
187+
let gs_config = gossipsub_config(
188+
config.network_load,
189+
ctx.fork_context.clone(),
190+
gossipsub_config_params,
191+
ctx.chain_spec.seconds_per_slot,
192+
E::slots_per_epoch(),
193+
);
194+
195+
let score_settings = PeerScoreSettings::new(ctx.chain_spec, gs_config.mesh_n());
184196

185197
let gossip_cache = {
186198
let slot_duration = std::time::Duration::from_secs(ctx.chain_spec.seconds_per_slot);
@@ -248,18 +260,6 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
248260
max_subscriptions_per_request: max_topics * 2,
249261
};
250262

251-
let gossipsub_config_params = GossipsubConfigParams {
252-
message_domain_valid_snappy: ctx.chain_spec.message_domain_valid_snappy,
253-
gossip_max_size: ctx.chain_spec.gossip_max_size as usize,
254-
};
255-
config.gs_config = gossipsub_config(
256-
config.network_load,
257-
ctx.fork_context.clone(),
258-
gossipsub_config_params,
259-
ctx.chain_spec.seconds_per_slot,
260-
E::slots_per_epoch(),
261-
);
262-
263263
// If metrics are enabled for libp2p build the configuration
264264
let gossipsub_metrics = ctx.libp2p_registry.as_mut().map(|registry| {
265265
(
@@ -268,10 +268,10 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
268268
)
269269
});
270270

271-
let snappy_transform = SnappyTransform::new(config.gs_config.max_transmit_size());
271+
let snappy_transform = SnappyTransform::new(gs_config.max_transmit_size());
272272
let mut gossipsub = Gossipsub::new_with_subscription_filter_and_transform(
273273
MessageAuthenticity::Anonymous,
274-
config.gs_config.clone(),
274+
gs_config.clone(),
275275
gossipsub_metrics,
276276
filter,
277277
snappy_transform,

beacon_node/lighthouse_network/tests/common.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use lighthouse_network::{NetworkConfig, NetworkEvent};
77
use slog::{debug, error, o, Drain};
88
use std::sync::Arc;
99
use std::sync::Weak;
10-
use std::time::Duration;
1110
use tokio::runtime::Runtime;
1211
use types::{
1312
ChainSpec, EnrForkId, Epoch, EthSpec, ForkContext, ForkName, Hash256, MinimalEthSpec, Slot,
@@ -93,12 +92,6 @@ pub fn build_config(mut boot_nodes: Vec<Enr>) -> NetworkConfig {
9392
config.enr_address = (Some(std::net::Ipv4Addr::LOCALHOST), None);
9493
config.boot_nodes_enr.append(&mut boot_nodes);
9594
config.network_dir = path.into_path();
96-
// Reduce gossipsub heartbeat parameters
97-
config.gs_config = gossipsub::ConfigBuilder::from(config.gs_config)
98-
.heartbeat_initial_delay(Duration::from_millis(500))
99-
.heartbeat_interval(Duration::from_millis(500))
100-
.build()
101-
.unwrap();
10295
config
10396
}
10497

0 commit comments

Comments
 (0)