Compare commits

...

2 Commits

Author SHA1 Message Date
Potuz
181890e85c Terence's review 2024-02-02 14:44:03 -03:00
Potuz
74790e9986 Change init sync heursitics 2024-02-02 14:10:10 -03:00
2 changed files with 12 additions and 7 deletions

View File

@@ -559,15 +559,20 @@ func (s *Service) RecentBlockSlot(root [32]byte) (primitives.Slot, error) {
// inRegularSync applies the following heuristics to decide if the node is in
// regular sync mode vs init sync mode using only forkchoice.
// It checks that the highest received block is behind the current time by at least 2 epochs
// and that it was imported at least one epoch late if both of these
// tests pass then the node is in init sync. The caller of this function MUST
// have a lock on forkchoice
// The caller of this function MUST have a lock on forkchoice
func (s *Service) inRegularSync() bool {
currentSlot := s.CurrentSlot()
fc := s.cfg.ForkChoiceStore
if currentSlot-fc.HighestReceivedBlockSlot() < 2*params.BeaconConfig().SlotsPerEpoch {
highestSlot := fc.HighestReceivedBlockSlot()
// if the highest received slot is from the same epoch, we are in regular sync
if slots.ToEpoch(currentSlot) == slots.ToEpoch(highestSlot) {
return true
}
return fc.HighestReceivedBlockDelay() < params.BeaconConfig().SlotsPerEpoch
// If the highest received block is less than 2 blocks away we are in regular sync
if currentSlot-highestSlot < primitives.Slot(2) {
return true
}
// At this stage the last block received is from the previous epoch and more than 2 blocks ago.
// If the highest slot was received during its slot or the next one then we are in regular sync
return fc.HighestReceivedBlockDelay() < primitives.Slot(2)
}

View File

@@ -609,7 +609,7 @@ func TestService_inRegularSync(t *testing.T) {
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
require.Equal(t, false, c.inRegularSync())
c.SetGenesisTime(time.Now().Add(time.Second * time.Duration(-5*int64(params.BeaconConfig().SlotsPerEpoch)*int64(params.BeaconConfig().SecondsPerSlot))))
c.SetGenesisTime(time.Now().Add(time.Second * time.Duration(-4*int64(params.BeaconConfig().SlotsPerEpoch)*int64(params.BeaconConfig().SecondsPerSlot))))
require.Equal(t, true, c.inRegularSync())
c.SetGenesisTime(time.Now().Add(time.Second * time.Duration(-1*int64(params.BeaconConfig().SlotsPerEpoch)*int64(params.BeaconConfig().SecondsPerSlot))))