diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index f93883d4d..16972064f 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -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() diff --git a/beacon-chain/db/kv/blocks_test.go b/beacon-chain/db/kv/blocks_test.go index 150dcc0b6..7f7444556 100644 --- a/beacon-chain/db/kv/blocks_test.go +++ b/beacon-chain/db/kv/blocks_test.go @@ -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) {