From 90d562b3d46e71a92e05346958404f4d7625472a Mon Sep 17 00:00:00 2001 From: int88 Date: Wed, 26 Apr 2023 01:12:35 +0000 Subject: [PATCH] add attestation inclusion distance in http api (#4148) ## Issue Addressed #4097 ## Proposed Changes Add attestation inclusion distance in http api, extend `/lighthouse/ui/validator_metrics` to include it. ## Usage ``` curl -X POST "http://localhost:8001/lighthouse/ui/validator_metrics" -d '{"indices": [1]}' -H "Content-Type: application/json" | jq ``` ``` { "data": { "validators": { "1": { "attestation_hits": 3, "attestation_misses": 1, "attestation_hit_percentage": 75, "attestation_head_hits": 3, "attestation_head_misses": 0, "attestation_head_hit_percentage": 100, "attestation_target_hits": 3, "attestation_target_misses": 0, "attestation_target_hit_percentage": 100, "attestation_inclusion_distance": 1 } } } } ``` ## Additional Info NA --- beacon_node/beacon_chain/src/validator_monitor.rs | 8 +++++++- beacon_node/http_api/src/ui.rs | 4 ++++ book/src/api-lighthouse.md | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/beacon_node/beacon_chain/src/validator_monitor.rs b/beacon_node/beacon_chain/src/validator_monitor.rs index d79a56df6..396aac71b 100644 --- a/beacon_node/beacon_chain/src/validator_monitor.rs +++ b/beacon_node/beacon_chain/src/validator_monitor.rs @@ -199,6 +199,7 @@ pub struct ValidatorMetrics { pub attestation_head_misses: u64, pub attestation_target_hits: u64, pub attestation_target_misses: u64, + pub latest_attestation_inclusion_distance: u64, } impl ValidatorMetrics { @@ -225,6 +226,10 @@ impl ValidatorMetrics { pub fn increment_head_misses(&mut self) { self.attestation_head_misses += 1; } + + pub fn set_latest_inclusion_distance(&mut self, distance: u64) { + self.latest_attestation_inclusion_distance = distance; + } } /// A validator that is being monitored by the `ValidatorMonitor`. @@ -568,7 +573,6 @@ impl ValidatorMonitor { } else { validator_metrics.increment_misses() } - drop(validator_metrics); // Indicates if any attestation made it on-chain. // @@ -693,8 +697,10 @@ impl ValidatorMonitor { &[id], inclusion_delay as i64, ); + validator_metrics.set_latest_inclusion_distance(inclusion_delay); } } + drop(validator_metrics); // Indicates the number of sync committee signatures that made it into // a sync aggregate in the current_epoch (state.epoch - 1). diff --git a/beacon_node/http_api/src/ui.rs b/beacon_node/http_api/src/ui.rs index e8280a796..8911e785e 100644 --- a/beacon_node/http_api/src/ui.rs +++ b/beacon_node/http_api/src/ui.rs @@ -165,6 +165,7 @@ pub struct ValidatorMetrics { attestation_target_hits: u64, attestation_target_misses: u64, attestation_target_hit_percentage: f64, + latest_attestation_inclusion_distance: u64, } #[derive(PartialEq, Serialize, Deserialize)] @@ -210,6 +211,8 @@ pub fn post_validator_monitor_metrics( let attestation_head_misses = val_metrics.attestation_head_misses; let attestation_target_hits = val_metrics.attestation_target_hits; let attestation_target_misses = val_metrics.attestation_target_misses; + let latest_attestation_inclusion_distance = + val_metrics.latest_attestation_inclusion_distance; drop(val_metrics); let attestations = attestation_hits + attestation_misses; @@ -242,6 +245,7 @@ pub fn post_validator_monitor_metrics( attestation_target_hits, attestation_target_misses, attestation_target_hit_percentage, + latest_attestation_inclusion_distance, }; validators.insert(id.clone(), metrics); diff --git a/book/src/api-lighthouse.md b/book/src/api-lighthouse.md index 284818097..1fa7a1397 100644 --- a/book/src/api-lighthouse.md +++ b/book/src/api-lighthouse.md @@ -141,7 +141,8 @@ curl -X POST "http://localhost:5052/lighthouse/ui/validator_metrics" -d '{"indic "attestation_head_hit_percentage": 100, "attestation_target_hits": 5, "attestation_target_misses": 5, - "attestation_target_hit_percentage": 50 + "attestation_target_hit_percentage": 50, + "latest_attestation_inclusion_distance": 1 } } }