mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Handle addition overflow in /eth/v1/beacon/rewards/attestations/{epoch} (#15970)
* Handle addition overflow in `/eth/v1/beacon/rewards/attestations/{epoch}`
* Changelog
This commit is contained in:
@@ -209,8 +209,13 @@ func (s *Server) attRewardsState(w http.ResponseWriter, r *http.Request) (state.
|
||||
httputil.HandleError(w, "Attestation rewards are not supported for Phase 0", http.StatusNotFound)
|
||||
return nil, false
|
||||
}
|
||||
currentEpoch := uint64(slots.ToEpoch(s.TimeFetcher.CurrentSlot()))
|
||||
if requestedEpoch+1 >= currentEpoch {
|
||||
currentEpoch := slots.ToEpoch(s.TimeFetcher.CurrentSlot())
|
||||
bufferedEpoch, err := primitives.Epoch(requestedEpoch).SafeAdd(1)
|
||||
if err != nil {
|
||||
httputil.HandleError(w, "Could not increment epoch: "+err.Error(), http.StatusNotFound)
|
||||
return nil, false
|
||||
}
|
||||
if bufferedEpoch >= currentEpoch {
|
||||
httputil.HandleError(w,
|
||||
"Attestation rewards are available after two epoch transitions to ensure all attestations have a chance of inclusion",
|
||||
http.StatusNotFound)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
@@ -747,6 +748,18 @@ func TestAttestationRewards(t *testing.T) {
|
||||
assert.Equal(t, http.StatusNotFound, e.Code)
|
||||
assert.Equal(t, "Attestation rewards are available after two epoch transitions to ensure all attestations have a chance of inclusion", e.Message)
|
||||
})
|
||||
t.Run("epoch overflow", func(t *testing.T) {
|
||||
url := "http://only.the.epoch.number.at.the.end.is.important/" + strconv.FormatUint(math.MaxUint64, 10)
|
||||
request := httptest.NewRequest("POST", url, nil)
|
||||
writer := httptest.NewRecorder()
|
||||
writer.Body = &bytes.Buffer{}
|
||||
|
||||
s.AttestationRewards(writer, request)
|
||||
assert.Equal(t, http.StatusNotFound, writer.Code)
|
||||
e := &httputil.DefaultJsonError{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), e))
|
||||
assert.Equal(t, http.StatusNotFound, e.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSyncCommiteeRewards(t *testing.T) {
|
||||
|
||||
2
changelog/syjn99-attestation-epoch-overflow.md
Normal file
2
changelog/syjn99-attestation-epoch-overflow.md
Normal file
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Fix #15969: Handle addition overflow in `/eth/v1/beacon/rewards/attestations/{epoch}`.
|
||||
Reference in New Issue
Block a user