Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow filtering of validators by top-level validator status #7143

Merged

Conversation

vladmarusyk
Copy link
Contributor

Add support for filtering validators by top-level status

This pull request implements support for filtering validators by top-level statuses such as active, pending, exited, and withdrawal as specified in the beacon-api spec.

Changes:

  • Added mapToGeneralStatus function to map detailed statuses to top-level statuses (active, pending, exited, and withdrawal).
  • Updated filterStateValidatorsByStatus to support filtering validators by both detailed and top-level statuses.

Related issue:

Closes #7141

@vladmarusyk vladmarusyk requested a review from a team as a code owner October 9, 2024 15:58
@CLAassistant
Copy link

CLAassistant commented Oct 9, 2024

CLA assistant check
All committers have signed the CLA.

@vladmarusyk vladmarusyk changed the title Closes #7141 | Allow filtering of validators by top-level validator status feat: allow filtering of validators by top-level validator status Oct 9, 2024
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up, some initial feedback

@@ -83,6 +83,51 @@ export async function getStateResponseWithRegen(
return res;
}

function mapToGeneralStatus(subStatus: string): string {
Copy link
Member

Choose a reason for hiding this comment

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

switch-case would be nicer here, we can also reuse ValidatorStatus type, and potentially a extended type which includes top-level / general statuses as well

* Get the status of the validator
* based on conditions outlined in https://hackmd.io/ofFJ5gOmQpu1jjHilHbdQQ
*/
export function getValidatorStatus(validator: phase0.Validator, currentEpoch: Epoch): routes.beacon.ValidatorStatus {
Copy link
Member

Choose a reason for hiding this comment

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

why is this added here?

@nflaig
Copy link
Member

nflaig commented Oct 9, 2024

also note that ValidatorStatus type was just moved to types packages (see #7140), make sure your branch is up-to-date

@vladmarusyk
Copy link
Contributor Author

I've updated the code based on the feedback:

  • Replaced if-else with switch-case.
  • Used the ValidatorStatus type and created an extended type for general statuses.

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

Looks good, can you please remove unrelated code updates, see #7143 (comment)

packages/beacon-node/src/api/impl/beacon/state/utils.ts Outdated Show resolved Hide resolved
@nflaig
Copy link
Member

nflaig commented Oct 10, 2024

e07a82b just removed the actual code, the unrelated code changes are still here

@vladmarusyk
Copy link
Contributor Author

vladmarusyk commented Oct 10, 2024

Sorry for the inconvenience, solving the first issue. Thank you for the opportunity.

@vladmarusyk
Copy link
Contributor Author

Removed unrelated code

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the cleanup

packages/beacon-node/src/api/impl/beacon/state/utils.ts Outdated Show resolved Hide resolved
Co-authored-by: Nico Flaig <nflaig@protonmail.com>
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.19%. Comparing base (068fbae) to head (59febed).
Report is 5 commits behind head on unstable.

Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #7143   +/-   ##
=========================================
  Coverage     49.19%   49.19%           
=========================================
  Files           597      597           
  Lines         39725    39725           
  Branches       2073     2083   +10     
=========================================
+ Hits          19542    19544    +2     
+ Misses        20142    20140    -2     
  Partials         41       41           

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

LGTM

unrelated, commenting for posterity
ValidatorStatus shouldn't contain "active"

@wemeetagain wemeetagain merged commit 38f54ab into ChainSafe:unstable Oct 10, 2024
20 checks passed
@nflaig
Copy link
Member

nflaig commented Oct 10, 2024

unrelated, commenting for posterity ValidatorStatus shouldn't contain "active"

yeah, let's get rid of this #7146

philknows pushed a commit that referenced this pull request Oct 18, 2024
)

* Fix ValidatorStatus type issue

* refactor: use switch-case and typed general validator status mapping

* Update packages/beacon-node/src/api/impl/beacon/state/utils.ts

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* refactor: deleted unrelated code

* refactor: deleted unrelated code

* Update packages/beacon-node/src/api/impl/beacon/state/utils.ts

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.23.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow filtering of validators by top-level validator status
4 participants