mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Fix ui endpoint
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::http_metrics::metrics::{inc_counter_vec, ENDPOINT_ERRORS, ENDPOINT_RE
|
||||
use environment::RuntimeContext;
|
||||
use eth2::BeaconNodeHttpClient;
|
||||
use futures::future;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use slog::{debug, error, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::cmp::Ordering;
|
||||
@@ -138,11 +138,47 @@ pub enum CandidateError {
|
||||
TimeDiscrepancy,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
impl std::fmt::Display for CandidateError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
CandidateError::PreGenesis => write!(f, "PreGenesis"),
|
||||
CandidateError::Uninitialized => write!(f, "Uninitialized"),
|
||||
CandidateError::Offline => write!(f, "Offline"),
|
||||
CandidateError::Incompatible => write!(f, "Incompatible"),
|
||||
CandidateError::TimeDiscrepancy => write!(f, "TimeDiscrepancy"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct CandidateInfo {
|
||||
pub index: usize,
|
||||
pub node: String,
|
||||
pub health: Option<BeaconNodeHealth>,
|
||||
pub endpoint: String,
|
||||
pub health: Result<BeaconNodeHealth, CandidateError>,
|
||||
}
|
||||
|
||||
impl Serialize for CandidateInfo {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_struct("CandidateInfo", 2)?;
|
||||
|
||||
state.serialize_field("index", &self.index)?;
|
||||
state.serialize_field("endpoint", &self.endpoint)?;
|
||||
|
||||
// Serialize either the health or the error field based on the Result
|
||||
match &self.health {
|
||||
Ok(health) => {
|
||||
state.serialize_field("health", health)?;
|
||||
}
|
||||
Err(e) => {
|
||||
state.serialize_field("error", &e.to_string())?;
|
||||
}
|
||||
}
|
||||
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a `BeaconNodeHttpClient` inside a `BeaconNodeFallback` that may or may not be used
|
||||
@@ -417,8 +453,8 @@ impl<T: SlotClock, E: EthSpec> BeaconNodeFallback<T, E> {
|
||||
|
||||
candidate_info.push(CandidateInfo {
|
||||
index: candidate.index,
|
||||
node: candidate.beacon_node.to_string(),
|
||||
health: health.ok(),
|
||||
endpoint: candidate.beacon_node.to_string(),
|
||||
health,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@ mod tests;
|
||||
|
||||
pub mod test_utils;
|
||||
|
||||
use crate::beacon_node_fallback::CandidateError;
|
||||
use crate::beacon_node_health::BeaconNodeHealth;
|
||||
use crate::beacon_node_fallback::CandidateInfo;
|
||||
use crate::http_api::graffiti::{delete_graffiti, get_graffiti, set_graffiti};
|
||||
|
||||
use crate::http_api::create_signed_voluntary_exit::create_signed_voluntary_exit;
|
||||
@@ -419,21 +418,28 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(block_service_filter.clone())
|
||||
.then(|block_filter: BlockService<T, E>| async move {
|
||||
let mut result: HashMap<(usize, String), Result<BeaconNodeHealth, CandidateError>> =
|
||||
HashMap::new();
|
||||
let mut result: HashMap<String, Vec<CandidateInfo>> = HashMap::new();
|
||||
|
||||
let mut beacon_nodes = Vec::new();
|
||||
for node in &*block_filter.beacon_nodes.candidates.read().await {
|
||||
result.insert(
|
||||
(node.index, node.beacon_node.to_string()),
|
||||
*node.health.read().await,
|
||||
);
|
||||
beacon_nodes.push(CandidateInfo {
|
||||
index: node.index,
|
||||
endpoint: node.beacon_node.to_string(),
|
||||
health: *node.health.read().await,
|
||||
});
|
||||
}
|
||||
if let Some(proposer_nodes) = &block_filter.proposer_nodes {
|
||||
for node in &*proposer_nodes.candidates.read().await {
|
||||
result.insert(
|
||||
(node.index, node.beacon_node.to_string()),
|
||||
*node.health.read().await,
|
||||
);
|
||||
result.insert("beacon_nodes".to_string(), beacon_nodes);
|
||||
|
||||
if let Some(proposer_nodes_list) = &block_filter.proposer_nodes {
|
||||
let mut proposer_nodes = Vec::new();
|
||||
for node in &*proposer_nodes_list.candidates.read().await {
|
||||
proposer_nodes.push(CandidateInfo {
|
||||
index: node.index,
|
||||
endpoint: node.beacon_node.to_string(),
|
||||
health: *node.health.read().await,
|
||||
});
|
||||
}
|
||||
result.insert("proposer_nodes".to_string(), proposer_nodes);
|
||||
}
|
||||
|
||||
blocking_json_task(move || Ok(api_types::GenericResponse::from(result))).await
|
||||
|
||||
@@ -59,7 +59,7 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
|
||||
if num_synced > 0 {
|
||||
let primary = candidate_info
|
||||
.first()
|
||||
.map(|candidate| candidate.node.as_str())
|
||||
.map(|candidate| candidate.endpoint.as_str())
|
||||
.unwrap_or("None");
|
||||
info!(
|
||||
log,
|
||||
@@ -85,13 +85,13 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
|
||||
}
|
||||
|
||||
for info in candidate_info {
|
||||
if let Some(health) = info.health {
|
||||
if let Ok(health) = info.health {
|
||||
debug!(
|
||||
log,
|
||||
"Beacon node info";
|
||||
"status" => "Connected",
|
||||
"index" => info.index,
|
||||
"endpoint" => info.node,
|
||||
"endpoint" => info.endpoint,
|
||||
"head_slot" => %health.head,
|
||||
"is_optimistic" => ?health.optimistic_status,
|
||||
"execution_engine_status" => ?health.execution_status,
|
||||
@@ -103,7 +103,7 @@ async fn notify<T: SlotClock + 'static, E: EthSpec>(
|
||||
"Beacon node info";
|
||||
"status" => "Disconnected",
|
||||
"index" => info.index,
|
||||
"endpoint" => info.node,
|
||||
"endpoint" => info.endpoint,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user