-
Notifications
You must be signed in to change notification settings - Fork 210
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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>
node-api/backend/validator.go
Outdated
} | ||
|
||
if !matchesStatusFilter(status, statuses) { | ||
//nolint:nilnil // no data to return |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
nit for readability Signed-off-by: Cal Bera <calbera@berachain.com>
There was a problem hiding this 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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
Tested these two endpoints -
https://ethereum.github.io/beacon-APIs/#/Beacon/getStateValidators
https://ethereum.github.io/beacon-APIs/#/Beacon/postStateValidators
Testing other validator endpoints, will open separate PR as don't want to increase diff.