2021-08-27 01:34:20 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/encoder"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/time/slots"
|
2021-08-27 01:34:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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() {
|
2021-09-15 00:09:04 +00:00
|
|
|
slotTicker := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
2021-08-27 01:34:20 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case currSlot := <-slotTicker.C():
|
2021-10-01 20:17:57 +00:00
|
|
|
currEpoch := slots.ToEpoch(currSlot)
|
2022-01-20 14:12:15 +00:00
|
|
|
if currEpoch == params.BeaconConfig().AltairForkEpoch ||
|
2022-11-09 23:11:46 +00:00
|
|
|
currEpoch == params.BeaconConfig().BellatrixForkEpoch ||
|
2023-07-10 19:02:44 +00:00
|
|
|
currEpoch == params.BeaconConfig().CapellaForkEpoch ||
|
|
|
|
currEpoch == params.BeaconConfig().DenebForkEpoch {
|
2021-08-27 01:34:20 +00:00
|
|
|
// 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.
|
2023-02-22 06:53:09 +00:00
|
|
|
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")
|
|
|
|
}
|
2021-08-27 01:34:20 +00:00
|
|
|
}
|
2022-01-20 14:12:15 +00:00
|
|
|
|
|
|
|
// from Bellatrix Epoch, the MaxGossipSize and the MaxChunkSize is changed to 10Mb.
|
2022-11-09 23:59:10 +00:00
|
|
|
if currEpoch == params.BeaconConfig().BellatrixForkEpoch {
|
2022-01-20 14:12:15 +00:00
|
|
|
encoder.SetMaxGossipSizeForBellatrix()
|
|
|
|
encoder.SetMaxChunkSizeForBellatrix()
|
|
|
|
}
|
2021-08-27 01:34:20 +00:00
|
|
|
}
|
|
|
|
case <-s.ctx.Done():
|
|
|
|
log.Debug("Context closed, exiting goroutine")
|
|
|
|
slotTicker.Done()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|