mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Update to latest discovery (#6486)
* Upgrade discv5 to v0.8 * Rename some logs * Improve the NAT reporting with new discv5 metrics * Merge branch 'unstable' into discv5-v8 * Limited Cargo.lock update * Update yanked futures-* crates
This commit is contained in:
@@ -305,12 +305,12 @@ impl Default for Config {
|
||||
let discv5_config = discv5::ConfigBuilder::new(discv5_listen_config)
|
||||
.enable_packet_filter()
|
||||
.session_cache_capacity(5000)
|
||||
.request_timeout(Duration::from_secs(1))
|
||||
.request_timeout(Duration::from_secs(2))
|
||||
.query_peer_timeout(Duration::from_secs(2))
|
||||
.query_timeout(Duration::from_secs(30))
|
||||
.request_retries(1)
|
||||
.enr_peer_update_min(10)
|
||||
.query_parallelism(5)
|
||||
.query_parallelism(8)
|
||||
.disable_report_discovered_peers()
|
||||
.ip_limit() // limits /24 IP's in buckets.
|
||||
.incoming_bucket_limit(8) // half the bucket size
|
||||
|
||||
@@ -1052,10 +1052,6 @@ impl<E: EthSpec> NetworkBehaviour for Discovery<E> {
|
||||
discv5::Event::SocketUpdated(socket_addr) => {
|
||||
info!(self.log, "Address updated"; "ip" => %socket_addr.ip(), "udp_port" => %socket_addr.port());
|
||||
metrics::inc_counter(&metrics::ADDRESS_UPDATE_COUNT);
|
||||
// We have SOCKET_UPDATED messages. This occurs when discovery has a majority of
|
||||
// users reporting an external port and our ENR gets updated.
|
||||
// Which means we are able to do NAT traversal.
|
||||
metrics::set_gauge_vec(&metrics::NAT_OPEN, &["discv5"], 1);
|
||||
// Discv5 will have updated our local ENR. We save the updated version
|
||||
// to disk.
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ pub static NAT_OPEN: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
|
||||
&["protocol"],
|
||||
)
|
||||
});
|
||||
|
||||
pub static ADDRESS_UPDATE_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
|
||||
try_create_int_counter(
|
||||
"libp2p_address_update_total",
|
||||
@@ -212,4 +213,6 @@ pub fn scrape_discovery_metrics() {
|
||||
set_gauge(&DISCOVERY_SESSIONS, metrics.active_sessions as i64);
|
||||
set_gauge_vec(&DISCOVERY_BYTES, &["inbound"], metrics.bytes_recv as i64);
|
||||
set_gauge_vec(&DISCOVERY_BYTES, &["outbound"], metrics.bytes_sent as i64);
|
||||
set_gauge_vec(&NAT_OPEN, &["discv5_ipv4"], metrics.ipv4_contactable as i64);
|
||||
set_gauge_vec(&NAT_OPEN, &["discv5_ipv6"], metrics.ipv6_contactable as i64);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ use futures::StreamExt;
|
||||
use libp2p::core::transport::PortUse;
|
||||
use libp2p::core::ConnectedPoint;
|
||||
use libp2p::identity::PeerId;
|
||||
use libp2p::multiaddr::Protocol;
|
||||
use libp2p::swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
|
||||
use libp2p::swarm::dial_opts::{DialOpts, PeerCondition};
|
||||
use libp2p::swarm::dummy::ConnectionHandler;
|
||||
use libp2p::swarm::{ConnectionDenied, ConnectionId, NetworkBehaviour, ToSwarm};
|
||||
pub use metrics::{set_gauge_vec, NAT_OPEN};
|
||||
use slog::{debug, error, trace};
|
||||
use types::EthSpec;
|
||||
|
||||
@@ -160,8 +162,8 @@ impl<E: EthSpec> NetworkBehaviour for PeerManager<E> {
|
||||
) -> Result<(), ConnectionDenied> {
|
||||
// get the IP address to verify it's not banned.
|
||||
let ip = match remote_addr.iter().next() {
|
||||
Some(libp2p::multiaddr::Protocol::Ip6(ip)) => IpAddr::V6(ip),
|
||||
Some(libp2p::multiaddr::Protocol::Ip4(ip)) => IpAddr::V4(ip),
|
||||
Some(Protocol::Ip6(ip)) => IpAddr::V6(ip),
|
||||
Some(Protocol::Ip4(ip)) => IpAddr::V4(ip),
|
||||
_ => {
|
||||
return Err(ConnectionDenied::new(format!(
|
||||
"Connection to peer rejected: invalid multiaddr: {remote_addr}"
|
||||
@@ -207,6 +209,14 @@ impl<E: EthSpec> NetworkBehaviour for PeerManager<E> {
|
||||
));
|
||||
}
|
||||
|
||||
// We have an inbound connection, this is indicative of having our libp2p NAT ports open. We
|
||||
// distinguish between ipv4 and ipv6 here:
|
||||
match remote_addr.iter().next() {
|
||||
Some(Protocol::Ip4(_)) => set_gauge_vec(&NAT_OPEN, &["libp2p_ipv4"], 1),
|
||||
Some(Protocol::Ip6(_)) => set_gauge_vec(&NAT_OPEN, &["libp2p_ipv6"], 1),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(ConnectionHandler)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user