Skip to content

Commit

Permalink
fix(api): deduplicate block numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbitfly committed Jan 15, 2025
1 parent 2b2512b commit 34360ce
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions handlers/api_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,27 @@ func ApiETH1ExecBlocks(w http.ResponseWriter, r *http.Request) {
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
}

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

if len(blockList) > int(limit) {
SendBadRequestResponse(w, r.URL.String(), fmt.Sprintf("only a maximum of %d query parameters are allowed", limit))
return
blockListMap[temp] = struct{}{}
}

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

0 comments on commit 34360ce

Please sign in to comment.