2021-08-27 01:34:20 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
2021-09-03 20:10:31 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
2021-08-27 01:34:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case currSlot := <-slotTicker.C():
|
2021-09-03 20:10:31 +00:00
|
|
|
currEpoch := core.SlotToEpoch(currSlot)
|
2021-08-27 01:34:20 +00:00
|
|
|
if currEpoch == params.BeaconConfig().AltairForkEpoch {
|
|
|
|
// 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.
|
|
|
|
_, 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|