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

Update to latest discovery #6486

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
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
709 changes: 365 additions & 344 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ derivative = "2"
dirs = "3"
either = "1.9"
rust_eth_kzg = "0.5.1"
discv5 = { version = "0.7", features = ["libp2p"] }
discv5 = { version = "0.9", features = ["libp2p"] }
env_logger = "0.9"
error-chain = "0.12"
ethereum_hashing = "0.7.0"
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this bumped?

.disable_report_discovered_peers()
.ip_limit() // limits /24 IP's in buckets.
.incoming_bucket_limit(8) // half the bucket size
Expand Down
4 changes: 0 additions & 4 deletions beacon_node/lighthouse_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions beacon_node/lighthouse_network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions boot_node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub async fn run<E: EthSpec>(
"active_sessions" => metrics.active_sessions,
"requests/s" => format_args!("{:.2}", metrics.unsolicited_requests_per_second),
"ipv4_nodes" => ipv4_only_reachable,
"ipv6_nodes" => ipv6_only_reachable,
"ipv6_and_ipv4_nodes" => ipv4_ipv6_reachable,
"ipv6_only_nodes" => ipv6_only_reachable,
"dual_stack_nodes" => ipv4_ipv6_reachable,
"unreachable_nodes" => unreachable_nodes,
);

Expand Down
50 changes: 44 additions & 6 deletions common/system_health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,61 @@ pub fn observe_system_health_vc(
}
}

/// The current state of Lighthouse NAT/connectivity.
#[derive(Serialize, Deserialize)]
pub struct NatState {
/// Contactable on discovery ipv4.
discv5_ipv4: bool,
/// Contactable on discovery ipv6.
discv5_ipv6: bool,
/// Contactable on libp2p ipv4.
libp2p_ipv4: bool,
/// Contactable on libp2p ipv6.
libp2p_ipv6: bool,
}

impl NatState {
pub fn is_anything_open(&self) -> bool {
self.discv5_ipv4 || self.discv5_ipv6 || self.libp2p_ipv4 || self.libp2p_ipv6
}
}

/// Observes if NAT traversal is possible.
pub fn observe_nat() -> bool {
let discv5_nat = lighthouse_network::metrics::get_int_gauge(
pub fn observe_nat() -> NatState {
let discv5_ipv4 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["discv5"],
&["discv5_ipv4"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();

let libp2p_nat = lighthouse_network::metrics::get_int_gauge(
let discv5_ipv6 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["discv5_ipv6"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();

let libp2p_ipv4 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["libp2p"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();

let libp2p_ipv6 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["libp2p"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();

discv5_nat || libp2p_nat
NatState {
discv5_ipv4,
discv5_ipv6,
libp2p_ipv4,
libp2p_ipv6,
}
}

/// Observes the Beacon Node system health.
Expand Down Expand Up @@ -242,7 +280,7 @@ pub fn observe_system_health_bn<E: EthSpec>(
.unwrap_or_else(|| (String::from("None"), 0, 0));

// Determine if the NAT is open or not.
let nat_open = observe_nat();
let nat_open = observe_nat().is_anything_open();

SystemHealthBN {
system_health,
Expand Down
Loading