Skip to content

Conversation

@realbigsean
Copy link
Member

@realbigsean realbigsean commented Oct 21, 2020

Issue Addressed

Michael's comment here: #1434 (comment)
Resolves #1808

Proposed Changes

  • Add query param id and status to the validators endpoint
  • Add string serialization and deserialization for ValidatorStatus
  • Drop Epoch from ValidatorStatus variants

Additional Info

Please provide any additional information. For example, future considerations
or information useful for reviewers.

@realbigsean realbigsean added the ready-for-review The code is ready for review label Oct 21, 2020
@realbigsean realbigsean requested review from michaelsproul and paulhauner and removed request for michaelsproul October 21, 2020 17:15
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far, but I think we also need:

.and_then(
|state_id: StateId, chain: Arc<BeaconChain<T>>, query: api_types::ValidatorsQuery| {
blocking_json_task(move || {
let id_predicate = |index: &u64, validator: &Validator| match query.id.as_ref()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the use of map_or you might be able to avoid these predicates.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I got what you were thinking

far_future_epoch,
);

if id_predicate(&(index as u64), validator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would place these predicates (perhaps as map_ors) above the filter_map on L444; this will stop us from allocating a ValidatorStatus for validators we're not going to return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the filters ahead of the map, but because the second filter tests against ValidatorStatus, am I now allocating a ValidatorStatus twice whenever we return a validator that passes a status filter ?

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Oct 22, 2020
@realbigsean
Copy link
Member Author

Addressed all the comments so far (had one question), here is the diff.

@realbigsean realbigsean added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Oct 23, 2020
.filter(|(_, (validator, _))| {
query.status.as_ref().map_or(true, |statuses| {
statuses.0.contains(
&api_types::ValidatorStatus::from_validator(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the double-instantiation by combining the filter on L439 and map on L451 with a filter_map. E.g.,:

    .filter_map(|(index, (validator, balance))| {
        let status = api_types::ValidatorStatus::from_validator(
            Some(validator),
            epoch,
            finalized_epoch,
            far_future_epoch,
        );

        if query
            .status
            .as_ref()
            .map_or(true, |statuses| statuses.0.contains(&status))
        {
            Some(api_types::ValidatorData {
                index: index as u64,
                balance: *balance,
                status: api_types::ValidatorStatus::from_validator(
                    Some(validator),
                    epoch,
                    finalized_epoch,
                    far_future_epoch,
                ),
                validator: validator.clone(),
            })
        } else {
            None
        }
    })

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Oct 26, 2020
@realbigsean realbigsean added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Oct 26, 2020
&self,
state_id: StateId,
ids: Option<&[ValidatorId]>,
statuses: Option<&[ValidatorStatus]>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that giving Some(&[]) would yield no results. This seemed odd at first, but after giving it some thought I think it's my preference.

No change requested :)

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

bors r+

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Oct 29, 2020
bors bot pushed a commit that referenced this pull request Oct 29, 2020
## Issue Addressed

Michael's comment here: #1434 (comment)
Resolves #1808

## Proposed Changes

- Add query param `id` and `status` to the `validators` endpoint
- Add string serialization and deserialization for `ValidatorStatus`
- Drop `Epoch` from `ValidatorStatus` variants

## Additional Info

Please provide any additional information. For example, future considerations
or information useful for reviewers.
@bors
Copy link

bors bot commented Oct 29, 2020

@bors bors bot changed the title Beacon state validator id filter [Merged by Bors] - Beacon state validator id filter Oct 29, 2020
@bors bors bot closed this Oct 29, 2020
@realbigsean realbigsean deleted the beacon-state-validator-id-filter branch November 21, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge This PR is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Endpoint /eth/v1/beacon/states/head/validators returns incorrect information.

2 participants