Skip to content

Create network_utils crate #7761

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

Open
wants to merge 2 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
38 changes: 25 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"common/malloc_utils",
"common/metrics",
"common/monitoring_api",
"common/network_utils",
"common/oneshot_broadcast",
"common/pretty_reqwest_error",
"common/sensitive_url",
Expand All @@ -44,7 +45,6 @@ members = [
"common/target_check",
"common/task_executor",
"common/test_random_derive",
"common/unused_port",
"common/validator_dir",
"common/warp_utils",
"common/workspace_members",
Expand Down Expand Up @@ -190,6 +190,7 @@ mockall_double = "0.3"
mockito = "1.5.0"
monitoring_api = { path = "common/monitoring_api" }
network = { path = "beacon_node/network" }
network_utils = { path = "common/network_utils" }
node_test_rig = { path = "testing/node_test_rig" }
num_cpus = "1"
once_cell = "1.17.1"
Expand Down Expand Up @@ -257,7 +258,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tree_hash = "0.10.0"
tree_hash_derive = "0.10.0"
types = { path = "consensus/types" }
unused_port = { path = "common/unused_port" }
url = "2"
uuid = { version = "0.8", features = ["serde", "v4"] }
validator_client = { path = "validator_client" }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ http_api = { workspace = true }
hyper = { workspace = true }
lighthouse_network = { workspace = true }
monitoring_api = { workspace = true }
network_utils = { workspace = true }
sensitive_url = { workspace = true }
serde_json = { workspace = true }
slasher = { workspace = true }
Expand All @@ -41,7 +42,6 @@ strum = { workspace = true }
task_executor = { workspace = true }
tracing = { workspace = true }
types = { workspace = true }
unused_port = { workspace = true }

[dev-dependencies]
node_test_rig = { path = "../testing/node_test_rig" }
1 change: 1 addition & 0 deletions beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ logging = { workspace = true }
lru = { workspace = true }
metrics = { workspace = true }
network = { workspace = true }
network_utils = { workspace = true }
operation_pool = { workspace = true }
parking_lot = { workspace = true }
proto_array = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ use eth2::types::{
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
use health_metrics::observe::Observe;
use lighthouse_network::rpc::methods::MetaData;
use lighthouse_network::{types::SyncState, Enr, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_network::{types::SyncState, Enr, NetworkGlobals, PeerId, PubsubMessage};
use lighthouse_version::version_with_platform;
use logging::{crit, SSELoggingComponents};
use network::{NetworkMessage, NetworkSenders, ValidatorSubscriptionMessage};
use network_utils::enr_ext::EnrExt;
use operation_pool::ReceivedPreCapella;
use parking_lot::RwLock;
pub use publish_blocks::{
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use http_api::{
test_utils::{create_api_server, ApiServer},
BlockId, StateId,
};
use lighthouse_network::{types::SyncState, Enr, EnrExt, PeerId};
use lighthouse_network::{types::SyncState, Enr, PeerId};
use network::NetworkReceivers;
use network_utils::enr_ext::EnrExt;
use operation_pool::attestation_storage::CheckpointKey;
use proto_array::ExecutionStatus;
use sensitive_url::SensitiveUrl;
Expand Down
1 change: 1 addition & 0 deletions beacon_node/http_metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lighthouse_version = { workspace = true }
logging = { workspace = true }
malloc_utils = { workspace = true }
metrics = { workspace = true }
network_utils = { workspace = true }
serde = { workspace = true }
slot_clock = { workspace = true }
store = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
store::scrape_for_metrics(db_path, freezer_db_path);
}

lighthouse_network::scrape_discovery_metrics();
network_utils::discovery_metrics::scrape_discovery_metrics();

health_metrics::metrics::scrape_health_metrics();

Expand Down
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ logging = { workspace = true }
lru = { workspace = true }
lru_cache = { workspace = true }
metrics = { workspace = true }
network_utils = { workspace = true }
parking_lot = { workspace = true }
prometheus-client = "0.22.0"
rand = { workspace = true }
Expand All @@ -43,15 +44,13 @@ ssz_types = { workspace = true }
strum = { workspace = true }
superstruct = { workspace = true }
task_executor = { workspace = true }
tiny-keccak = "2"
tokio = { workspace = true }
tokio-io-timeout = "1"
tokio-util = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
types = { workspace = true }
unsigned-varint = { version = "0.8", features = ["codec"] }
unused_port = { workspace = true }

[dependencies.libp2p]
version = "0.55"
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::listen_addr::{ListenAddr, ListenAddress};
use crate::rpc::config::{InboundRateLimiterConfig, OutboundRateLimiterConfig};
use crate::types::GossipKind;
use crate::{Enr, PeerIdSerialized};
Expand All @@ -7,6 +6,7 @@ use directory::{
};
use libp2p::Multiaddr;
use local_ip_address::local_ipv6;
use network_utils::listen_addr::{ListenAddr, ListenAddress};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::net::{Ipv4Addr, Ipv6Addr};
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/discovery/enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

pub use discv5::enr::CombinedKey;

use super::enr_ext::CombinedKeyExt;
use super::enr_ext::{EnrExt, QUIC6_ENR_KEY, QUIC_ENR_KEY};
use super::ENR_FILENAME;
use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield};
use crate::NetworkConfig;
use alloy_rlp::bytes::Bytes;
use libp2p::identity::Keypair;
use lighthouse_version::{client_name, version};
use network_utils::enr_ext::CombinedKeyExt;
use network_utils::enr_ext::{EnrExt, QUIC6_ENR_KEY, QUIC_ENR_KEY};
use ssz::{Decode, Encode};
use ssz_types::BitVector;
use std::fs::File;
Expand Down
16 changes: 11 additions & 5 deletions beacon_node/lighthouse_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
//! queries and manages access to the discovery routing table.

pub(crate) mod enr;
pub mod enr_ext;

// Allow external use of the lighthouse ENR builder
use crate::service::TARGET_SUBNET_PEERS;
use crate::{metrics, ClearDialError};
use crate::{Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery};
use discv5::{enr::NodeId, Discv5};
pub use enr::{build_enr, load_enr_from_disk, use_or_load_enr, CombinedKey, Eth2Enr};
pub use enr_ext::{peer_id_to_node_id, CombinedKeyExt, EnrExt};
pub use libp2p::identity::{Keypair, PublicKey};
use network_utils::enr_ext::{peer_id_to_node_id, CombinedKeyExt, EnrExt};

use alloy_rlp::bytes::Bytes;
use enr::{ATTESTATION_BITFIELD_ENR_KEY, ETH2_ENR_KEY, SYNC_COMMITTEE_BITFIELD_ENR_KEY};
Expand All @@ -33,6 +32,7 @@ pub use libp2p::{
};
use logging::crit;
use lru::LruCache;
use network_utils::discovery_metrics;
use ssz::Encode;
use std::num::NonZeroUsize;
use std::{
Expand Down Expand Up @@ -687,7 +687,10 @@ impl<E: EthSpec> Discovery<E> {
min_ttl,
retries,
});
metrics::set_gauge(&metrics::DISCOVERY_QUEUE, self.queued_queries.len() as i64);
metrics::set_gauge(
&discovery_metrics::DISCOVERY_QUEUE,
self.queued_queries.len() as i64,
);
}
}

