registerSubscribers: Register correctly. (#14759)

Issue before this commit:
The `currentSlot` in the `getSubnetsToSubscribe` is really set to the current slot. So, even if the `registerSubscribers` function is called
one epoch in advance, as done in `registerForUpcomingFork`, then
`currentSlot` will still be - really - the current slot.
==> The new blobs subnets will be subscribed only at the start of the
Electra fork, and not one epoch in advance.

With this commit:
The new blobs subnets will be effectively subscribed one epoch in advance.
This commit is contained in:
Manu NALEPA
2024-12-31 09:42:56 +01:00
committed by GitHub
parent ead08d56d0
commit 937d441e2e
2 changed files with 28 additions and 15 deletions

View File

@@ -40,6 +40,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
### Fixed
- Added check to prevent nil pointer deference or out of bounds array access when validating the BLSToExecutionChange on an impossibly nil validator.
- EIP-7691: Ensure new blobs subnets are subscribed on epoch in advance.
### Security

View File

@@ -117,7 +117,7 @@ func (s *Service) registerSubscribers(epoch primitives.Epoch, digest [4]byte) {
s.persistentAndAggregatorSubnetIndices,
s.attesterSubnetIndices,
)
// Altair Fork Version
// Altair fork version
if params.BeaconConfig().AltairForkEpoch <= epoch {
s.subscribe(
p2p.SyncContributionAndProofSubnetTopicFormat,
@@ -135,7 +135,7 @@ func (s *Service) registerSubscribers(epoch primitives.Epoch, digest [4]byte) {
)
}
// New Gossip Topic in Capella
// New gossip topic in Capella
if params.BeaconConfig().CapellaForkEpoch <= epoch {
s.subscribe(
p2p.BlsToExecutionChangeSubnetTopicFormat,
@@ -145,28 +145,33 @@ func (s *Service) registerSubscribers(epoch primitives.Epoch, digest [4]byte) {
)
}
// New Gossip Topic in Deneb
if params.BeaconConfig().DenebForkEpoch <= epoch {
// New gossip topic in Deneb, modified in Electra
if params.BeaconConfig().DenebForkEpoch <= epoch && epoch < params.BeaconConfig().ElectraForkEpoch {
s.subscribeWithParameters(
p2p.BlobSubnetTopicFormat,
s.validateBlob,
s.blobSubscriber,
digest,
blobSubnetSlice,
func(currentSlot primitives.Slot) []uint64 {
return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCount)
},
func(currentSlot primitives.Slot) []uint64 { return []uint64{} },
)
}
}
// 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)
// Modified gossip topic in Electra
if params.BeaconConfig().ElectraForkEpoch <= epoch {
s.subscribeWithParameters(
p2p.BlobSubnetTopicFormat,
s.validateBlob,
s.blobSubscriber,
digest,
func(currentSlot primitives.Slot) []uint64 {
return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCountElectra)
},
func(currentSlot primitives.Slot) []uint64 { return []uint64{} },
)
}
return sliceFromCount(params.BeaconConfig().BlobsidecarSubnetCount)
}
// subscribe to a given topic with a given validator and subscription handler.
@@ -440,7 +445,14 @@ func (s *Service) subscribeToSubnets(
description = topicFormat[pos+1:]
}
log.WithField("digest", fmt.Sprintf("%#x", digest)).Warningf("%s subnets with this digest are no longer valid, unsubscribing from all of them.", description)
if pos := strings.LastIndex(description, "_"); pos != -1 {
description = description[:pos]
}
log.WithFields(logrus.Fields{
"digest": fmt.Sprintf("%#x", digest),
"subnets": description,
}).Debug("Subnets with this digest are no longer valid, unsubscribing from all of them")
s.reValidateSubscriptions(subscriptions, []uint64{}, topicFormat, digest)
return false
}