Fix bug in Beacon API getBlobs (#13100)

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
Justin Traglia 2023-10-24 22:33:59 -05:00 committed by GitHub
parent cbf6a2752d
commit 671bf00c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -85,7 +85,7 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
http2.HandleError(w, errors.Wrapf(err, "could not retrieve blobs for slot %d", slot).Error(), http.StatusInternalServerError)
return
}
http2.WriteJson(w, buildSidecardsResponse(sidecars))
http2.WriteJson(w, buildSidecarsResponse(sidecars))
return
}
}
@ -116,7 +116,7 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
return
}
http2.WriteJson(w, buildSidecardsResponse(sidecars))
http2.WriteJson(w, buildSidecarsResponse(sidecars))
}
// parseIndices filters out invalid and duplicate blob indices
@ -129,8 +129,11 @@ loop:
if err != nil {
continue
}
if ix >= field_params.MaxBlobsPerBlock {
continue
}
for i := range indices {
if ix == indices[i] || ix >= field_params.MaxBlobsPerBlock {
if ix == indices[i] {
continue loop
}
}
@ -139,7 +142,7 @@ loop:
return indices
}
func buildSidecardsResponse(sidecars []*eth.BlobSidecar) *SidecarsResponse {
func buildSidecarsResponse(sidecars []*eth.BlobSidecar) *SidecarsResponse {
resp := &SidecarsResponse{Data: make([]*Sidecar, len(sidecars))}
for i, sc := range sidecars {
resp.Data[i] = &Sidecar{

View File

@ -23,7 +23,7 @@ import (
)
func TestParseIndices(t *testing.T) {
assert.DeepEqual(t, []uint64{1, 2, 3}, parseIndices(&url.URL{RawQuery: "indices=1&indices=2&indices=foo&indices=1&indices=3&bar=bar"}))
assert.DeepEqual(t, []uint64{1, 2, 3}, parseIndices(&url.URL{RawQuery: "indices=100&indices=1&indices=2&indices=foo&indices=1&indices=3&bar=bar"}))
}
func TestBlobs(t *testing.T) {