Fix attestation performance API InvalidValidatorIndex error (#3503)

## Issue Addressed

When requesting an index which is not active during `start_epoch`, Lighthouse returns: 
```
curl "http://localhost:5052/lighthouse/analysis/attestation_performance/999999999?start_epoch=100000&end_epoch=100000"
```
```json
{
  "code": 500,
  "message": "INTERNAL_SERVER_ERROR: ParticipationCache(InvalidValidatorIndex(999999999))",
  "stacktraces": []
}
```

This error occurs even when the index in question becomes active before `end_epoch` which is undesirable as it can prevent larger queries from completing.

## Proposed Changes

In the event the index is out-of-bounds (has not yet been activated), simply return all fields as `false`:

```
-> curl "http://localhost:5052/lighthouse/analysis/attestation_performance/999999999?start_epoch=100000&end_epoch=100000"
```
```json
[
  {
    "index": 999999999,
    "epochs": {
      "100000": {
        "active": false,
        "head": false,
        "target": false,
        "source": false
      }
    }
  }
]
```

By doing this, we cover the case where a validator becomes active sometime between `start_epoch` and `end_epoch`.

## Additional Info

Note that this error only occurs for epochs after the Altair hard fork.
This commit is contained in:
Mac L 2022-09-05 04:50:45 +00:00
parent 473abc14ca
commit 80359d8ddb
2 changed files with 28 additions and 4 deletions

View File

@ -83,6 +83,10 @@ pub fn get_attestation_performance<T: BeaconChainTypes>(
} }
// Either use the global validator set, or the specified index. // Either use the global validator set, or the specified index.
//
// Does no further validation of the indices, so in the event an index has not yet been
// activated or does not yet exist (according to the head state), it will return all fields as
// `false`.
let index_range = if target.to_lowercase() == "global" { let index_range = if target.to_lowercase() == "global" {
chain chain
.with_head(|head| Ok((0..head.beacon_state.validators().len() as u64).collect())) .with_head(|head| Ok((0..head.beacon_state.validators().len() as u64).collect()))

View File

@ -129,7 +129,12 @@ impl<T: EthSpec> EpochProcessingSummary<T> {
EpochProcessingSummary::Altair { EpochProcessingSummary::Altair {
participation_cache, participation_cache,
.. ..
} => participation_cache.is_current_epoch_timely_target_attester(val_index), } => participation_cache
.is_current_epoch_timely_target_attester(val_index)
.or_else(|e| match e {
ParticipationCacheError::InvalidValidatorIndex(_) => Ok(false),
e => Err(e),
}),
} }
} }
@ -222,7 +227,12 @@ impl<T: EthSpec> EpochProcessingSummary<T> {
EpochProcessingSummary::Altair { EpochProcessingSummary::Altair {
participation_cache, participation_cache,
.. ..
} => participation_cache.is_previous_epoch_timely_target_attester(val_index), } => participation_cache
.is_previous_epoch_timely_target_attester(val_index)
.or_else(|e| match e {
ParticipationCacheError::InvalidValidatorIndex(_) => Ok(false),
e => Err(e),
}),
} }
} }
@ -248,7 +258,12 @@ impl<T: EthSpec> EpochProcessingSummary<T> {
EpochProcessingSummary::Altair { EpochProcessingSummary::Altair {
participation_cache, participation_cache,
.. ..
} => participation_cache.is_previous_epoch_timely_head_attester(val_index), } => participation_cache
.is_previous_epoch_timely_head_attester(val_index)
.or_else(|e| match e {
ParticipationCacheError::InvalidValidatorIndex(_) => Ok(false),
e => Err(e),
}),
} }
} }
@ -274,7 +289,12 @@ impl<T: EthSpec> EpochProcessingSummary<T> {
EpochProcessingSummary::Altair { EpochProcessingSummary::Altair {
participation_cache, participation_cache,
.. ..
} => participation_cache.is_previous_epoch_timely_source_attester(val_index), } => participation_cache
.is_previous_epoch_timely_source_attester(val_index)
.or_else(|e| match e {
ParticipationCacheError::InvalidValidatorIndex(_) => Ok(false),
e => Err(e),
}),
} }
} }