Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion Cargo.lock

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

44 changes: 17 additions & 27 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod builder_states;
mod database;
mod light_client;
mod metrics;
mod peer;
mod produce_block;
mod proposer_duties;
mod publish_attestations;
Expand Down Expand Up @@ -3092,15 +3093,13 @@ pub fn serve<T: BeaconChainTypes>(
};

// the eth2 API spec implies only peers we have been connected to at some point should be included.
if let Some(dir) = peer_info.connection_direction().as_ref() {
if let Some(&dir) = peer_info.connection_direction() {
return Ok(api_types::GenericResponse::from(api_types::PeerData {
peer_id: peer_id.to_string(),
enr: peer_info.enr().map(|enr| enr.to_base64()),
last_seen_p2p_address: address,
direction: api_types::PeerDirection::from((*dir).clone()),
state: api_types::PeerState::from(
peer_info.connection_status().clone(),
),
direction: dir.into(),
state: peer_info.connection_status().clone().into(),
}));
}
}
Expand Down Expand Up @@ -3141,11 +3140,9 @@ pub fn serve<T: BeaconChainTypes>(
};

// the eth2 API spec implies only peers we have been connected to at some point should be included.
if let Some(dir) = peer_info.connection_direction() {
let direction = api_types::PeerDirection::from((*dir).clone());
let state = api_types::PeerState::from(
peer_info.connection_status().clone(),
);
if let Some(&dir) = peer_info.connection_direction() {
let direction = dir.into();
let state = peer_info.connection_status().clone().into();

let state_matches = query.state.as_ref().map_or(true, |states| {
states.iter().any(|state_param| *state_param == state)
Expand Down Expand Up @@ -4205,18 +4202,15 @@ pub fn serve<T: BeaconChainTypes>(
|task_spawner: TaskSpawner<T::EthSpec>,
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
task_spawner.blocking_json_task(Priority::P1, move || {
let mut peers = vec![];
for (peer_id, peer_info) in network_globals.peers.read().peers() {
peers.push(eth2::lighthouse::Peer {
Ok(network_globals
.peers
.read()
.peers()
.map(|(peer_id, peer_info)| peer::Peer {
peer_id: peer_id.to_string(),
peer_info: serde_json::to_value(peer_info).map_err(|e| {
warp_utils::reject::custom_not_found(format!(
"unable to serialize peer_info: {e:?}",
))
})?,
});
}
Ok(peers)
peer_info: peer_info.clone(),
})
.collect::<Vec<_>>())
})
},
);
Expand All @@ -4234,13 +4228,9 @@ pub fn serve<T: BeaconChainTypes>(
task_spawner.blocking_json_task(Priority::P1, move || {
let mut peers = vec![];
for (peer_id, peer_info) in network_globals.peers.read().connected_peers() {
peers.push(eth2::lighthouse::Peer {
peers.push(peer::Peer {
peer_id: peer_id.to_string(),
peer_info: serde_json::to_value(peer_info).map_err(|e| {
warp_utils::reject::custom_not_found(format!(
"unable to serialize peer_info: {e:?}",
))
})?,
peer_info: peer_info.clone(),
});
}
Ok(peers)
Expand Down
13 changes: 13 additions & 0 deletions beacon_node/http_api/src/peer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::Serialize;
use lighthouse_network::PeerInfo;
use types::EthSpec;

/// Information returned by `peers` and `connected_peers`.
#[derive(Debug, Clone, Serialize)]
#[serde(bound = "E: EthSpec")]
pub(crate) struct Peer<E: EthSpec> {
/// The Peer's ID
pub peer_id: String,
/// The PeerInfo associated with the peer.
pub peer_info: PeerInfo<E>,
}
21 changes: 0 additions & 21 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5675,25 +5675,6 @@ impl ApiTester {
self
}

pub async fn test_get_lighthouse_database_info(self) -> Self {
let info = self.client.get_lighthouse_database_info().await.unwrap();

assert_eq!(
serde_json::from_value::<AnchorInfo>(info.get("anchor").unwrap().clone()).unwrap(),
self.chain.store.get_anchor_info()
);
assert_eq!(
serde_json::from_value::<Split>(info.get("split").unwrap().clone()).unwrap(),
self.chain.store.get_split_info()
);
assert_eq!(
serde_json::from_value::<u64>(info.get("schema_version").unwrap().clone()).unwrap(),
store::metadata::CURRENT_SCHEMA_VERSION.as_u64()
);

self
}

pub async fn test_post_lighthouse_database_reconstruct(self) -> Self {
let response = self
.client
Expand Down Expand Up @@ -7232,8 +7213,6 @@ async fn lighthouse_endpoints() {
.await
.test_get_lighthouse_staking()
.await
.test_get_lighthouse_database_info()
.await
.test_post_lighthouse_database_reconstruct()
.await
.test_post_lighthouse_liveness()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<E: EthSpec> PeerInfo<E> {
}

/// Connection Direction of connection.
#[derive(Debug, Clone, Serialize, AsRefStr)]
#[derive(Debug, Clone, Copy, Serialize, AsRefStr)]
#[strum(serialize_all = "snake_case")]
pub enum ConnectionDirection {
/// The connection was established by a peer dialing us.
Expand Down
22 changes: 0 additions & 22 deletions common/eth2/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ pub use block_rewards::{AttestationRewards, BlockReward, BlockRewardMeta, BlockR
four_byte_option_impl!(four_byte_option_u64, u64);
four_byte_option_impl!(four_byte_option_hash256, Hash256);

/// Information returned by `peers` and `connected_peers`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Peer {
/// The Peer's ID
pub peer_id: String,
/// The PeerInfo associated with the peer.
pub peer_info: serde_json::Value,
}

/// The results of validators voting during an epoch.
///
/// Provides information about the current and previous epochs.
Expand Down Expand Up @@ -361,19 +352,6 @@ impl BeaconNodeHttpClient {
self.get_opt::<(), _>(path).await.map(|opt| opt.is_some())
}

/// `GET lighthouse/database/info`
pub async fn get_lighthouse_database_info(&self) -> Result<serde_json::Value, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("lighthouse")
.push("database")
.push("info");

self.get(path).await
}

/// `POST lighthouse/database/reconstruct`
pub async fn post_lighthouse_database_reconstruct(&self) -> Result<String, Error> {
let mut path = self.server.full.clone();
Expand Down
1 change: 0 additions & 1 deletion common/warp_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = { workspace = true }
bytes = { workspace = true }
eth2 = { workspace = true }
headers = "0.3.2"
metrics = { workspace = true }
safe_arith = { workspace = true }
serde = { workspace = true }
serde_array_query = "0.1.0"
Expand Down
Loading