mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
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:
@@ -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(),
|
||||
|
||||
@@ -638,7 +638,6 @@ impl ApiTester {
|
||||
|
||||
let expected = state_opt.map(|state| {
|
||||
let epoch = state.current_epoch();
|
||||
let finalized_epoch = state.finalized_checkpoint.epoch;
|
||||
let far_future_epoch = self.chain.spec.far_future_epoch;
|
||||
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
@@ -649,12 +648,14 @@ impl ApiTester {
|
||||
}
|
||||
let validator = state.validators[i as usize].clone();
|
||||
let status = ValidatorStatus::from_validator(
|
||||
Some(&validator),
|
||||
&validator,
|
||||
epoch,
|
||||
finalized_epoch,
|
||||
far_future_epoch,
|
||||
);
|
||||
if statuses.contains(&status) || statuses.is_empty() {
|
||||
if statuses.contains(&status)
|
||||
|| statuses.is_empty()
|
||||
|| statuses.contains(&status.superstatus())
|
||||
{
|
||||
validators.push(ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances[i as usize],
|
||||
@@ -706,16 +707,14 @@ impl ApiTester {
|
||||
|
||||
let expected = {
|
||||
let epoch = state.current_epoch();
|
||||
let finalized_epoch = state.finalized_checkpoint.epoch;
|
||||
let far_future_epoch = self.chain.spec.far_future_epoch;
|
||||
|
||||
ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances[i],
|
||||
status: ValidatorStatus::from_validator(
|
||||
Some(&validator),
|
||||
&validator,
|
||||
epoch,
|
||||
finalized_epoch,
|
||||
far_future_epoch,
|
||||
),
|
||||
validator: validator.clone(),
|
||||
@@ -1444,18 +1443,19 @@ impl ApiTester {
|
||||
vec![],
|
||||
vec![ValidatorStatus::Active],
|
||||
vec![
|
||||
ValidatorStatus::Unknown,
|
||||
ValidatorStatus::WaitingForEligibility,
|
||||
ValidatorStatus::WaitingForFinality,
|
||||
ValidatorStatus::WaitingInQueue,
|
||||
ValidatorStatus::StandbyForActive,
|
||||
ValidatorStatus::Active,
|
||||
ValidatorStatus::ActiveAwaitingVoluntaryExit,
|
||||
ValidatorStatus::ActiveAwaitingSlashedExit,
|
||||
ValidatorStatus::ExitedVoluntarily,
|
||||
ValidatorStatus::PendingInitialized,
|
||||
ValidatorStatus::PendingQueued,
|
||||
ValidatorStatus::ActiveOngoing,
|
||||
ValidatorStatus::ActiveExiting,
|
||||
ValidatorStatus::ActiveSlashed,
|
||||
ValidatorStatus::ExitedUnslashed,
|
||||
ValidatorStatus::ExitedSlashed,
|
||||
ValidatorStatus::Withdrawable,
|
||||
ValidatorStatus::Withdrawn,
|
||||
ValidatorStatus::WithdrawalPossible,
|
||||
ValidatorStatus::WithdrawalDone,
|
||||
ValidatorStatus::Active,
|
||||
ValidatorStatus::Pending,
|
||||
ValidatorStatus::Exited,
|
||||
ValidatorStatus::Withdrawal,
|
||||
],
|
||||
];
|
||||
interesting
|
||||
|
||||
Reference in New Issue
Block a user