mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
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
This commit is contained in:
@@ -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![],
|
||||
|
||||
@@ -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<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)
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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| {
|
||||
(
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user