Fix proposer duties sorting (#12909)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka 2023-09-16 16:11:57 +02:00 committed by GitHub
parent 6b915bab26
commit d8e6d2cb2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}