Skip to content

Commit

Permalink
Fix proposer duties sorting (#12909)
Browse files Browse the repository at this point in the history
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
rkapka and prylabs-bulldozer[bot] authored Sep 16, 2023
1 parent 6b915ba commit d8e6d2c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions beacon-chain/rpc/eth/validator/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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),
Expand Down Expand Up @@ -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
}

0 comments on commit d8e6d2c

Please sign in to comment.