Blocks filtering should return genesis when startSlot=0 and endSlot=0 (#8270)

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
pinglamb 2021-01-16 02:36:17 +08:00 committed by GitHub
parent b6c4bc197f
commit d7d2c6354b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -442,6 +442,11 @@ func fetchBlockRootsBySlotRange(
ctx, span := trace.StartSpan(ctx, "BeaconDB.fetchBlockRootsBySlotRange")
defer span.End()
// Return nothing when all slot parameters are missing
if startSlotEncoded == nil && endSlotEncoded == nil && startEpochEncoded == nil && endEpochEncoded == nil {
return [][]byte{}, nil
}
var startSlot, endSlot, step uint64
var ok bool
if startSlot, ok = startSlotEncoded.(uint64); !ok {
@ -476,10 +481,6 @@ func fetchBlockRootsBySlotRange(
if endSlot < startSlot {
return nil, errInvalidSlotRange
}
// Return nothing with an end slot of 0.
if endSlot == 0 {
return [][]byte{}, nil
}
rootsRange := (endSlot - startSlot) / step
roots := make([][]byte, 0, rootsRange)
c := bkt.Cursor()

View File

@ -118,7 +118,7 @@ func TestStore_BlocksHandleZeroCase(t *testing.T) {
zeroFilter := filters.NewFilter().SetStartSlot(0).SetEndSlot(0)
retrieved, _, err := db.Blocks(ctx, zeroFilter)
require.NoError(t, err)
assert.Equal(t, 0, len(retrieved), "Unexpected number of blocks received, expected none")
assert.Equal(t, 1, len(retrieved), "Unexpected number of blocks received, expected one")
}
func TestStore_BlocksHandleInvalidEndSlot(t *testing.T) {