2023-01-16 15:00:11 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
2023-01-26 23:13:28 +00:00
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
2023-01-16 15:00:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/time/slots"
|
|
|
|
)
|
|
|
|
|
2023-01-26 23:13:28 +00:00
|
|
|
// This routine broadcasts known BLS changes at the Capella fork.
|
|
|
|
func (s *Service) broadcastBLSChanges(currSlot types.Slot) {
|
2023-01-16 15:00:11 +00:00
|
|
|
capellaSlotStart, err := slots.EpochStart(params.BeaconConfig().CapellaForkEpoch)
|
|
|
|
if err != nil {
|
2023-01-17 10:59:51 +00:00
|
|
|
// only possible error is an overflow, so we exit early from the method
|
2023-01-26 23:13:28 +00:00
|
|
|
return
|
2023-01-16 15:00:11 +00:00
|
|
|
}
|
2023-01-26 23:13:28 +00:00
|
|
|
if currSlot != capellaSlotStart {
|
|
|
|
return
|
2023-01-16 15:00:11 +00:00
|
|
|
}
|
2023-01-26 23:13:28 +00:00
|
|
|
changes, err := s.cfg.blsToExecPool.PendingBLSToExecChanges()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("could not get BLS to execution changes")
|
|
|
|
}
|
|
|
|
if len(changes) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
source := rand.NewGenerator()
|
|
|
|
broadcastChanges := make([]*ethpb.SignedBLSToExecutionChange, len(changes))
|
|
|
|
for i := 0; i < len(changes); i++ {
|
|
|
|
idx := source.Intn(len(changes))
|
|
|
|
broadcastChanges[i] = changes[idx]
|
|
|
|
changes = append(changes[:idx], changes[idx+1:]...)
|
|
|
|
}
|
|
|
|
s.cfg.p2p.BroadcastBLSChanges(s.ctx, broadcastChanges)
|
2023-01-16 15:00:11 +00:00
|
|
|
}
|