Register blocks in validator monitor (#3635)

## Issue Addressed

Closes #3460

## Proposed Changes

`blocks` and `block_min_delay` are never updated in the epoch summary



Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
tim gretler 2022-11-09 05:37:09 +00:00
parent 9d6209725f
commit 266d765285

View File

@ -109,6 +109,11 @@ impl EpochSummary {
} }
} }
pub fn register_block(&mut self, delay: Duration) {
self.blocks += 1;
Self::update_if_lt(&mut self.block_min_delay, delay);
}
pub fn register_unaggregated_attestation(&mut self, delay: Duration) { pub fn register_unaggregated_attestation(&mut self, delay: Duration) {
self.attestations += 1; self.attestations += 1;
Self::update_if_lt(&mut self.attestation_min_delay, delay); Self::update_if_lt(&mut self.attestation_min_delay, delay);
@ -613,13 +618,6 @@ impl<T: EthSpec> ValidatorMonitor<T> {
Ok(()) Ok(())
} }
fn get_validator_id(&self, validator_index: u64) -> Option<&str> {
self.indices
.get(&validator_index)
.and_then(|pubkey| self.validators.get(pubkey))
.map(|validator| validator.id.as_str())
}
fn get_validator(&self, validator_index: u64) -> Option<&MonitoredValidator> { fn get_validator(&self, validator_index: u64) -> Option<&MonitoredValidator> {
self.indices self.indices
.get(&validator_index) .get(&validator_index)
@ -685,7 +683,9 @@ impl<T: EthSpec> ValidatorMonitor<T> {
block_root: Hash256, block_root: Hash256,
slot_clock: &S, slot_clock: &S,
) { ) {
if let Some(id) = self.get_validator_id(block.proposer_index()) { let epoch = block.slot().epoch(T::slots_per_epoch());
if let Some(validator) = self.get_validator(block.proposer_index()) {
let id = &validator.id;
let delay = get_block_delay_ms(seen_timestamp, block, slot_clock); let delay = get_block_delay_ms(seen_timestamp, block, slot_clock);
metrics::inc_counter_vec(&metrics::VALIDATOR_MONITOR_BEACON_BLOCK_TOTAL, &[src, id]); metrics::inc_counter_vec(&metrics::VALIDATOR_MONITOR_BEACON_BLOCK_TOTAL, &[src, id]);
@ -704,6 +704,8 @@ impl<T: EthSpec> ValidatorMonitor<T> {
"src" => src, "src" => src,
"validator" => %id, "validator" => %id,
); );
validator.with_epoch_summary(epoch, |summary| summary.register_block(delay));
} }
} }