Skip to content

Commit

Permalink
fix(api): deduplicate and sort block numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
guybrush authored and peterbitfly committed Jan 15, 2025
1 parent 34360ce commit 806c4d5
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions handlers/api_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"net/http"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -69,28 +70,24 @@ func ApiETH1ExecBlocks(w http.ResponseWriter, r *http.Request) {
limit := uint64(100)
vars := mux.Vars(r)

var blockList []uint64
blockListMap := make(map[uint64]struct{}, 100)

splits := strings.Split(vars["blockNumber"], ",")

if len(splits) > int(limit) {
SendBadRequestResponse(w, r.URL.String(), fmt.Sprintf("only a maximum of %d query parameters are allowed", limit))
return
}

slices.Sort(splits)
splits = slices.Compact(splits)

var blockList []uint64
for _, split := range splits {
temp, err := strconv.ParseUint(split, 10, 64)
if err != nil {
SendBadRequestResponse(w, r.URL.String(), "invalid block number")
return
}
_, seen := blockListMap[temp]
if seen {
continue
}
blockList = append(blockList, temp)
blockListMap[temp] = struct{}{}
}

blocks, err := db.BigtableClient.GetBlocksIndexedMultiple(blockList, limit)
Expand Down

0 comments on commit 806c4d5

Please sign in to comment.