-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13ae2d0
POST versions of GetValidators and GetValidatorBalances
rkapka 02adbf6
Merge branch '__develop' into state-validators-post
rkapka d5e6309
post statuses
rkapka 30838cd
balances test
rkapka c1d9896
Merge branch 'develop' into state-validators-post
rkapka 77b0b32
group params
rkapka 02cb208
test error cases
rkapka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package beacon | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
@@ -49,7 +51,32 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) { | |
} | ||
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot) | ||
|
||
rawIds := r.URL.Query()["id"] | ||
var req GetValidatorsRequest | ||
if r.Method == http.MethodPost { | ||
err = json.NewDecoder(r.Body).Decode(&req) | ||
switch { | ||
case err == io.EOF: | ||
http2.HandleError(w, "No data submitted", http.StatusBadRequest) | ||
return | ||
case err != nil: | ||
http2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
} | ||
|
||
var statuses []string | ||
var rawIds []string | ||
if r.Method == http.MethodGet { | ||
rawIds = r.URL.Query()["id"] | ||
statuses = r.URL.Query()["status"] | ||
} else { | ||
rawIds = req.Ids | ||
statuses = req.Statuses | ||
} | ||
for i, ss := range statuses { | ||
statuses[i] = strings.ToLower(ss) | ||
} | ||
|
||
ids, ok := decodeIds(w, st, rawIds, true /* ignore unknown */) | ||
if !ok { | ||
return | ||
|
@@ -72,11 +99,6 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) { | |
epoch := slots.ToEpoch(st.Slot()) | ||
allBalances := st.Balances() | ||
|
||
statuses := r.URL.Query()["status"] | ||
for i, ss := range statuses { | ||
statuses[i] = strings.ToLower(ss) | ||
} | ||
|
||
// Exit early if no matching validators were found or we don't want to further filter validators by status. | ||
if len(readOnlyVals) == 0 || len(statuses) == 0 { | ||
containers := make([]*ValidatorContainer, len(readOnlyVals)) | ||
|
@@ -234,7 +256,21 @@ func (bs *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) { | |
} | ||
isFinalized := bs.FinalizationFetcher.IsFinalized(ctx, blockRoot) | ||
|
||
rawIds := r.URL.Query()["id"] | ||
var rawIds []string | ||
if r.Method == http.MethodGet { | ||
rawIds = r.URL.Query()["id"] | ||
} else { | ||
err = json.NewDecoder(r.Body).Decode(&rawIds) | ||
switch { | ||
case err == io.EOF: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those errors case seem not to be tested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
http2.HandleError(w, "No data submitted", http.StatusBadRequest) | ||
return | ||
case err != nil: | ||
http2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
} | ||
|
||
ids, ok := decodeIds(w, st, rawIds, true /* ignore unknown */) | ||
if !ok { | ||
return | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Those errors case seem not to be tested.
(Not sure about the testing policy in that case.)
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.
done