Create network_utils crate (#7761)

Anchor currently depends on `lighthouse_network` for a few types and utilities that live within. As we use our own libp2p behaviours, we actually do not use the core logic in that crate. This makes us transitively depend on a bunch of unneeded crates (even a whole separate libp2p if the versions mismatch!)


  Move things we require into it's own lightweight crate.


Co-Authored-By: Daniel Knopik <daniel@dknopik.de>
This commit is contained in:
Daniel Knopik
2025-09-10 14:59:24 +02:00
committed by GitHub
parent caa1df6fc3
commit ee1b6bc81b
42 changed files with 198 additions and 169 deletions

View File

@@ -1,4 +1,5 @@
use lighthouse_network::{NetworkGlobals, types::SyncState};
use network_utils::discovery_metrics;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
@@ -219,33 +220,21 @@ impl NatState {
/// Observes if NAT traversal is possible.
pub fn observe_nat() -> NatState {
let discv5_ipv4 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["discv5_ipv4"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();
let discv5_ipv4 = metrics::get_int_gauge(&discovery_metrics::NAT_OPEN, &["discv5_ipv4"])
.map(|g| g.get() == 1)
.unwrap_or_default();
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 discv5_ipv6 = metrics::get_int_gauge(&discovery_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_ipv4"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();
let libp2p_ipv4 = metrics::get_int_gauge(&discovery_metrics::NAT_OPEN, &["libp2p_ipv4"])
.map(|g| g.get() == 1)
.unwrap_or_default();
let libp2p_ipv6 = lighthouse_network::metrics::get_int_gauge(
&lighthouse_network::metrics::NAT_OPEN,
&["libp2p_ipv6"],
)
.map(|g| g.get() == 1)
.unwrap_or_default();
let libp2p_ipv6 = metrics::get_int_gauge(&discovery_metrics::NAT_OPEN, &["libp2p_ipv6"])
.map(|g| g.get() == 1)
.unwrap_or_default();
NatState {
discv5_ipv4,