mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 11:32:09 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
"github.com/prysmaticlabs/prysm/v5/time/slots"
|
|
)
|
|
|
|
// A background routine which listens for new and upcoming forks and
|
|
// updates the node's discovery service to reflect any new fork version
|
|
// changes.
|
|
func (s *Service) forkWatcher() {
|
|
slotTicker := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
|
for {
|
|
select {
|
|
case currSlot := <-slotTicker.C():
|
|
currEpoch := slots.ToEpoch(currSlot)
|
|
if currEpoch == params.BeaconConfig().AltairForkEpoch ||
|
|
currEpoch == params.BeaconConfig().BellatrixForkEpoch ||
|
|
currEpoch == params.BeaconConfig().CapellaForkEpoch ||
|
|
currEpoch == params.BeaconConfig().DenebForkEpoch {
|
|
// If we are in the fork epoch, we update our enr with
|
|
// the updated fork digest. These repeatedly does
|
|
// this over the epoch, which might be slightly wasteful
|
|
// but is fine nonetheless.
|
|
if s.dv5Listener != nil { // make sure it's not a local network
|
|
_, err := addForkEntry(s.dv5Listener.LocalNode(), s.genesisTime, s.genesisValidatorsRoot)
|
|
if err != nil {
|
|
log.WithError(err).Error("Could not add fork entry")
|
|
}
|
|
}
|
|
}
|
|
case <-s.ctx.Done():
|
|
log.Debug("Context closed, exiting goroutine")
|
|
slotTicker.Done()
|
|
return
|
|
}
|
|
}
|
|
}
|