Update ValidatorStatus to match the v1 API (#2149)

## Issue Addressed

N/A

## Proposed Changes

We are currently a bit off of the standard API spec because we have [this](https://hackmd.io/bQxMDRt1RbS1TLno8K4NPg?view) proposal implemented for validator status.  Based on discussion [here](https://github.com/ethereum/eth2.0-APIs/pull/94), it looks like this won't be added to the spec until v2, so this PR implements [this](https://hackmd.io/ofFJ5gOmQpu1jjHilHbdQQ) validator status logic instead

## Additional Info

N/A


Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
realbigsean
2021-02-24 04:15:13 +00:00
parent a764c3b247
commit 5bc93869c8
3 changed files with 113 additions and 97 deletions

View File

@@ -498,7 +498,6 @@ pub fn serve<T: BeaconChainTypes>(
state_id
.map_state(&chain, |state| {
let epoch = state.current_epoch();
let finalized_epoch = state.finalized_checkpoint.epoch;
let far_future_epoch = chain.spec.far_future_epoch;
Ok(state
@@ -522,17 +521,18 @@ pub fn serve<T: BeaconChainTypes>(
// filter by status(es) if provided and map the result
.filter_map(|(index, (validator, balance))| {
let status = api_types::ValidatorStatus::from_validator(
Some(validator),
validator,
epoch,
finalized_epoch,
far_future_epoch,
);
if query
.status
.as_ref()
.map_or(true, |statuses| statuses.0.contains(&status))
{
let status_matches =
query.status.as_ref().map_or(true, |statuses| {
statuses.0.contains(&status)
|| statuses.0.contains(&status.superstatus())
});
if status_matches {
Some(api_types::ValidatorData {
index: index as u64,
balance: *balance,
@@ -577,16 +577,14 @@ pub fn serve<T: BeaconChainTypes>(
let validator = state.validators.get(index)?;
let balance = *state.balances.get(index)?;
let epoch = state.current_epoch();
let finalized_epoch = state.finalized_checkpoint.epoch;
let far_future_epoch = chain.spec.far_future_epoch;
Some(api_types::ValidatorData {
index: index as u64,
balance,
status: api_types::ValidatorStatus::from_validator(
Some(validator),
validator,
epoch,
finalized_epoch,
far_future_epoch,
),
validator: validator.clone(),