mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-11 05:20:07 +00:00
df40700ddd
## Description The `eth2_libp2p` crate was originally named and designed to incorporate a simple libp2p integration into lighthouse. Since its origins the crates purpose has expanded dramatically. It now houses a lot more sophistication that is specific to lighthouse and no longer just a libp2p integration. As of this writing it currently houses the following high-level lighthouse-specific logic: - Lighthouse's implementation of the eth2 RPC protocol and specific encodings/decodings - Integration and handling of ENRs with respect to libp2p and eth2 - Lighthouse's discovery logic, its integration with discv5 and logic about searching and handling peers. - Lighthouse's peer manager - This is a large module handling various aspects of Lighthouse's network, such as peer scoring, handling pings and metadata, connection maintenance and recording, etc. - Lighthouse's peer database - This is a collection of information stored for each individual peer which is specific to lighthouse. We store connection state, sync state, last seen ips and scores etc. The data stored for each peer is designed for various elements of the lighthouse code base such as syncing and the http api. - Gossipsub scoring - This stores a collection of gossipsub 1.1 scoring mechanisms that are continuously analyssed and updated based on the ethereum 2 networks and how Lighthouse performs on these networks. - Lighthouse specific types for managing gossipsub topics, sync status and ENR fields - Lighthouse's network HTTP API metrics - A collection of metrics for lighthouse network monitoring - Lighthouse's custom configuration of all networking protocols, RPC, gossipsub, discovery, identify and libp2p. Therefore it makes sense to rename the crate to be more akin to its current purposes, simply that it manages the majority of Lighthouse's network stack. This PR renames this crate to `lighthouse_network` Co-authored-by: Paul Hauner <paul@paulhauner.com>
63 lines
2.1 KiB
Rust
63 lines
2.1 KiB
Rust
extern crate slog;
|
|
|
|
pub mod config;
|
|
mod metrics;
|
|
mod notifier;
|
|
|
|
pub mod builder;
|
|
pub mod error;
|
|
|
|
use beacon_chain::BeaconChain;
|
|
use lighthouse_network::{Enr, Multiaddr, NetworkGlobals};
|
|
use std::net::SocketAddr;
|
|
use std::sync::Arc;
|
|
|
|
pub use beacon_chain::{BeaconChainTypes, Eth1ChainBackend};
|
|
pub use builder::ClientBuilder;
|
|
pub use config::{ClientGenesis, Config as ClientConfig};
|
|
pub use eth2_config::Eth2Config;
|
|
|
|
/// The core "beacon node" client.
|
|
///
|
|
/// Holds references to running services, cleanly shutting them down when dropped.
|
|
pub struct Client<T: BeaconChainTypes> {
|
|
beacon_chain: Option<Arc<BeaconChain<T>>>,
|
|
network_globals: Option<Arc<NetworkGlobals<T::EthSpec>>>,
|
|
/// Listen address for the standard eth2.0 API, if the service was started.
|
|
http_api_listen_addr: Option<SocketAddr>,
|
|
/// Listen address for the HTTP server which serves Prometheus metrics.
|
|
http_metrics_listen_addr: Option<SocketAddr>,
|
|
}
|
|
|
|
impl<T: BeaconChainTypes> Client<T> {
|
|
/// Returns an `Arc` reference to the client's `BeaconChain`, if it was started.
|
|
pub fn beacon_chain(&self) -> Option<Arc<BeaconChain<T>>> {
|
|
self.beacon_chain.clone()
|
|
}
|
|
|
|
/// Returns the address of the client's standard eth2.0 API server, if it was started.
|
|
pub fn http_api_listen_addr(&self) -> Option<SocketAddr> {
|
|
self.http_api_listen_addr
|
|
}
|
|
|
|
/// Returns the address of the client's HTTP Prometheus metrics server, if it was started.
|
|
pub fn http_metrics_listen_addr(&self) -> Option<SocketAddr> {
|
|
self.http_metrics_listen_addr
|
|
}
|
|
|
|
/// Returns the port of the client's libp2p stack, if it was started.
|
|
pub fn libp2p_listen_port(&self) -> Option<u16> {
|
|
self.network_globals.as_ref().map(|n| n.listen_port_tcp())
|
|
}
|
|
|
|
/// Returns the list of libp2p addresses the client is listening to.
|
|
pub fn libp2p_listen_addresses(&self) -> Option<Vec<Multiaddr>> {
|
|
self.network_globals.as_ref().map(|n| n.listen_multiaddrs())
|
|
}
|
|
|
|
/// Returns the local libp2p ENR of this node, for network discovery.
|
|
pub fn enr(&self) -> Option<Enr> {
|
|
self.network_globals.as_ref().map(|n| n.local_enr())
|
|
}
|
|
}
|