Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the mesh_n value from NetworkLoad for PeerScoreSettings #5013

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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![],
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,7 +51,7 @@ pub struct PeerScoreSettings<E: EthSpec> {
}

impl<E: EthSpec> PeerScoreSettings<E> {
pub fn new(chain_spec: &ChainSpec, gs_config: &GossipsubConfig) -> PeerScoreSettings<E> {
pub fn new(chain_spec: &ChainSpec, mesh_n: usize) -> PeerScoreSettings<E> {
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)
Expand All @@ -72,7 +69,7 @@ impl<E: EthSpec> PeerScoreSettings<E> {
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,
Expand Down
32 changes: 16 additions & 16 deletions beacon_node/lighthouse_network/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
) -> error::Result<(Self, Arc<NetworkGlobals<E>>)> {
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);
Expand Down Expand Up @@ -180,7 +180,19 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
.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);
Expand Down Expand Up @@ -248,18 +260,6 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
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| {
(
Expand All @@ -268,10 +268,10 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
)
});

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,
Expand Down
7 changes: 0 additions & 7 deletions beacon_node/lighthouse_network/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,12 +92,6 @@ pub fn build_config(mut boot_nodes: Vec<Enr>) -> 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
}

Expand Down
Loading