Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BIDS-2169) return “OK” and all the information a missing slot has #2641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions handlers/api.go
Copy link
Collaborator

@LuccaBitfly LuccaBitfly Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying the endpoint on missed slots the data returned is a huge array consisting of the same slot object, e.g. /api/v1/slot/230431 on Holesky gives me this (5984 elements):
image

Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,27 @@ func ApiSlots(w http.ResponseWriter, r *http.Request) {
slotOrHash := strings.Replace(vars["slotOrHash"], "0x", "", -1)

blockSlot := int64(-1)
blockRootHash := []byte{}
blockInfo := struct {
BlockRootHash []byte `db:"blockroot"`
Status string `db:"status"`
}{}

if slotOrHash == "latest" {
// simply check the latest slot (might be empty which causes an error)
blockSlot = int64(services.LatestSlot())
} else if slotOrHash == "head" {
// retrieve the slot containing the head block of the chain
blockRootHash = services.Eth1HeadBlockRootHash()
if len(blockRootHash) != 32 {
blockInfo.BlockRootHash = services.Eth1HeadBlockRootHash()
if len(blockInfo.BlockRootHash) != 32 {
sendErrorResponse(w, r.URL.String(), "could not retrieve db results")
return
}
} else {
var err error
blockRootHash, err = hex.DecodeString(slotOrHash)
blockInfo.BlockRootHash, err = hex.DecodeString(slotOrHash)
if err != nil || len(slotOrHash) != 64 {
// not a valid root hash, try to parse as slot number instead
blockRootHash = []byte{}
blockInfo.BlockRootHash = []byte{}
blockSlot, err = strconv.ParseInt(vars["slotOrHash"], 10, 64)
if err != nil {
sendErrorResponse(w, r.URL.String(), "could not parse slot number")
Expand All @@ -413,13 +416,17 @@ func ApiSlots(w http.ResponseWriter, r *http.Request) {
}
}

if len(blockRootHash) != 32 {
err := db.ReaderDb.Get(&blockRootHash, `SELECT blockroot FROM blocks WHERE slot = $1`, blockSlot)
err := db.ReaderDb.Get(&blockInfo, `SELECT blockroot, status FROM blocks WHERE slot = $1`, blockSlot)

if err != nil || len(blockRootHash) != 32 {
sendErrorResponse(w, r.URL.String(), "could not retrieve db results")
return
}
if err != nil {
sendErrorResponse(w, r.URL.String(), "could not retrieve db results")
return
}

// status 2 = missed slots
if len(blockInfo.BlockRootHash) != 32 && blockInfo.Status != "2" {
sendErrorResponse(w, r.URL.String(), "could not retrieve db resultsyy")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"resultsyy" 🙃

return
}

rows, err := db.ReaderDb.Query(`
Expand Down Expand Up @@ -467,7 +474,7 @@ func ApiSlots(w http.ResponseWriter, r *http.Request) {
LEFT JOIN
(SELECT beaconblockroot, sum(array_length(validators, 1)) AS votes FROM blocks_attestations GROUP BY beaconblockroot) ba ON (blocks.blockroot = ba.beaconblockroot)
WHERE
blocks.blockroot = $1`, blockRootHash)
blocks.blockroot = $1`, blockInfo.BlockRootHash)

if err != nil {
logger.WithError(err).Error("could not retrieve db results")
Expand Down