mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
Merge remote-tracking branch 'origin/unstable' into capella-update
This commit is contained in:
@@ -2980,6 +2980,22 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
})
|
||||
});
|
||||
|
||||
// POST lighthouse/ui/validator_metrics
|
||||
let post_lighthouse_ui_validator_metrics = warp::path("lighthouse")
|
||||
.and(warp::path("ui"))
|
||||
.and(warp::path("validator_metrics"))
|
||||
.and(warp::path::end())
|
||||
.and(warp::body::json())
|
||||
.and(chain_filter.clone())
|
||||
.and_then(
|
||||
|request_data: ui::ValidatorMetricsRequestData, chain: Arc<BeaconChain<T>>| {
|
||||
blocking_json_task(move || {
|
||||
ui::post_validator_monitor_metrics(request_data, chain)
|
||||
.map(api_types::GenericResponse::from)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// GET lighthouse/syncing
|
||||
let get_lighthouse_syncing = warp::path("lighthouse")
|
||||
.and(warp::path("syncing"))
|
||||
@@ -3431,6 +3447,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.or(get_validator_sync_committee_contribution.boxed())
|
||||
.or(get_lighthouse_health.boxed())
|
||||
.or(get_lighthouse_ui_health.boxed())
|
||||
.or(get_lighthouse_ui_validator_count.boxed())
|
||||
.or(get_lighthouse_syncing.boxed())
|
||||
.or(get_lighthouse_nat.boxed())
|
||||
.or(get_lighthouse_peers.boxed())
|
||||
@@ -3448,7 +3465,6 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.or(get_lighthouse_attestation_performance.boxed())
|
||||
.or(get_lighthouse_block_packing_efficiency.boxed())
|
||||
.or(get_lighthouse_merge_readiness.boxed())
|
||||
.or(get_lighthouse_ui_validator_count.boxed())
|
||||
.or(get_events.boxed()),
|
||||
)
|
||||
.boxed()
|
||||
@@ -3473,7 +3489,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.or(post_lighthouse_liveness.boxed())
|
||||
.or(post_lighthouse_database_reconstruct.boxed())
|
||||
.or(post_lighthouse_database_historical_blocks.boxed())
|
||||
.or(post_lighthouse_block_rewards.boxed()),
|
||||
.or(post_lighthouse_block_rewards.boxed())
|
||||
.or(post_lighthouse_ui_validator_metrics.boxed()),
|
||||
))
|
||||
.recover(warp_utils::reject::handle_rejection)
|
||||
.with(slog_logging(log.clone()))
|
||||
|
||||
@@ -5,7 +5,7 @@ use beacon_chain::{
|
||||
};
|
||||
use lighthouse_network::{PubsubMessage, SignedBeaconBlockAndBlobsSidecar};
|
||||
use network::NetworkMessage;
|
||||
use slog::{crit, error, info, warn, Logger};
|
||||
use slog::{error, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
@@ -90,10 +90,10 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
//
|
||||
// Check to see the thresholds are non-zero to avoid logging errors with small
|
||||
// slot times (e.g., during testing)
|
||||
let crit_threshold = chain.slot_clock.unagg_attestation_production_delay();
|
||||
let error_threshold = crit_threshold / 2;
|
||||
if delay >= crit_threshold {
|
||||
crit!(
|
||||
let too_late_threshold = chain.slot_clock.unagg_attestation_production_delay();
|
||||
let delayed_threshold = too_late_threshold / 2;
|
||||
if delay >= too_late_threshold {
|
||||
error!(
|
||||
log,
|
||||
"Block was broadcast too late";
|
||||
"msg" => "system may be overloaded, block likely to be orphaned",
|
||||
@@ -101,7 +101,7 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
"slot" => block.slot(),
|
||||
"root" => ?root,
|
||||
)
|
||||
} else if delay >= error_threshold {
|
||||
} else if delay >= delayed_threshold {
|
||||
error!(
|
||||
log,
|
||||
"Block broadcast was delayed";
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use beacon_chain::{metrics, BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use eth2::types::ValidatorStatus;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use warp_utils::reject::beacon_chain_error;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ValidatorCountResponse {
|
||||
pub active_ongoing: u64,
|
||||
pub active_exiting: u64,
|
||||
@@ -69,3 +70,126 @@ pub fn get_validator_count<T: BeaconChainTypes>(
|
||||
exited_slashed,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub struct ValidatorMetricsRequestData {
|
||||
indices: Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub struct ValidatorMetrics {
|
||||
attestation_hits: u64,
|
||||
attestation_misses: u64,
|
||||
attestation_hit_percentage: f64,
|
||||
attestation_head_hits: u64,
|
||||
attestation_head_misses: u64,
|
||||
attestation_head_hit_percentage: f64,
|
||||
attestation_target_hits: u64,
|
||||
attestation_target_misses: u64,
|
||||
attestation_target_hit_percentage: f64,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub struct ValidatorMetricsResponse {
|
||||
validators: HashMap<String, ValidatorMetrics>,
|
||||
}
|
||||
|
||||
pub fn post_validator_monitor_metrics<T: BeaconChainTypes>(
|
||||
request_data: ValidatorMetricsRequestData,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
) -> Result<ValidatorMetricsResponse, warp::Rejection> {
|
||||
let validator_ids = chain
|
||||
.validator_monitor
|
||||
.read()
|
||||
.get_all_monitored_validators()
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<HashSet<String>>();
|
||||
|
||||
let indices = request_data
|
||||
.indices
|
||||
.iter()
|
||||
.map(|index| index.to_string())
|
||||
.collect::<HashSet<String>>();
|
||||
|
||||
let ids = validator_ids
|
||||
.intersection(&indices)
|
||||
.collect::<HashSet<&String>>();
|
||||
|
||||
let mut validators = HashMap::new();
|
||||
|
||||
for id in ids {
|
||||
let attestation_hits = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_HIT,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let attestation_misses = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_ATTESTER_MISS,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let attestations = attestation_hits + attestation_misses;
|
||||
let attestation_hit_percentage: f64 = if attestations == 0 {
|
||||
0.0
|
||||
} else {
|
||||
(100 * attestation_hits / attestations) as f64
|
||||
};
|
||||
|
||||
let attestation_head_hits = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_HIT,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let attestation_head_misses = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_HEAD_ATTESTER_MISS,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let head_attestations = attestation_head_hits + attestation_head_misses;
|
||||
let attestation_head_hit_percentage: f64 = if head_attestations == 0 {
|
||||
0.0
|
||||
} else {
|
||||
(100 * attestation_head_hits / head_attestations) as f64
|
||||
};
|
||||
|
||||
let attestation_target_hits = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_HIT,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let attestation_target_misses = metrics::get_int_counter(
|
||||
&metrics::VALIDATOR_MONITOR_PREV_EPOCH_ON_CHAIN_TARGET_ATTESTER_MISS,
|
||||
&[id],
|
||||
)
|
||||
.map(|counter| counter.get())
|
||||
.unwrap_or(0);
|
||||
let target_attestations = attestation_target_hits + attestation_target_misses;
|
||||
let attestation_target_hit_percentage: f64 = if target_attestations == 0 {
|
||||
0.0
|
||||
} else {
|
||||
(100 * attestation_target_hits / target_attestations) as f64
|
||||
};
|
||||
|
||||
let metrics = ValidatorMetrics {
|
||||
attestation_hits,
|
||||
attestation_misses,
|
||||
attestation_hit_percentage,
|
||||
attestation_head_hits,
|
||||
attestation_head_misses,
|
||||
attestation_head_hit_percentage,
|
||||
attestation_target_hits,
|
||||
attestation_target_misses,
|
||||
attestation_target_hit_percentage,
|
||||
};
|
||||
|
||||
validators.insert(id.clone(), metrics);
|
||||
}
|
||||
|
||||
Ok(ValidatorMetricsResponse { validators })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user