Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cdaafce
Add first draft
paulhauner Dec 30, 2020
2e79051
Add per-epoch events, pruning
paulhauner Jan 5, 2021
ece3986
Add API endpoint, attestations in blocks
paulhauner Jan 5, 2021
3e2f2bc
Slight refactor, major improvement
paulhauner Jan 6, 2021
e18a5c0
Add seen timestamps
paulhauner Jan 6, 2021
7f98059
Add exit, slashings
paulhauner Jan 6, 2021
c8578ac
Add ids
paulhauner Jan 7, 2021
4a22dd9
Add metrics
paulhauner Jan 7, 2021
8428ab7
Remove mutability
paulhauner Jan 7, 2021
94fbef2
Remove events
paulhauner Jan 7, 2021
4e0ead5
Remove unused code, change flags
paulhauner Jan 7, 2021
090c1f3
Tidy flags, add total monitored val count
paulhauner Jan 7, 2021
c2cb527
Add previous epoch tracking
paulhauner Jan 8, 2021
0f90879
Add individual validator metrics
paulhauner Jan 17, 2021
c0fb0dd
Add comments
paulhauner Jan 17, 2021
f9585c1
Add docs
paulhauner Jan 18, 2021
79c5171
Use custom logger
paulhauner Jan 18, 2021
aa28dd7
Log validators at startup
paulhauner Jan 18, 2021
ceac25d
Change flags, update docs
paulhauner Jan 18, 2021
78347cd
Merge branch 'unstable' into validator-monitor
paulhauner Jan 18, 2021
f9237d0
Address test failures
paulhauner Jan 18, 2021
337aa68
Fix test builder
paulhauner Jan 18, 2021
0978d9e
Fix more harness issues
paulhauner Jan 18, 2021
854c562
Merge branch 'unstable' into validator-monitor
paulhauner Jan 19, 2021
9f7a730
Update beacon_node/beacon_chain/src/metrics.rs
paulhauner Jan 20, 2021
06c3624
Apply suggestions from code review
paulhauner Jan 20, 2021
f008f04
Update beacon_node/beacon_chain/src/metrics.rs
paulhauner Jan 20, 2021
3020b5b
Address some review comments
paulhauner Jan 20, 2021
cd4c390
Fix clippy lints
paulhauner Jan 20, 2021
0d04bc1
Add deadlock warning
paulhauner Jan 20, 2021
001a53b
More generic Copy impl for Pubkey bytes
paulhauner Jan 20, 2021
82cd921
Register slashings in blocks
paulhauner Jan 20, 2021
0ac39b6
Register exits in blocks
paulhauner Jan 20, 2021
bfcb6fe
Register state and validators at startup
paulhauner Jan 20, 2021
16d1f08
Add extra metrics
paulhauner Jan 20, 2021
2742ad1
Merge branch 'unstable' into validator-monitor
paulhauner Jan 20, 2021
a631c6a
Update docs for dashboard
paulhauner Jan 20, 2021
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
5 changes: 5 additions & 0 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,11 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
&self.attestation
}

/// Returns the wrapped `indexed_attestation`.
pub fn indexed_attestation(&self) -> &IndexedAttestation<T::EthSpec> {
&self.indexed_attestation
}

/// Returns a mutable reference to the underlying attestation.
///
/// Only use during testing since modifying the `IndexedAttestation` can cause the attestation
Expand Down
38 changes: 38 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use crate::persisted_fork_choice::PersistedForkChoice;
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
use crate::snapshot_cache::SnapshotCache;
use crate::timeout_rw_lock::TimeoutRwLock;
use crate::validator_monitor::{
ValidatorMonitor, HISTORIC_EPOCHS as VALIDATOR_MONITOR_HISTORIC_EPOCHS,
};
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::BeaconForkChoiceStore;
use crate::BeaconSnapshot;
Expand Down Expand Up @@ -242,6 +245,8 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub(crate) graffiti: Graffiti,
/// Optional slasher.
pub slasher: Option<Arc<Slasher<T::EthSpec>>>,
/// Provides monitoring of a set of explicitly defined validators.
pub validator_monitor: RwLock<ValidatorMonitor<T::EthSpec>>,
}

type BeaconBlockAndState<T> = (BeaconBlock<T>, BeaconState<T>);
Expand Down Expand Up @@ -1624,6 +1629,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}

// Allow the validator monitor to learn about a new valid state.
self.validator_monitor
.write()
.process_valid_state(current_slot.epoch(T::EthSpec::slots_per_epoch()), &state);
let validator_monitor = self.validator_monitor.read();

// Register each attestation in the block with the fork choice service.
for attestation in &block.body.attestations[..] {
let _fork_choice_attestation_timer =
Expand All @@ -1641,8 +1652,35 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Err(ForkChoiceError::InvalidAttestation(_)) => Ok(()),
Err(e) => Err(BlockError::BeaconChainError(e.into())),
}?;

