mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
|
"github.com/OffchainLabs/prysm/v7/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() {
|
|
// Exit early if discovery is disabled - there's no ENR to update
|
|
if s.dv5Listener == nil {
|
|
log.Debug("Discovery disabled, exiting fork watcher")
|
|
return
|
|
}
|
|
|
|
slotTicker := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
|
var scheduleEntry params.NetworkScheduleEntry
|
|
for {
|
|
select {
|
|
case currSlot := <-slotTicker.C():
|
|
currentEpoch := slots.ToEpoch(currSlot)
|
|
newEntry := params.GetNetworkScheduleEntry(currentEpoch)
|
|
if newEntry.ForkDigest != scheduleEntry.ForkDigest {
|
|
nextEntry := params.NextNetworkScheduleEntry(currentEpoch)
|
|
if err := updateENR(s.dv5Listener.LocalNode(), newEntry, nextEntry); err != nil {
|
|
log.WithFields(newEntry.LogFields()).WithError(err).Error("Could not add fork entry")
|
|
continue // don't replace scheduleEntry until this succeeds
|
|
}
|
|
scheduleEntry = newEntry
|
|
}
|
|
case <-s.ctx.Done():
|
|
log.Debug("Context closed, exiting goroutine")
|
|
slotTicker.Done()
|
|
return
|
|
}
|
|
}
|
|
}
|