diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher.go b/beacon-chain/sync/initial-sync/blocks_fetcher.go index 396a95abb4e2..915826801ed7 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher.go @@ -461,7 +461,7 @@ func (r *blobRange) Request() *p2ppb.BlobSidecarsByRangeRequest { } return &p2ppb.BlobSidecarsByRangeRequest{ StartSlot: r.low, - Count: uint64(r.high.SubSlot(r.low)) + 1, + Count: uint64(r.high.FlooredSubSlot(r.low)) + 1, } } diff --git a/consensus-types/primitives/slot.go b/consensus-types/primitives/slot.go index 3579f4dd97f1..1f9490f88338 100644 --- a/consensus-types/primitives/slot.go +++ b/consensus-types/primitives/slot.go @@ -124,6 +124,14 @@ func (s Slot) SubSlot(x Slot) Slot { return s.Sub(uint64(x)) } +// FlooredSubSlot safely subtracts x from the slot, returning 0 if the result would underflow. +func (s Slot) FlooredSubSlot(x Slot) Slot { + if s < x { + return 0 + } + return s - x +} + // SafeSubSlot finds difference between two slot values. // In case of arithmetic issues (overflow/underflow/div by zero) error is returned. func (s Slot) SafeSubSlot(x Slot) (Slot, error) {