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

POST version of GetValidators and GetValidatorBalances #13199

Merged
merged 7 commits into from
Nov 22, 2023

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Nov 17, 2023

What type of PR is this?

Feature

What does this PR do? Why is it needed?

Implements ethereum/beacon-APIs#367. I also simplified testing to use less validators.

Which issues(s) does this PR fix?

Fixes #13187

@rkapka rkapka added Ready For Review API Api related tasks labels Nov 17, 2023
@rkapka rkapka requested a review from a team as a code owner November 17, 2023 18:39
@rkapka rkapka changed the title POST versions of GetValidators and GetValidatorBalances POST version of GetValidators and GetValidatorBalances Nov 17, 2023
if r.Method == http.MethodGet {
rawIds = r.URL.Query()["id"]
} else {
err = json.NewDecoder(r.Body).Decode(&rawIds)
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw the spec and this list should be a unique list of IDs, i don't think decodeIds is checking for uniqueness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see it anywhere in the spec. It is a useful thing to add, but I would prefer to have it in another PR.

nalepae
nalepae previously approved these changes Nov 22, 2023
Copy link
Contributor

@nalepae nalepae left a comment

Choose a reason for hiding this comment

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

3 minors comments

@@ -72,7 +93,12 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
epoch := slots.ToEpoch(st.Slot())
allBalances := st.Balances()

statuses := r.URL.Query()["status"]
var statuses []string
if r.Method == http.MethodGet {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe grouping rawIds and statuses to reduce the number of r.Method == http.MethodGet?
(Not sure what is the most idiomatic in that case.)

Like:

	var rawIds []string
	var statuses []string

	if r.Method == http.MethodGet {
		rawIds = r.URL.Query()["id"]
		statuses = r.URL.Query()["status"]
	} else {
		rawIds = req.Ids
		statuses = req.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.

done

if r.Method == http.MethodPost {
err = json.NewDecoder(r.Body).Decode(&req)
switch {
case err == io.EOF:
Copy link
Contributor

Choose a reason for hiding this comment

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

Those errors case seem not to be tested.
(Not sure about the testing policy in that case.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

} else {
err = json.NewDecoder(r.Body).Decode(&rawIds)
switch {
case err == io.EOF:
Copy link
Contributor

Choose a reason for hiding this comment

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

Those errors case seem not to be tested.
(Not sure about the testing policy in that case.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@prylabs-bulldozer prylabs-bulldozer bot merged commit 4b3c511 into develop Nov 22, 2023
5 checks passed
@prylabs-bulldozer prylabs-bulldozer bot deleted the state-validators-post branch November 22, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BEACON API: add POST validators endpoints for validators and validator_balances endpoints
3 participants