// Only register this with the validator monitor when the block is sufficiently close to
// the current slot.
if VALIDATOR_MONITOR_HISTORIC_EPOCHS as u64 * T::EthSpec::slots_per_epoch()
+ block.slot.as_u64()
>= current_slot.as_u64()
{
validator_monitor.register_attestation_in_block(
&indexed_attestation,
&block,
&self.spec,
);
}
}

for exit in &block.body.voluntary_exits {
validator_monitor.register_block_voluntary_exit(&exit.message)
}

for slashing in &block.body.attester_slashings {
validator_monitor.register_block_attester_slashing(slashing)
}

for slashing in &block.body.proposer_slashings {
validator_monitor.register_block_proposer_slashing(slashing)
}

drop(validator_monitor);

metrics::observe(
&metrics::OPERATIONS_PER_BLOCK_ATTESTATION,
block.body.attestations.len() as f64,
Expand Down
40 changes: 36 additions & 4 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::persisted_beacon_chain::PersistedBeaconChain;
use crate::shuffling_cache::ShufflingCache;
use crate::snapshot_cache::{SnapshotCache, DEFAULT_SNAPSHOT_CACHE_SIZE};
use crate::timeout_rw_lock::TimeoutRwLock;
use crate::validator_monitor::ValidatorMonitor;
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::ChainConfig;
use crate::{
Expand All @@ -26,8 +27,8 @@ use std::sync::Arc;
use std::time::Duration;
use store::{HotColdDB, ItemStore};
use types::{
BeaconBlock, BeaconState, ChainSpec, EthSpec, Graffiti, Hash256, Signature, SignedBeaconBlock,
Slot,
BeaconBlock, BeaconState, ChainSpec, EthSpec, Graffiti, Hash256, PublicKeyBytes, Signature,
SignedBeaconBlock, Slot,
};

pub const PUBKEY_CACHE_FILENAME: &str = "pubkey_cache.ssz";
Expand Down Expand Up @@ -88,6 +89,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
log: Option<Logger>,
graffiti: Graffiti,
slasher: Option<Arc<Slasher<T::EthSpec>>>,
validator_monitor: Option<ValidatorMonitor<T::EthSpec>>,
}

impl<TSlotClock, TEth1Backend, TEthSpec, THotStore, TColdStore>
Expand Down Expand Up @@ -126,6 +128,7 @@ where
log: None,
graffiti: Graffiti::default(),
slasher: None,
validator_monitor: None,
}
}

Expand Down Expand Up @@ -170,8 +173,8 @@ where
/// Sets the logger.
///
/// Should generally be called early in the build chain.
pub fn logger(mut self, logger: Logger) -> Self {
self.log = Some(logger);
pub fn logger(mut self, log: Logger) -> Self {
self.log = Some(log);
self
}

Expand Down Expand Up @@ -391,6 +394,23 @@ where
self
}

/// Register some validators for additional monitoring.
///
/// `validators` is a comma-separated string of 0x-formatted BLS pubkeys.
pub fn monitor_validators(
mut self,
auto_register: bool,
validators: Vec<PublicKeyBytes>,
log: Logger,
) -> Self {
self.validator_monitor = Some(ValidatorMonitor::new(
validators,
auto_register,
log.clone(),
));
self
}

/// Consumes `self`, returning a `BeaconChain` if all required parameters have been supplied.
///
/// An error will be returned at runtime if all required parameters have not been configured.
Expand Down Expand Up @@ -418,6 +438,9 @@ where
let genesis_state_root = self
.genesis_state_root
.ok_or("Cannot build without a genesis state root")?;
let mut validator_monitor = self
.validator_monitor
.ok_or("Cannot build without a validator monitor")?;

let current_slot = if slot_clock
.is_prior_to_genesis()
Expand Down Expand Up @@ -496,6 +519,13 @@ where
log.clone(),
);

if let Some(slot) = slot_clock.now() {
validator_monitor.process_valid_state(
slot.epoch(TEthSpec::slots_per_epoch()),
&canonical_head.beacon_state,
);
}

let beacon_chain = BeaconChain {
spec: self.spec,
config: self.chain_config,
Expand Down Expand Up @@ -538,6 +568,7 @@ where
log: log.clone(),
graffiti: self.graffiti,
slasher: self.slasher.clone(),
validator_monitor: RwLock::new(validator_monitor),
};

let head = beacon_chain
Expand Down Expand Up @@ -706,6 +737,7 @@ mod test {
.testing_slot_clock(Duration::from_secs(1))
.expect("should configure testing slot clock")
.shutdown_sender(shutdown_tx)
.monitor_validators(true, vec![], log.clone())
.build()
.expect("should build");

Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod shuffling_cache;
mod snapshot_cache;
pub mod test_utils;
mod timeout_rw_lock;
pub mod validator_monitor;
mod validator_pubkey_cache;

pub use self::beacon_chain::{
Expand Down
Loading