mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-04 05:14:33 +00:00
Add network feature to eth2 (#8558)
This reverts some of the changes from #8524 by adding back the typed network endpoints with an optional `network` feature. Without the `network` feature, these endpoints (and associated dependencies) will not be built. This means the `enr`, `multiaddr` and `libp2p-identity` dependencies have returned but are now optional Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -3120,13 +3120,16 @@ dependencies = [
|
|||||||
"context_deserialize",
|
"context_deserialize",
|
||||||
"educe",
|
"educe",
|
||||||
"eip_3076",
|
"eip_3076",
|
||||||
|
"enr",
|
||||||
"eth2_keystore",
|
"eth2_keystore",
|
||||||
"ethereum_serde_utils",
|
"ethereum_serde_utils",
|
||||||
"ethereum_ssz",
|
"ethereum_ssz",
|
||||||
"ethereum_ssz_derive",
|
"ethereum_ssz_derive",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"libp2p-identity",
|
||||||
"mediatype",
|
"mediatype",
|
||||||
|
"multiaddr",
|
||||||
"pretty_reqwest_error",
|
"pretty_reqwest_error",
|
||||||
"proto_array",
|
"proto_array",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ alloy-primitives = { workspace = true }
|
|||||||
bitvec = { workspace = true }
|
bitvec = { workspace = true }
|
||||||
bls = { workspace = true }
|
bls = { workspace = true }
|
||||||
educe = { workspace = true }
|
educe = { workspace = true }
|
||||||
eth2 = { workspace = true, features = ["lighthouse"] }
|
eth2 = { workspace = true, features = ["lighthouse", "network"] }
|
||||||
eth2_network_config = { workspace = true }
|
eth2_network_config = { workspace = true }
|
||||||
ethereum_hashing = { workspace = true }
|
ethereum_hashing = { workspace = true }
|
||||||
ethereum_serde_utils = { workspace = true }
|
ethereum_serde_utils = { workspace = true }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ arc-swap = "1.6.0"
|
|||||||
bls = { workspace = true }
|
bls = { workspace = true }
|
||||||
builder_client = { path = "../builder_client" }
|
builder_client = { path = "../builder_client" }
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
eth2 = { workspace = true, features = ["events", "lighthouse"] }
|
eth2 = { workspace = true, features = ["events", "lighthouse", "network"] }
|
||||||
ethereum_serde_utils = { workspace = true }
|
ethereum_serde_utils = { workspace = true }
|
||||||
ethereum_ssz = { workspace = true }
|
ethereum_ssz = { workspace = true }
|
||||||
fixed_bytes = { workspace = true }
|
fixed_bytes = { workspace = true }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ bytes = { workspace = true }
|
|||||||
context_deserialize = { workspace = true }
|
context_deserialize = { workspace = true }
|
||||||
directory = { workspace = true }
|
directory = { workspace = true }
|
||||||
either = { workspace = true }
|
either = { workspace = true }
|
||||||
eth2 = { workspace = true, features = ["lighthouse"] }
|
eth2 = { workspace = true, features = ["lighthouse", "network"] }
|
||||||
ethereum_serde_utils = { workspace = true }
|
ethereum_serde_utils = { workspace = true }
|
||||||
ethereum_ssz = { workspace = true }
|
ethereum_ssz = { workspace = true }
|
||||||
execution_layer = { workspace = true }
|
execution_layer = { workspace = true }
|
||||||
|
|||||||
@@ -2140,12 +2140,9 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
let discovery_addresses = enr.multiaddr_p2p_udp();
|
let discovery_addresses = enr.multiaddr_p2p_udp();
|
||||||
Ok(api_types::GenericResponse::from(api_types::IdentityData {
|
Ok(api_types::GenericResponse::from(api_types::IdentityData {
|
||||||
peer_id: network_globals.local_peer_id().to_base58(),
|
peer_id: network_globals.local_peer_id().to_base58(),
|
||||||
enr: enr.to_base64(),
|
enr,
|
||||||
p2p_addresses: p2p_addresses.iter().map(|a| a.to_string()).collect(),
|
p2p_addresses,
|
||||||
discovery_addresses: discovery_addresses
|
discovery_addresses,
|
||||||
.iter()
|
|
||||||
.map(|a| a.to_string())
|
|
||||||
.collect(),
|
|
||||||
metadata: utils::from_meta_data::<T::EthSpec>(
|
metadata: utils::from_meta_data::<T::EthSpec>(
|
||||||
&network_globals.local_metadata,
|
&network_globals.local_metadata,
|
||||||
&chain.spec,
|
&chain.spec,
|
||||||
|
|||||||
@@ -2855,19 +2855,9 @@ impl ApiTester {
|
|||||||
|
|
||||||
let expected = IdentityData {
|
let expected = IdentityData {
|
||||||
peer_id: self.local_enr.peer_id().to_string(),
|
peer_id: self.local_enr.peer_id().to_string(),
|
||||||
enr: self.local_enr.to_base64(),
|
enr: self.local_enr.clone(),
|
||||||
p2p_addresses: self
|
p2p_addresses: self.local_enr.multiaddr_p2p_tcp(),
|
||||||
.local_enr
|
discovery_addresses: self.local_enr.multiaddr_p2p_udp(),
|
||||||
.multiaddr_p2p_tcp()
|
|
||||||
.iter()
|
|
||||||
.map(|a| a.to_string())
|
|
||||||
.collect(),
|
|
||||||
discovery_addresses: self
|
|
||||||
.local_enr
|
|
||||||
.multiaddr_p2p_udp()
|
|
||||||
.iter()
|
|
||||||
.map(|a| a.to_string())
|
|
||||||
.collect(),
|
|
||||||
metadata: MetaData::V2(MetaDataV2 {
|
metadata: MetaData::V2(MetaDataV2 {
|
||||||
seq_number: 0,
|
seq_number: 0,
|
||||||
attnets: "0x0000000000000000".to_string(),
|
attnets: "0x0000000000000000".to_string(),
|
||||||
@@ -2896,7 +2886,7 @@ impl ApiTester {
|
|||||||
pub async fn test_get_node_peers_by_id(self) -> Self {
|
pub async fn test_get_node_peers_by_id(self) -> Self {
|
||||||
let result = self
|
let result = self
|
||||||
.client
|
.client
|
||||||
.get_node_peers_by_id(&self.external_peer_id.to_string())
|
.get_node_peers_by_id(self.external_peer_id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.data;
|
.data;
|
||||||
|
|||||||
@@ -8,19 +8,23 @@ edition = { workspace = true }
|
|||||||
default = []
|
default = []
|
||||||
lighthouse = ["proto_array", "eth2_keystore", "eip_3076", "zeroize"]
|
lighthouse = ["proto_array", "eth2_keystore", "eip_3076", "zeroize"]
|
||||||
events = ["reqwest-eventsource", "futures", "futures-util"]
|
events = ["reqwest-eventsource", "futures", "futures-util"]
|
||||||
|
network = ["libp2p-identity", "enr", "multiaddr"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bls = { workspace = true }
|
bls = { workspace = true }
|
||||||
context_deserialize = { workspace = true }
|
context_deserialize = { workspace = true }
|
||||||
educe = { workspace = true }
|
educe = { workspace = true }
|
||||||
eip_3076 = { workspace = true, optional = true }
|
eip_3076 = { workspace = true, optional = true }
|
||||||
|
enr = { version = "0.13.0", features = ["ed25519"], optional = true }
|
||||||
eth2_keystore = { workspace = true, optional = true }
|
eth2_keystore = { workspace = true, optional = true }
|
||||||
ethereum_serde_utils = { workspace = true }
|
ethereum_serde_utils = { workspace = true }
|
||||||
ethereum_ssz = { workspace = true }
|
ethereum_ssz = { workspace = true }
|
||||||
ethereum_ssz_derive = { workspace = true }
|
ethereum_ssz_derive = { workspace = true }
|
||||||
futures = { workspace = true, optional = true }
|
futures = { workspace = true, optional = true }
|
||||||
futures-util = { version = "0.3.8", optional = true }
|
futures-util = { version = "0.3.8", optional = true }
|
||||||
|
libp2p-identity = { version = "0.2", features = ["peerid"], optional = true }
|
||||||
mediatype = "0.19.13"
|
mediatype = "0.19.13"
|
||||||
|
multiaddr = { version = "0.18.2", optional = true }
|
||||||
pretty_reqwest_error = { workspace = true }
|
pretty_reqwest_error = { workspace = true }
|
||||||
proto_array = { workspace = true, optional = true }
|
proto_array = { workspace = true, optional = true }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ use educe::Educe;
|
|||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
#[cfg(feature = "events")]
|
#[cfg(feature = "events")]
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
#[cfg(feature = "network")]
|
||||||
|
use libp2p_identity::PeerId;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
Body, IntoUrl, RequestBuilder, Response,
|
Body, IntoUrl, RequestBuilder, Response,
|
||||||
header::{HeaderMap, HeaderValue},
|
header::{HeaderMap, HeaderValue},
|
||||||
@@ -1939,6 +1941,7 @@ impl BeaconNodeHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `GET node/identity`
|
/// `GET node/identity`
|
||||||
|
#[cfg(feature = "network")]
|
||||||
pub async fn get_node_identity(&self) -> Result<GenericResponse<IdentityData>, Error> {
|
pub async fn get_node_identity(&self) -> Result<GenericResponse<IdentityData>, Error> {
|
||||||
let mut path = self.eth_path(V1)?;
|
let mut path = self.eth_path(V1)?;
|
||||||
|
|
||||||
@@ -1986,9 +1989,10 @@ impl BeaconNodeHttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `GET node/peers/{peer_id}`
|
/// `GET node/peers/{peer_id}`
|
||||||
|
#[cfg(feature = "network")]
|
||||||
pub async fn get_node_peers_by_id(
|
pub async fn get_node_peers_by_id(
|
||||||
&self,
|
&self,
|
||||||
peer_id: &str,
|
peer_id: PeerId,
|
||||||
) -> Result<GenericResponse<PeerData>, Error> {
|
) -> Result<GenericResponse<PeerData>, Error> {
|
||||||
let mut path = self.eth_path(V1)?;
|
let mut path = self.eth_path(V1)?;
|
||||||
|
|
||||||
@@ -1996,7 +2000,7 @@ impl BeaconNodeHttpClient {
|
|||||||
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
|
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
|
||||||
.push("node")
|
.push("node")
|
||||||
.push("peers")
|
.push("peers")
|
||||||
.push(peer_id);
|
.push(&peer_id.to_string());
|
||||||
|
|
||||||
self.get(path).await
|
self.get(path).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use bls::{PublicKeyBytes, SecretKey, Signature, SignatureBytes};
|
use bls::{PublicKeyBytes, SecretKey, Signature, SignatureBytes};
|
||||||
use context_deserialize::ContextDeserialize;
|
use context_deserialize::ContextDeserialize;
|
||||||
|
#[cfg(feature = "network")]
|
||||||
|
use enr::{CombinedKey, Enr};
|
||||||
use mediatype::{MediaType, MediaTypeList, names};
|
use mediatype::{MediaType, MediaTypeList, names};
|
||||||
|
#[cfg(feature = "network")]
|
||||||
|
use multiaddr::Multiaddr;
|
||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use serde_utils::quoted_u64::Quoted;
|
use serde_utils::quoted_u64::Quoted;
|
||||||
@@ -559,12 +563,13 @@ pub struct ChainHeadData {
|
|||||||
pub execution_optimistic: Option<bool>,
|
pub execution_optimistic: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "network")]
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct IdentityData {
|
pub struct IdentityData {
|
||||||
pub peer_id: String,
|
pub peer_id: String,
|
||||||
pub enr: String,
|
pub enr: Enr<CombinedKey>,
|
||||||
pub p2p_addresses: Vec<String>,
|
pub p2p_addresses: Vec<Multiaddr>,
|
||||||
pub discovery_addresses: Vec<String>,
|
pub discovery_addresses: Vec<Multiaddr>,
|
||||||
pub metadata: MetaData,
|
pub metadata: MetaData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user