Skip to content
Merged
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
44 changes: 22 additions & 22 deletions beacon-chain/sync/initial-sync/blocks_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,39 +347,39 @@ func blobRequest(bwb []blocks2.BlockWithVerifiedBlobs, blobWindowStart primitive
if len(bwb) == 0 {
return nil
}
// Short-circuit if the highest block is before the deneb start epoch or retention period start.
// This assumes blocks are sorted by sortedBlockWithVerifiedBlobSlice.
highest := bwb[len(bwb)-1].Block.Block().Slot()
// bwb is sorted by slot, so if the last element is outside the retention window, no blobs are needed.
if highest < blobWindowStart {
return nil
}
lowest := lowestSlotNeedsBlob(blobWindowStart, bwb)
if lowest == nil {
return nil
}
highest := bwb[len(bwb)-1].Block.Block().Slot()
return &p2ppb.BlobSidecarsByRangeRequest{
StartSlot: *lowest,
Count: uint64(highest.SubSlot(*lowest)) + 1,
}
}

func lowestSlotNeedsBlob(retentionStart primitives.Slot, bwb []blocks2.BlockWithVerifiedBlobs) *primitives.Slot {
i := sort.Search(len(bwb), func(i int) bool {
if bwb[i].Block.Block().Slot() < retentionStart {
return false
if len(bwb) == 0 {
return nil
}
// Short-circuit if the highest block is before the deneb start epoch or retention period start.
// This assumes blocks are sorted by sortedBlockWithVerifiedBlobSlice.
// bwb is sorted by slot, so if the last element is outside the retention window, no blobs are needed.
if bwb[len(bwb)-1].Block.Block().Slot() < retentionStart {
return nil
}
for _, b := range bwb {
slot := b.Block.Block().Slot()
if slot < retentionStart {
continue
}
commits, err := bwb[i].Block.Block().Body().BlobKzgCommitments()
commits, err := b.Block.Block().Body().BlobKzgCommitments()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to return nil here on errors? the caller will also return early with a nil when perhaps we want to propagate an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Something I'm trying to do more often is minimize error handling to callers. In this case we know these accessors just return errors when a property isn't supported by the version. It isn't worth propagating that IMO.

if err != nil || len(commits) == 0 {
return false
continue
}
return true
})
if i >= len(bwb) {
return nil
return &slot
}
s := bwb[i].Block.Block().Slot()
return &s
return nil
}

func sortBlobs(blobs []*p2ppb.BlobSidecar) []*p2ppb.BlobSidecar {
Expand Down Expand Up @@ -427,11 +427,11 @@ func verifyAndPopulateBlobs(bwb []blocks2.BlockWithVerifiedBlobs, blobs []*p2ppb
// There are more expected commitments in this block, but we've run out of blobs from the response
// (out-of-bound error guard).
if blobi == len(blobs) {
return nil, missingCommitError(bb.Block.Root(), commits[ci:])
return nil, missingCommitError(bb.Block.Root(), bb.Block.Block().Slot(), commits[ci:])
}
bl := blobs[blobi]
if bl.Slot != block.Slot() {
return nil, missingCommitError(bb.Block.Root(), commits[ci:])
return nil, missingCommitError(bb.Block.Root(), bb.Block.Block().Slot(), commits[ci:])
}
if bytesutil.ToBytes32(bl.BlockRoot) != bb.Block.Root() {
return nil, errors.Wrapf(errMismatchedBlobBlockRoot,
Expand All @@ -456,13 +456,13 @@ func verifyAndPopulateBlobs(bwb []blocks2.BlockWithVerifiedBlobs, blobs []*p2ppb
return bwb, nil
}

func missingCommitError(root [32]byte, missing [][]byte) error {
func missingCommitError(root [32]byte, slot primitives.Slot, missing [][]byte) error {
missStr := make([]string, len(missing))
for k := range missing {
missStr = append(missStr, fmt.Sprintf("%#x", k))
}
return errors.Wrapf(errMissingBlobsForBlockCommitments,
"block root %#x missing %d commitments %s", root, len(missing), strings.Join(missStr, ","))
"block root %#x at slot %d missing %d commitments %s", root, slot, len(missing), strings.Join(missStr, ","))
}

// fetchBlobsFromPeer fetches blocks from a single randomly selected peer.
Expand Down