Update lighthouse to the latest upstream libp2p and gossipsub (#7828)

This commit is contained in:
João Oliveira
2025-08-21 08:57:46 +01:00
committed by GitHub
parent c9ffdf7f71
commit cee30d8ca5
5 changed files with 147 additions and 230 deletions

View File

@@ -328,26 +328,25 @@ impl<E: EthSpec> Network<E> {
max_subscriptions_per_request: max_topics_at_any_fork * 2,
};
// If metrics are enabled for libp2p build the configuration
let gossipsub_metrics = ctx.libp2p_registry.as_mut().map(|registry| {
(
registry.sub_registry_with_prefix("gossipsub"),
Default::default(),
)
});
let spec = &ctx.chain_spec;
let snappy_transform =
SnappyTransform::new(spec.max_payload_size as usize, spec.max_compressed_len());
let mut gossipsub = Gossipsub::new_with_subscription_filter_and_transform(
MessageAuthenticity::Anonymous,
gs_config.clone(),
gossipsub_metrics,
filter,
snappy_transform,
)
.map_err(|e| format!("Could not construct gossipsub: {:?}", e))?;
// If metrics are enabled for libp2p build the configuration
if let Some(ref mut registry) = ctx.libp2p_registry {
gossipsub = gossipsub.with_metrics(
registry.sub_registry_with_prefix("gossipsub"),
Default::default(),
);
}
gossipsub
.with_peer_score(params, thresholds)
.expect("Valid score params and thresholds");
@@ -1374,14 +1373,12 @@ impl<E: EthSpec> Network<E> {
} => {
debug!(
peer_id = %peer_id,
publish = failed_messages.publish,
forward = failed_messages.forward,
priority = failed_messages.priority,
non_priority = failed_messages.non_priority,
"Slow gossipsub peer"
);
// Punish the peer if it cannot handle priority messages
if failed_messages.timeout > 10 {
if failed_messages.priority > 10 {
debug!(%peer_id, "Slow gossipsub peer penalized for priority failure");
self.peer_manager_mut().report_peer(
&peer_id,
@@ -1390,7 +1387,7 @@ impl<E: EthSpec> Network<E> {
None,
"publish_timeout_penalty",
);
} else if failed_messages.total_queue_full() > 10 {
} else if failed_messages.non_priority > 10 {
debug!(%peer_id, "Slow gossipsub peer penalized for send queue full");
self.peer_manager_mut().report_peer(
&peer_id,
@@ -1888,6 +1885,7 @@ impl<E: EthSpec> Network<E> {
send_back_addr,
error,
connection_id: _,
peer_id: _,
} => {
let error_repr = match error {
libp2p::swarm::ListenError::Aborted => {
@@ -1896,8 +1894,8 @@ impl<E: EthSpec> Network<E> {
libp2p::swarm::ListenError::WrongPeerId { obtained, endpoint } => {
format!("Wrong peer id, obtained {obtained}, endpoint {endpoint:?}")
}
libp2p::swarm::ListenError::LocalPeerId { endpoint } => {
format!("Dialing local peer id {endpoint:?}")
libp2p::swarm::ListenError::LocalPeerId { address } => {
format!("Dialing local peer id {address:?}")
}
libp2p::swarm::ListenError::Denied { cause } => {
format!("Connection was denied with cause: {cause:?}")

View File

@@ -6,8 +6,8 @@ use futures::future::Either;
use gossipsub;
use libp2p::core::{multiaddr::Multiaddr, muxing::StreamMuxerBox, transport::Boxed};
use libp2p::identity::{Keypair, secp256k1};
use libp2p::metrics::Registry;
use libp2p::{PeerId, Transport, core, noise, yamux};
use prometheus_client::registry::Registry;
use ssz::Decode;
use std::collections::HashSet;
use std::fs::File;