-
Notifications
You must be signed in to change notification settings - Fork 441
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
gocoffeecup
wants to merge
1
commit into
gobitfly:master
Choose a base branch
from
gocoffeecup:BIDS-2169
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "resultsyy" 🙃 |
||
return | ||
} | ||
|
||
rows, err := db.ReaderDb.Query(` | ||
|
@@ -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") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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):