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
This commit is contained in:
int88 2023-04-26 01:12:35 +00:00
parent a78285db5e
commit 90d562b3d4
3 changed files with 13 additions and 2 deletions

View File

@ -199,6 +199,7 @@ pub struct ValidatorMetrics {
pub attestation_head_misses: u64, pub attestation_head_misses: u64,
pub attestation_target_hits: u64, pub attestation_target_hits: u64,
pub attestation_target_misses: u64, pub attestation_target_misses: u64,
pub latest_attestation_inclusion_distance: u64,
} }
impl ValidatorMetrics { impl ValidatorMetrics {
@ -225,6 +226,10 @@ impl ValidatorMetrics {
pub fn increment_head_misses(&mut self) { pub fn increment_head_misses(&mut self) {
self.attestation_head_misses += 1; 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`. /// A validator that is being monitored by the `ValidatorMonitor`.
@ -568,7 +573,6 @@ impl<T: EthSpec> ValidatorMonitor<T> {
} else { } else {
validator_metrics.increment_misses() validator_metrics.increment_misses()
} }
drop(validator_metrics);
// Indicates if any attestation made it on-chain. // Indicates if any attestation made it on-chain.
// //
@ -693,8 +697,10 @@ impl<T: EthSpec> ValidatorMonitor<T> {
&[id], &[id],
inclusion_delay as i64, 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 // Indicates the number of sync committee signatures that made it into
// a sync aggregate in the current_epoch (state.epoch - 1). // a sync aggregate in the current_epoch (state.epoch - 1).

View File

@ -165,6 +165,7 @@ pub struct ValidatorMetrics {
attestation_target_hits: u64, attestation_target_hits: u64,
attestation_target_misses: u64, attestation_target_misses: u64,
attestation_target_hit_percentage: f64, attestation_target_hit_percentage: f64,
latest_attestation_inclusion_distance: u64,
} }
#[derive(PartialEq, Serialize, Deserialize)] #[derive(PartialEq, Serialize, Deserialize)]
@ -210,6 +211,8 @@ pub fn post_validator_monitor_metrics<T: BeaconChainTypes>(
let attestation_head_misses = val_metrics.attestation_head_misses; let attestation_head_misses = val_metrics.attestation_head_misses;
let attestation_target_hits = val_metrics.attestation_target_hits; let attestation_target_hits = val_metrics.attestation_target_hits;
let attestation_target_misses = val_metrics.attestation_target_misses; let attestation_target_misses = val_metrics.attestation_target_misses;
let latest_attestation_inclusion_distance =
val_metrics.latest_attestation_inclusion_distance;
drop(val_metrics); drop(val_metrics);
let attestations = attestation_hits + attestation_misses; let attestations = attestation_hits + attestation_misses;
@ -242,6 +245,7 @@ pub fn post_validator_monitor_metrics<T: BeaconChainTypes>(
attestation_target_hits, attestation_target_hits,
attestation_target_misses, attestation_target_misses,
attestation_target_hit_percentage, attestation_target_hit_percentage,
latest_attestation_inclusion_distance,
}; };
validators.insert(id.clone(), metrics); validators.insert(id.clone(), metrics);

View File

@ -141,7 +141,8 @@ curl -X POST "http://localhost:5052/lighthouse/ui/validator_metrics" -d '{"indic
"attestation_head_hit_percentage": 100, "attestation_head_hit_percentage": 100,
"attestation_target_hits": 5, "attestation_target_hits": 5,
"attestation_target_misses": 5, "attestation_target_misses": 5,
"attestation_target_hit_percentage": 50 "attestation_target_hit_percentage": 50,
"latest_attestation_inclusion_distance": 1
} }
} }
} }