Expand Down Expand Up @@ -722,7 +725,10 @@ impl<E: EthSpec> Discovery<E> {
}
}
// Update the queue metric
metrics::set_gauge(&metrics::DISCOVERY_QUEUE, self.queued_queries.len() as i64);
metrics::set_gauge(
&discovery_metrics::DISCOVERY_QUEUE,
self.queued_queries.len() as i64,
);
processed
}

Expand Down Expand Up @@ -1227,7 +1233,7 @@ mod tests {
let spec = Arc::new(ChainSpec::default());
let keypair = secp256k1::Keypair::generate();
let mut config = NetworkConfig::default();
config.set_listening_addr(crate::ListenAddress::unused_v4_ports());
config.set_listening_addr(network_utils::listen_addr::ListenAddress::unused_v4_ports());
let config = Arc::new(config);
let enr_key: CombinedKey = CombinedKey::from_secp256k1(&keypair);
let next_fork_digest = [0; 4];
Expand Down
5 changes: 1 addition & 4 deletions beacon_node/lighthouse_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ mod config;
pub mod service;

pub mod discovery;
pub mod listen_addr;
pub mod metrics;
pub mod peer_manager;
pub mod rpc;
pub mod types;

use libp2p::swarm::DialError;
pub use listen_addr::*;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;
Expand Down Expand Up @@ -107,13 +105,12 @@ pub use crate::types::{
pub use prometheus_client;

pub use config::Config as NetworkConfig;
pub use discovery::{CombinedKeyExt, EnrExt, Eth2Enr};
pub use discovery::Eth2Enr;
pub use discv5;
pub use gossipsub::{IdentTopic, MessageAcceptance, MessageId, Topic, TopicHash};
pub use libp2p;
pub use libp2p::{core::ConnectedPoint, PeerId, Swarm};
pub use libp2p::{multiaddr, Multiaddr};
pub use metrics::scrape_discovery_metrics;
pub use peer_manager::{
peerdb::client::Client,
peerdb::score::{PeerAction, ReportSource},
Expand Down
Loading