-
Notifications
You must be signed in to change notification settings - Fork 1.3k
P2P: broadcast blob #12419
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
Merged
Merged
P2P: broadcast blob #12419
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a156674
Broadcast blob
terencechain 9bdfb8f
Add retry attempt
terencechain e8c12f2
Test feedback
terencechain 0423099
Update beacon-chain/p2p/subnets.go
rkapka 4660b31
Set blob subnet locker val to 110
terencechain 9568071
rm new line
terencechain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -202,6 +202,67 @@ func (s *Service) broadcastSyncCommittee(ctx context.Context, subnet uint64, sMs | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // BroadcastBlob broadcasts a blob to the p2p network, the message is assumed to be | ||||||
| // broadcasted to the current fork and to the input subnet. | ||||||
| func (s *Service) BroadcastBlob(ctx context.Context, subnet uint64, blob *ethpb.SignedBlobSidecar) error { | ||||||
| ctx, span := trace.StartSpan(ctx, "p2p.BroadcastBlob") | ||||||
| defer span.End() | ||||||
| if blob == nil { | ||||||
| return errors.New("attempted to broadcast nil blob sidecar") | ||||||
| } | ||||||
| forkDigest, err := s.currentForkDigest() | ||||||
| if err != nil { | ||||||
| err := errors.Wrap(err, "could not retrieve fork digest") | ||||||
| tracing.AnnotateError(span, err) | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| // Non-blocking broadcast, with attempts to discover a subnet peer if none available. | ||||||
| go s.broadcastBlob(ctx, subnet, blob, forkDigest) | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func (s *Service) broadcastBlob(ctx context.Context, subnet uint64, blobSidecar *ethpb.SignedBlobSidecar, forkDigest [4]byte) { | ||||||
| _, span := trace.StartSpan(ctx, "p2p.broadcastBlob") | ||||||
|
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.
Suggested change
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. renamed the function to |
||||||
| defer span.End() | ||||||
| ctx = trace.NewContext(context.Background(), span) // clear parent context / deadline. | ||||||
|
|
||||||
| oneSlot := time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second | ||||||
| ctx, cancel := context.WithTimeout(ctx, oneSlot) | ||||||
| defer cancel() | ||||||
|
|
||||||
| wrappedSubIdx := subnet + blobSubnetLockerVal | ||||||
| s.subnetLocker(wrappedSubIdx).RLock() | ||||||
| hasPeer := s.hasPeerWithSubnet(blobSubnetToTopic(subnet, forkDigest)) | ||||||
| s.subnetLocker(wrappedSubIdx).RUnlock() | ||||||
|
|
||||||
| if !hasPeer { | ||||||
| blobSidecarCommitteeBroadcastAttempts.Inc() | ||||||
| if err := func() error { | ||||||
| s.subnetLocker(wrappedSubIdx).Lock() | ||||||
| defer s.subnetLocker(wrappedSubIdx).Unlock() | ||||||
| ok, err := s.FindPeersWithSubnet(ctx, blobSubnetToTopic(subnet, forkDigest), subnet, 1) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if ok { | ||||||
| blobSidecarCommitteeBroadcasts.Inc() | ||||||
| return nil | ||||||
| } | ||||||
| return errors.New("failed to find peers for subnet") | ||||||
| }(); err != nil { | ||||||
| log.WithError(err).Error("Failed to find peers") | ||||||
| tracing.AnnotateError(span, err) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if err := s.broadcastObject(ctx, blobSidecar, blobSubnetToTopic(subnet, forkDigest)); err != nil { | ||||||
| log.WithError(err).Error("Failed to broadcast blob sidecar") | ||||||
| tracing.AnnotateError(span, err) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // method to broadcast messages to other peers in our gossip mesh. | ||||||
| func (s *Service) broadcastObject(ctx context.Context, obj ssz.Marshaler, topic string) error { | ||||||
| ctx, span := trace.StartSpan(ctx, "p2p.broadcastObject") | ||||||
|
|
@@ -238,3 +299,7 @@ func attestationToTopic(subnet uint64, forkDigest [4]byte) string { | |||||
| func syncCommitteeToTopic(subnet uint64, forkDigest [4]byte) string { | ||||||
| return fmt.Sprintf(SyncCommitteeSubnetTopicFormat, forkDigest, subnet) | ||||||
| } | ||||||
|
|
||||||
| func blobSubnetToTopic(subnet uint64, forkDigest [4]byte) string { | ||||||
| return fmt.Sprintf(BlobSubnetTopicFormat, forkDigest, subnet) | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the only validation we need to do before a blob sidecar is broadcasted? do we need to validate blob with kzg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just broadcast from p2p's perspective. Validations (if there are any) are done before this