mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Add IsOptimistic enum for readability
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
//! succeed.
|
//! succeed.
|
||||||
|
|
||||||
use crate::beacon_node_health::{
|
use crate::beacon_node_health::{
|
||||||
BeaconNodeHealth, BeaconNodeSyncDistanceTiers, ExecutionEngineHealth, SyncDistanceTier,
|
BeaconNodeHealth, BeaconNodeSyncDistanceTiers, ExecutionEngineHealth, IsOptimistic,
|
||||||
|
SyncDistanceTier,
|
||||||
};
|
};
|
||||||
use crate::check_synced::check_node_health;
|
use crate::check_synced::check_node_health;
|
||||||
use crate::http_metrics::metrics::{inc_counter_vec, ENDPOINT_ERRORS, ENDPOINT_REQUESTS};
|
use crate::http_metrics::metrics::{inc_counter_vec, ENDPOINT_ERRORS, ENDPOINT_REQUESTS};
|
||||||
@@ -209,10 +210,16 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
|
|||||||
ExecutionEngineHealth::Healthy
|
ExecutionEngineHealth::Healthy
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let optimistic_status = if is_optimistic {
|
||||||
|
IsOptimistic::Yes
|
||||||
|
} else {
|
||||||
|
IsOptimistic::No
|
||||||
|
};
|
||||||
|
|
||||||
let new_health = BeaconNodeHealth::from_status(
|
let new_health = BeaconNodeHealth::from_status(
|
||||||
self.id,
|
self.id,
|
||||||
head,
|
head,
|
||||||
is_optimistic,
|
optimistic_status,
|
||||||
execution_status,
|
execution_status,
|
||||||
distance_tiers,
|
distance_tiers,
|
||||||
slot_clock,
|
slot_clock,
|
||||||
@@ -631,7 +638,7 @@ mod tests {
|
|||||||
|
|
||||||
// These fields is irrelvant for sorting. They are set to arbitrary values.
|
// These fields is irrelvant for sorting. They are set to arbitrary values.
|
||||||
let head = Slot::new(99);
|
let head = Slot::new(99);
|
||||||
let optimistic_status = false;
|
let optimistic_status = IsOptimistic::No;
|
||||||
let execution_status = ExecutionEngineHealth::Healthy;
|
let execution_status = ExecutionEngineHealth::Healthy;
|
||||||
|
|
||||||
let candidate_1 = new_candidate(1);
|
let candidate_1 = new_candidate(1);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ const SYNC_DISTANCE_MEDIUM_MODIFIER: Slot = Slot::new(31);
|
|||||||
|
|
||||||
type HealthTier = u8;
|
type HealthTier = u8;
|
||||||
type SyncDistance = Slot;
|
type SyncDistance = Slot;
|
||||||
type OptimisticStatus = bool;
|
|
||||||
|
|
||||||
/// Helpful enum which is used when pattern matching to determine health tier.
|
/// Helpful enum which is used when pattern matching to determine health tier.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
@@ -77,13 +76,20 @@ impl Default for BeaconNodeSyncDistanceTiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Execution Node health metrics.
|
/// Execution Node health metrics.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
///
|
||||||
#[allow(dead_code)]
|
/// Currently only considers `el_offline`.
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ExecutionEngineHealth {
|
pub enum ExecutionEngineHealth {
|
||||||
Healthy,
|
Healthy,
|
||||||
Unhealthy,
|
Unhealthy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum IsOptimistic {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct BeaconNodeHealthTier {
|
pub struct BeaconNodeHealthTier {
|
||||||
pub tier: HealthTier,
|
pub tier: HealthTier,
|
||||||
@@ -144,7 +150,7 @@ pub struct BeaconNodeHealth {
|
|||||||
// The slot number of the head.
|
// The slot number of the head.
|
||||||
pub head: Slot,
|
pub head: Slot,
|
||||||
// Whether the node is optimistically synced.
|
// Whether the node is optimistically synced.
|
||||||
pub optimistic_status: OptimisticStatus,
|
pub optimistic_status: IsOptimistic,
|
||||||
// The status of the nodes connected Execution Engine.
|
// The status of the nodes connected Execution Engine.
|
||||||
pub execution_status: ExecutionEngineHealth,
|
pub execution_status: ExecutionEngineHealth,
|
||||||
// The overall health tier of the Beacon Node. Used to rank the nodes for the purposes of
|
// The overall health tier of the Beacon Node. Used to rank the nodes for the purposes of
|
||||||
@@ -174,7 +180,7 @@ impl BeaconNodeHealth {
|
|||||||
pub fn from_status<T: SlotClock>(
|
pub fn from_status<T: SlotClock>(
|
||||||
id: usize,
|
id: usize,
|
||||||
head: Slot,
|
head: Slot,
|
||||||
optimistic_status: OptimisticStatus,
|
optimistic_status: IsOptimistic,
|
||||||
execution_status: ExecutionEngineHealth,
|
execution_status: ExecutionEngineHealth,
|
||||||
distance_tiers: &BeaconNodeSyncDistanceTiers,
|
distance_tiers: &BeaconNodeSyncDistanceTiers,
|
||||||
slot_clock: &T,
|
slot_clock: &T,
|
||||||
@@ -214,7 +220,7 @@ impl BeaconNodeHealth {
|
|||||||
|
|
||||||
fn compute_health_tier(
|
fn compute_health_tier(
|
||||||
sync_distance: SyncDistance,
|
sync_distance: SyncDistance,
|
||||||
optimistic_status: OptimisticStatus,
|
optimistic_status: IsOptimistic,
|
||||||
execution_status: ExecutionEngineHealth,
|
execution_status: ExecutionEngineHealth,
|
||||||
sync_distance_tiers: &BeaconNodeSyncDistanceTiers,
|
sync_distance_tiers: &BeaconNodeSyncDistanceTiers,
|
||||||
) -> BeaconNodeHealthTier {
|
) -> BeaconNodeHealthTier {
|
||||||
@@ -222,52 +228,52 @@ impl BeaconNodeHealth {
|
|||||||
let health = (sync_distance_tier, optimistic_status, execution_status);
|
let health = (sync_distance_tier, optimistic_status, execution_status);
|
||||||
|
|
||||||
match health {
|
match health {
|
||||||
(SyncDistanceTier::Synced, false, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Synced, IsOptimistic::No, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(1, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(1, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Small, false, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Small, IsOptimistic::No, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(2, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(2, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Synced, false, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Synced, IsOptimistic::No, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(3, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(3, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Medium, false, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Medium, IsOptimistic::No, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(4, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(4, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Synced, true, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Synced, IsOptimistic::Yes, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(5, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(5, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Synced, true, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Synced, IsOptimistic::Yes, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(6, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(6, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Small, false, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Small, IsOptimistic::No, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(7, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(7, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Small, true, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Small, IsOptimistic::Yes, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(8, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(8, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Small, true, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Small, IsOptimistic::Yes, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(9, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(9, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Large, false, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Large, IsOptimistic::No, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(10, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(10, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Medium, false, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Medium, IsOptimistic::No, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(11, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(11, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Medium, true, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Medium, IsOptimistic::Yes, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(12, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(12, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Medium, true, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Medium, IsOptimistic::Yes, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(13, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(13, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Large, false, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Large, IsOptimistic::No, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(14, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(14, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Large, true, ExecutionEngineHealth::Healthy) => {
|
(SyncDistanceTier::Large, IsOptimistic::Yes, ExecutionEngineHealth::Healthy) => {
|
||||||
BeaconNodeHealthTier::new(15, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(15, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
(SyncDistanceTier::Large, true, ExecutionEngineHealth::Unhealthy) => {
|
(SyncDistanceTier::Large, IsOptimistic::Yes, ExecutionEngineHealth::Unhealthy) => {
|
||||||
BeaconNodeHealthTier::new(16, sync_distance, sync_distance_tier)
|
BeaconNodeHealthTier::new(16, sync_distance, sync_distance_tier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,7 +284,7 @@ impl BeaconNodeHealth {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::ExecutionEngineHealth::{Healthy, Unhealthy};
|
use super::ExecutionEngineHealth::{Healthy, Unhealthy};
|
||||||
use super::{BeaconNodeHealth, BeaconNodeSyncDistanceTiers, SyncDistanceTier};
|
use super::{BeaconNodeHealth, BeaconNodeSyncDistanceTiers, IsOptimistic, SyncDistanceTier};
|
||||||
use crate::beacon_node_fallback::Config;
|
use crate::beacon_node_fallback::Config;
|
||||||
use slot_clock::{SlotClock, TestingSlotClock};
|
use slot_clock::{SlotClock, TestingSlotClock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -297,7 +303,7 @@ mod tests {
|
|||||||
let mut health_vec = vec![];
|
let mut health_vec = vec![];
|
||||||
|
|
||||||
for head_slot in (0..=64).rev() {
|
for head_slot in (0..=64).rev() {
|
||||||
for optimistic_status in &[false, true] {
|
for optimistic_status in &[IsOptimistic::No, IsOptimistic::Yes] {
|
||||||
for ee_health in &[Healthy, Unhealthy] {
|
for ee_health in &[Healthy, Unhealthy] {
|
||||||
let health = BeaconNodeHealth::from_status(
|
let health = BeaconNodeHealth::from_status(
|
||||||
0,
|
0,
|
||||||
@@ -332,9 +338,9 @@ mod tests {
|
|||||||
|
|
||||||
// Check optimistic status.
|
// Check optimistic status.
|
||||||
if [1, 2, 3, 4, 7, 10, 11, 14].contains(&tier) {
|
if [1, 2, 3, 4, 7, 10, 11, 14].contains(&tier) {
|
||||||
assert!(!health.optimistic_status);
|
assert_eq!(health.optimistic_status, IsOptimistic::No);
|
||||||
} else {
|
} else {
|
||||||
assert!(health.optimistic_status);
|
assert_eq!(health.optimistic_status, IsOptimistic::Yes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check execution health.
|
// Check execution health.
|
||||||
@@ -354,20 +360,48 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let distance_tiers = BeaconNodeSyncDistanceTiers::from_config(&config);
|
let distance_tiers = BeaconNodeSyncDistanceTiers::from_config(&config);
|
||||||
|
|
||||||
let synced_low =
|
let synced_low = BeaconNodeHealth::compute_health_tier(
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(0), false, Healthy, &distance_tiers);
|
Slot::new(0),
|
||||||
let synced_high =
|
IsOptimistic::No,
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(8), false, Healthy, &distance_tiers);
|
Healthy,
|
||||||
let small_low =
|
&distance_tiers,
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(9), false, Healthy, &distance_tiers);
|
);
|
||||||
let small_high =
|
let synced_high = BeaconNodeHealth::compute_health_tier(
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(15), false, Healthy, &distance_tiers);
|
Slot::new(8),
|
||||||
let medium_low =
|
IsOptimistic::No,
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(16), false, Healthy, &distance_tiers);
|
Healthy,
|
||||||
let medium_high =
|
&distance_tiers,
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(39), false, Healthy, &distance_tiers);
|
);
|
||||||
let large =
|
let small_low = BeaconNodeHealth::compute_health_tier(
|
||||||
BeaconNodeHealth::compute_health_tier(Slot::new(40), false, Healthy, &distance_tiers);
|
Slot::new(9),
|
||||||
|
IsOptimistic::No,
|
||||||
|
Healthy,
|
||||||
|
&distance_tiers,
|
||||||
|
);
|
||||||
|
let small_high = BeaconNodeHealth::compute_health_tier(
|
||||||
|
Slot::new(15),
|
||||||
|
IsOptimistic::No,
|
||||||
|
Healthy,
|
||||||
|
&distance_tiers,
|
||||||
|
);
|
||||||
|
let medium_low = BeaconNodeHealth::compute_health_tier(
|
||||||
|
Slot::new(16),
|
||||||
|
IsOptimistic::No,
|
||||||
|
Healthy,
|
||||||
|
&distance_tiers,
|
||||||
|
);
|
||||||
|
let medium_high = BeaconNodeHealth::compute_health_tier(
|
||||||
|
Slot::new(39),
|
||||||
|
IsOptimistic::No,
|
||||||
|
Healthy,
|
||||||
|
&distance_tiers,
|
||||||
|
);
|
||||||
|
let large = BeaconNodeHealth::compute_health_tier(
|
||||||
|
Slot::new(40),
|
||||||
|
IsOptimistic::No,
|
||||||
|
Healthy,
|
||||||
|
&distance_tiers,
|
||||||
|
);
|
||||||
|
|
||||||
assert!(synced_low.tier == 1);
|
assert!(synced_low.tier == 1);
|
||||||
assert!(synced_high.tier == 1);
|
assert!(synced_high.tier == 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user