diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index 85f8b1f848d..03f530db4d1 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -69,10 +69,6 @@ pub struct Config { /// Target number of connected peers. pub target_peers: usize, - /// Gossipsub configuration parameters. - #[serde(skip)] - pub gs_config: gossipsub::Config, - /// Discv5 configuration parameters. #[serde(skip)] pub discv5_config: discv5::Config, @@ -278,12 +274,6 @@ impl Default for Config { .join(DEFAULT_BEACON_NODE_DIR) .join(DEFAULT_NETWORK_DIR); - // Note: Using the default config here. Use `gossipsub_config` function for getting - // Lighthouse specific configuration for gossipsub. - let gs_config = gossipsub::ConfigBuilder::default() - .build() - .expect("valid gossipsub configuration"); - // Discv5 Unsolicited Packet Rate Limiter let filter_rate_limiter = Some( discv5::RateLimiterBuilder::new() @@ -336,7 +326,6 @@ impl Default for Config { enr_quic6_port: None, enr_tcp6_port: None, target_peers: 100, - gs_config, discv5_config, boot_nodes_enr: vec![], boot_nodes_multiaddr: vec![], diff --git a/beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs b/beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs index 0846a9f4aa6..c6a764bb0ef 100644 --- a/beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs +++ b/beacon_node/lighthouse_network/src/service/gossipsub_scoring_parameters.rs @@ -1,9 +1,6 @@ use crate::types::{GossipEncoding, GossipKind, GossipTopic}; use crate::{error, TopicHash}; -use gossipsub::{ - Config as GossipsubConfig, IdentTopic as Topic, PeerScoreParams, PeerScoreThresholds, - TopicScoreParams, -}; +use gossipsub::{IdentTopic as Topic, PeerScoreParams, PeerScoreThresholds, TopicScoreParams}; use std::cmp::max; use std::collections::HashMap; use std::marker::PhantomData; @@ -54,7 +51,7 @@ pub struct PeerScoreSettings { } impl PeerScoreSettings { - pub fn new(chain_spec: &ChainSpec, gs_config: &GossipsubConfig) -> PeerScoreSettings { + pub fn new(chain_spec: &ChainSpec, mesh_n: usize) -> PeerScoreSettings { let slot = Duration::from_secs(chain_spec.seconds_per_slot); let beacon_attestation_subnet_weight = 1.0 / chain_spec.attestation_subnet_count as f64; let max_positive_score = (MAX_IN_MESH_SCORE + MAX_FIRST_MESSAGE_DELIVERIES_SCORE) @@ -72,7 +69,7 @@ impl PeerScoreSettings { max_positive_score, decay_interval: max(Duration::from_secs(1), slot), decay_to_zero: 0.01, - mesh_n: gs_config.mesh_n(), + mesh_n, max_committees_per_slot: chain_spec.max_committees_per_slot, target_committee_size: chain_spec.target_committee_size, target_aggregators_per_committee: chain_spec.target_aggregators_per_committee as usize, diff --git a/beacon_node/lighthouse_network/src/service/mod.rs b/beacon_node/lighthouse_network/src/service/mod.rs index 3dd1d9b50c9..f91a5b471ad 100644 --- a/beacon_node/lighthouse_network/src/service/mod.rs +++ b/beacon_node/lighthouse_network/src/service/mod.rs @@ -140,7 +140,7 @@ impl Network { ) -> error::Result<(Self, Arc>)> { let log = log.new(o!("service"=> "libp2p")); - let mut config = ctx.config.clone(); + let config = ctx.config.clone(); trace!(log, "Libp2p Service starting"); // initialise the node's ID let local_keypair = utils::load_private_key(&config, &log); @@ -180,7 +180,19 @@ impl Network { .eth2() .expect("Local ENR must have a fork id"); - let score_settings = PeerScoreSettings::new(ctx.chain_spec, &config.gs_config); + let gossipsub_config_params = GossipsubConfigParams { + message_domain_valid_snappy: ctx.chain_spec.message_domain_valid_snappy, + gossip_max_size: ctx.chain_spec.gossip_max_size as usize, + }; + let gs_config = gossipsub_config( + config.network_load, + ctx.fork_context.clone(), + gossipsub_config_params, + ctx.chain_spec.seconds_per_slot, + E::slots_per_epoch(), + ); + + let score_settings = PeerScoreSettings::new(ctx.chain_spec, gs_config.mesh_n()); let gossip_cache = { let slot_duration = std::time::Duration::from_secs(ctx.chain_spec.seconds_per_slot); @@ -248,18 +260,6 @@ impl Network { max_subscriptions_per_request: max_topics * 2, }; - let gossipsub_config_params = GossipsubConfigParams { - message_domain_valid_snappy: ctx.chain_spec.message_domain_valid_snappy, - gossip_max_size: ctx.chain_spec.gossip_max_size as usize, - }; - config.gs_config = gossipsub_config( - config.network_load, - ctx.fork_context.clone(), - gossipsub_config_params, - ctx.chain_spec.seconds_per_slot, - E::slots_per_epoch(), - ); - // If metrics are enabled for libp2p build the configuration let gossipsub_metrics = ctx.libp2p_registry.as_mut().map(|registry| { ( @@ -268,10 +268,10 @@ impl Network { ) }); - let snappy_transform = SnappyTransform::new(config.gs_config.max_transmit_size()); + let snappy_transform = SnappyTransform::new(gs_config.max_transmit_size()); let mut gossipsub = Gossipsub::new_with_subscription_filter_and_transform( MessageAuthenticity::Anonymous, - config.gs_config.clone(), + gs_config.clone(), gossipsub_metrics, filter, snappy_transform, diff --git a/beacon_node/lighthouse_network/tests/common.rs b/beacon_node/lighthouse_network/tests/common.rs index 9ca7eeb2308..40ae341bd26 100644 --- a/beacon_node/lighthouse_network/tests/common.rs +++ b/beacon_node/lighthouse_network/tests/common.rs @@ -7,7 +7,6 @@ use lighthouse_network::{NetworkConfig, NetworkEvent}; use slog::{debug, error, o, Drain}; use std::sync::Arc; use std::sync::Weak; -use std::time::Duration; use tokio::runtime::Runtime; use types::{ ChainSpec, EnrForkId, Epoch, EthSpec, ForkContext, ForkName, Hash256, MinimalEthSpec, Slot, @@ -93,12 +92,6 @@ pub fn build_config(mut boot_nodes: Vec) -> NetworkConfig { config.enr_address = (Some(std::net::Ipv4Addr::LOCALHOST), None); config.boot_nodes_enr.append(&mut boot_nodes); config.network_dir = path.into_path(); - // Reduce gossipsub heartbeat parameters - config.gs_config = gossipsub::ConfigBuilder::from(config.gs_config) - .heartbeat_initial_delay(Duration::from_millis(500)) - .heartbeat_interval(Duration::from_millis(500)) - .build() - .unwrap(); config }