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

fix(node-api): Implement validators endpoint filtering properly #2467

Open
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

shotes
Copy link
Contributor

@shotes shotes commented Feb 3, 2025

Tested these two endpoints -
https://ethereum.github.io/beacon-APIs/#/Beacon/getStateValidators
https://ethereum.github.io/beacon-APIs/#/Beacon/postStateValidators

  • Refactored code for reusability as part of this change-set.
  • Increased go-eth2 client version.

Testing other validator endpoints, will open separate PR as don't want to increase diff.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 26.01881% with 236 lines in your changes missing coverage. Please review.

Project coverage is 32.77%. Comparing base (d90756b) to head (66c2f31).

Files with missing lines Patch % Lines
testing/e2e/suite/types/beacon_client.go 0.00% 71 Missing ⚠️
node-api/backend/validator.go 63.10% 32 Missing and 6 partials ⚠️
consensus-types/types/validator.go 0.00% 33 Missing ⚠️
testing/e2e/suite/types/consensus_client.go 0.00% 23 Missing ⚠️
node-api/handlers/beacon/types/conversions.go 46.15% 14 Missing and 7 partials ⚠️
node-api/handlers/beacon/validators.go 0.00% 15 Missing ⚠️
node-api/handlers/beacon/header.go 0.00% 14 Missing ⚠️
node-api/engines/echo/validator.go 0.00% 9 Missing ⚠️
node-api/handlers/beacon/types/response.go 0.00% 8 Missing ⚠️
node-api/handlers/beacon/historical.go 0.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2467      +/-   ##
==========================================
+ Coverage   32.30%   32.77%   +0.46%     
==========================================
  Files         350      351       +1     
  Lines       15674    15861     +187     
  Branches       20       20              
==========================================
+ Hits         5064     5198     +134     
- Misses      10247    10279      +32     
- Partials      363      384      +21     
Files with missing lines Coverage Δ
node-api/handlers/beacon/block.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/randao.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/historical.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/types/response.go 0.00% <0.00%> (ø)
node-api/engines/echo/validator.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/header.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/validators.go 0.00% <0.00%> (ø)
node-api/handlers/beacon/types/conversions.go 38.15% <46.15%> (+38.15%) ⬆️
testing/e2e/suite/types/consensus_client.go 0.00% <0.00%> (ø)
consensus-types/types/validator.go 67.08% <0.00%> (-17.72%) ⬇️
... and 2 more

... and 3 files with indirect coverage changes

@shotes shotes marked this pull request as ready for review February 3, 2025 21:26
@shotes shotes requested a review from a team as a code owner February 3, 2025 21:26
Copy link
Contributor

@calbera calbera left a comment

Choose a reason for hiding this comment

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

Changes look mostly good. Can we write 2 E2E tests querying validators endpoint. 1 with empty IDs & another with empty Statuses filters and show both calls return all validators?

Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
}

if !matchesStatusFilter(status, statuses) {
//nolint:nilnil // no data to return
Copy link
Contributor

Choose a reason for hiding this comment

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

Would agree that rather than returning nil, nil, we should return a defined error like ErrNoValidatorData and then explicitly catch this error case in the calling function.

Will remove the nolinting of nil,nil as well

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, returned an error and then handled it in filterAndBuildValidatorData so that when no status matches, error is not returned (as per spec).

Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
nit for readability

Signed-off-by: Cal Bera <calbera@berachain.com>
Copy link
Contributor

@calbera calbera left a comment

Choose a reason for hiding this comment

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

couple nits then LGTM

Copy link
Contributor Author

@shotes shotes left a comment

Choose a reason for hiding this comment

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

nits and questions. Really liking how this is turning out and all of the additional test cases. Also like the change of the NewResponse(data any) GenericResponse return value in the node-api. Fits well.

s.Ctx(),
&beaconapi.ValidatorsOpts{
State: utils.StateIDHead,
ValidatorStates: []apiv1.ValidatorState{}, // empty statuses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any difference between querying with empty-but-initialized ValidatorStates vs not populating the ValidatorStates field at all? This test feels redundant with TestValidatorsEmptyIndices

@@ -115,14 +115,15 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {

// Grab genesis validators to get withdrawal creds.
s.Require().NoError(apiClient.Connect(s.Ctx()))
s.Require().NotNil(apiClient.BeaconKitNodeClient)
response, err := apiClient.BeaconKitNodeClient.Validators(s.Ctx(), &api.ValidatorsOpts{
response, err := apiClient.Validators(s.Ctx(), &api.ValidatorsOpts{
State: "genesis",
Indices: []phase0.ValidatorIndex{0, 1, 2, 3, 4},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this be changed to empty Indices so that we know we are querying for all validators, instead of the hardcoded indices.

Copy link
Contributor

@nidhi-singh02 nidhi-singh02 Feb 19, 2025

Choose a reason for hiding this comment

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

Wanted to keep a test for querying multiple specific indices. We already have a test with empty Indices TestValidatorsEmptyIndices in that case we get all the validators.

Edit : TestValidatorsEmptyIndicesAndStatuses is the test as we have merged two tests now.

Signed-off-by: nidhi-singh02 <trippin@berachain.com>
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.

4 participants