From d8e6d2cb2ebfa7b288477f98a35470c8b99f2f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kapka?= Date: Sat, 16 Sep 2023 16:11:57 +0200 Subject: [PATCH] Fix proposer duties sorting (#12909) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/rpc/eth/validator/handlers.go | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index 3dcb712e8..3dcc53f33 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -839,9 +839,6 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) { }) } } - sort.Slice(duties, func(i, j int) bool { - return duties[i].Slot < duties[j].Slot - }) s.ProposerSlotIndexCache.PrunePayloadIDs(epochStartSlot) @@ -855,6 +852,9 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) { http2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError) return } + if !sortProposerDuties(w, duties) { + return + } resp := &GetProposerDutiesResponse{ DependentRoot: hexutil.Encode(dependentRoot), @@ -1053,3 +1053,23 @@ func syncCommitteeDuties( } return duties, nil } + +func sortProposerDuties(w http.ResponseWriter, duties []*ProposerDuty) bool { + ok := true + sort.Slice(duties, func(i, j int) bool { + si, err := strconv.ParseUint(duties[i].Slot, 10, 64) + if err != nil { + http2.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError) + ok = false + return false + } + sj, err := strconv.ParseUint(duties[j].Slot, 10, 64) + if err != nil { + http2.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError) + ok = false + return false + } + return si < sj + }) + return ok +}