Sync committee slot offset.

Ensure that sync committee messages are created for the slots of the
sync period, rather than in the slots of the sync period.
This commit is contained in:
Jim McDonald 2021-08-02 15:10:19 +01:00
parent 2a17229b39
commit d7efbd856b
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
2 changed files with 12 additions and 4 deletions

View File

@ -207,9 +207,13 @@ func (s *Service) refreshSyncCommitteeDutiesForEpochPeriod(ctx context.Context,
// Work out start and end epoch for the period.
period := uint64(epoch) / s.epochsPerSyncCommitteePeriod
firstEpoch := s.firstEpochOfSyncPeriod(period)
firstSlot := s.chainTimeService.FirstSlotOfEpoch(firstEpoch)
// If we are in the sync committee that starts at slot x we need to generate a message during slot x-1
// for it to be included in slot x, hence -1.
firstSlot := s.chainTimeService.FirstSlotOfEpoch(firstEpoch) - 1
lastEpoch := s.firstEpochOfSyncPeriod(period+1) - 1
lastSlot := s.chainTimeService.FirstSlotOfEpoch(lastEpoch+1) - 1
// If we are in the sync committee that ends at slot x we do not generate a message during slot x-1
// as it will never be included, hence -1.
lastSlot := s.chainTimeService.FirstSlotOfEpoch(lastEpoch+1) - 2
// First thing we do is cancel all scheduled sync committee message jobs.
for slot := firstSlot; slot <= lastSlot; slot++ {

View File

@ -40,9 +40,13 @@ func (s *Service) scheduleSyncCommitteeMessages(ctx context.Context,
period := uint64(epoch) / s.epochsPerSyncCommitteePeriod
firstEpoch := s.firstEpochOfSyncPeriod(period)
firstSlot := s.chainTimeService.FirstSlotOfEpoch(firstEpoch)
// If we are in the sync committee that starts at slot x we need to generate a message during slot x-1
// for it to be included in slot x, hence -1.
firstSlot := s.chainTimeService.FirstSlotOfEpoch(firstEpoch) - 1
lastEpoch := s.firstEpochOfSyncPeriod(period+1) - 1
lastSlot := s.chainTimeService.FirstSlotOfEpoch(lastEpoch+1) - 1
// If we are in the sync committee that ends at slot x we do not generate a message during slot x-1
// as it will never be included, hence -1.
lastSlot := s.chainTimeService.FirstSlotOfEpoch(lastEpoch+1) - 2
started := time.Now()
log.Trace().Uint64("period", period).Uint64("first_epoch", uint64(firstEpoch)).Uint64("last_epoch", uint64(lastEpoch)).Msg("Scheduling sync committee messages")