Skip to content

Commit

Permalink
Factorize blobs subscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Dec 30, 2024
1 parent 4e62a24 commit 051875e
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,21 @@ func (s *Service) registerSubscribers(epoch primitives.Epoch, digest [4]byte) {
s.validateBlob,
s.blobSubscriber,
digest,
blobSubnetSlice(epoch),
func(currentSlot primitives.Slot) []uint64 { return []uint64{} },
)
}

if params.BeaconConfig().ElectraForkEpoch <= epoch {
s.subscribeWithParameters(
p2p.BlobSubnetTopicFormat,
s.validateBlob,
s.blobSubscriber,
digest,
blobSubnetSlice(epoch),
blobSubnetSlice,
func(currentSlot primitives.Slot) []uint64 { return []uint64{} },
)
}
}

// blobSubnetSlice returns the blob subnet slice for the given epoch.
func blobSubnetSlice(e primitives.Epoch) func(primitives.Slot) []uint64 {
if e >= params.BeaconConfig().ElectraForkEpoch {
return func(primitives.Slot) []uint64 {
return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCountElectra)
}
// blobSubnetSlice returns the blob subnet slice for the given slot.
func blobSubnetSlice(currentSlot primitives.Slot) []uint64 {
currentEpoch := slots.ToEpoch(currentSlot)

if currentEpoch >= params.BeaconConfig().ElectraForkEpoch {
return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCountElectra)
}
return func(primitives.Slot) []uint64 { return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCount) }

return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCount)
}

// subscribe to a given topic with a given validator and subscription handler.
Expand Down

0 comments on commit 051875e

Please sign in to comment.