mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +00:00
Validator monitor support for sync committees (#2476)
## Issue Addressed N/A ## Proposed Changes Add functionality in the validator monitor to provide sync committee related metrics for monitored validators. Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -22,7 +22,7 @@ pub mod sync_committee_updates;
|
||||
pub fn process_epoch<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<EpochProcessingSummary, Error> {
|
||||
) -> Result<EpochProcessingSummary<T>, Error> {
|
||||
// Ensure the committee caches are built.
|
||||
state.build_committee_cache(RelativeEpoch::Previous, spec)?;
|
||||
state.build_committee_cache(RelativeEpoch::Current, spec)?;
|
||||
@@ -30,6 +30,7 @@ pub fn process_epoch<T: EthSpec>(
|
||||
|
||||
// Pre-compute participating indices and total balances.
|
||||
let participation_cache = ParticipationCache::new(state, spec)?;
|
||||
let sync_committee = state.current_sync_committee()?.clone();
|
||||
|
||||
// Justification and finalization.
|
||||
process_justification_and_finalization(state, &participation_cache)?;
|
||||
@@ -75,5 +76,6 @@ pub fn process_epoch<T: EthSpec>(
|
||||
|
||||
Ok(EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
sync_committee,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub mod validator_statuses;
|
||||
pub fn process_epoch<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<EpochProcessingSummary, Error> {
|
||||
) -> Result<EpochProcessingSummary<T>, Error> {
|
||||
// Ensure the committee caches are built.
|
||||
state.build_committee_cache(RelativeEpoch::Previous, spec)?;
|
||||
state.build_committee_cache(RelativeEpoch::Current, spec)?;
|
||||
|
||||
@@ -3,20 +3,23 @@ use super::{
|
||||
base::{validator_statuses::InclusionInfo, TotalBalances, ValidatorStatus},
|
||||
};
|
||||
use crate::metrics;
|
||||
use std::sync::Arc;
|
||||
use types::{EthSpec, SyncCommittee};
|
||||
|
||||
/// Provides a summary of validator participation during the epoch.
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum EpochProcessingSummary {
|
||||
pub enum EpochProcessingSummary<T: EthSpec> {
|
||||
Base {
|
||||
total_balances: TotalBalances,
|
||||
statuses: Vec<ValidatorStatus>,
|
||||
},
|
||||
Altair {
|
||||
participation_cache: ParticipationCache,
|
||||
sync_committee: Arc<SyncCommittee<T>>,
|
||||
},
|
||||
}
|
||||
|
||||
impl EpochProcessingSummary {
|
||||
impl<T: EthSpec> EpochProcessingSummary<T> {
|
||||
/// Updates some Prometheus metrics with some values in `self`.
|
||||
#[cfg(feature = "metrics")]
|
||||
pub fn observe_metrics(&self) -> Result<(), ParticipationCacheError> {
|
||||
@@ -40,12 +43,21 @@ impl EpochProcessingSummary {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the sync committee indices for the current epoch for altair.
|
||||
pub fn sync_committee(&self) -> Option<&SyncCommittee<T>> {
|
||||
match self {
|
||||
EpochProcessingSummary::Altair { sync_committee, .. } => Some(sync_committee),
|
||||
EpochProcessingSummary::Base { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the sum of the effective balance of all validators in the current epoch.
|
||||
pub fn current_epoch_total_active_balance(&self) -> u64 {
|
||||
match self {
|
||||
EpochProcessingSummary::Base { total_balances, .. } => total_balances.current_epoch(),
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.current_epoch_total_active_balance(),
|
||||
}
|
||||
}
|
||||
@@ -59,6 +71,7 @@ impl EpochProcessingSummary {
|
||||
}
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.current_epoch_target_attesting_balance(),
|
||||
}
|
||||
}
|
||||
@@ -69,6 +82,7 @@ impl EpochProcessingSummary {
|
||||
EpochProcessingSummary::Base { total_balances, .. } => total_balances.previous_epoch(),
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.previous_epoch_total_active_balance(),
|
||||
}
|
||||
}
|
||||
@@ -126,6 +140,7 @@ impl EpochProcessingSummary {
|
||||
}
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.previous_epoch_target_attesting_balance(),
|
||||
}
|
||||
}
|
||||
@@ -144,6 +159,7 @@ impl EpochProcessingSummary {
|
||||
}
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.previous_epoch_head_attesting_balance(),
|
||||
}
|
||||
}
|
||||
@@ -162,6 +178,7 @@ impl EpochProcessingSummary {
|
||||
}
|
||||
EpochProcessingSummary::Altair {
|
||||
participation_cache,
|
||||
..
|
||||
} => participation_cache.previous_epoch_source_attesting_balance(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user