-
Notifications
You must be signed in to change notification settings - Fork 1.3k
binary search is the wrong tool for the job, derp #12757
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
Contributor
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. Do we really want to return
Collaborator
Author
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. 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 { | ||
|
|
@@ -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, | ||
|
|
@@ -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. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.