2023-04-08 01:01:10 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
|
|
|
|
// OnTick executes on_tick operation for forkchoice.
|
|
|
|
func (f *ForkChoiceStore) OnTick(time uint64) {
|
|
|
|
f.mu.Lock()
|
|
|
|
defer f.mu.Unlock()
|
2023-10-21 21:10:58 +00:00
|
|
|
tickSlot := (time - f.genesisTime) / f.beaconCfg.SecondsPerSlot
|
2023-04-08 01:01:10 +00:00
|
|
|
for f.Slot() < tickSlot {
|
2023-10-21 21:10:58 +00:00
|
|
|
previousTime := f.genesisTime + (f.Slot()+1)*f.beaconCfg.SecondsPerSlot
|
2023-04-08 01:01:10 +00:00
|
|
|
f.onTickPerSlot(previousTime)
|
|
|
|
}
|
|
|
|
f.onTickPerSlot(time)
|
|
|
|
}
|
|
|
|
|
|
|
|
// onTickPerSlot handles ticks
|
|
|
|
func (f *ForkChoiceStore) onTickPerSlot(time uint64) {
|
|
|
|
previousSlot := f.Slot()
|
|
|
|
f.time = time
|
|
|
|
currentSlot := f.Slot()
|
|
|
|
if currentSlot <= previousSlot {
|
|
|
|
return
|
|
|
|
}
|
2023-10-14 18:53:16 +00:00
|
|
|
f.headHash = libcommon.Hash{}
|
2023-04-08 01:01:10 +00:00
|
|
|
// If this is a new slot, reset store.proposer_boost_root
|
|
|
|
f.proposerBoostRoot = libcommon.Hash{}
|
|
|
|
if f.computeSlotsSinceEpochStart(currentSlot) == 0 {
|
|
|
|
f.updateCheckpoints(f.unrealizedJustifiedCheckpoint.Copy(), f.unrealizedFinalizedCheckpoint.Copy())
|
|
|
|
}
|
|
|
|
}
|