ensure sync duties for next epoch are registered in time (#5084)

* ensure sync duties for next epoch are registered in time

For attestations, VC queries duties for current and next epoch.
For sync messages, VC queries for current and next period (if soon).
This means that for sync messages we don't actually have the duties for
next epoch in all situations, leading to situation where VC may miss
sync duties in the final slot of an epoch when using. As duties remain
same within a sync committee period, simply copy them over to next epoch
to avoid this situation without adding network latency.

* Update beacon_chain/validator_client/duties_service.nim

Co-authored-by: Jacek Sieka <jacek@status.im>

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
This commit is contained in:
Etan Kissling 2023-06-16 10:42:57 +02:00 committed by GitHub
parent 6f68c1a46e
commit e9262ab6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -305,7 +305,9 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef,
validator_sync_committee_index: validatorSyncCommitteeIndex))
res
fork = vc.forkAtEpoch(epoch)
nextEpoch = epoch + 1
nextEpochHasSameDuties =
epoch.sync_committee_period == nextEpoch.sync_committee_period
let addOrReplaceItems =
block:
@ -318,6 +320,10 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef,
map.duties.withValue(epoch, epochDuty):
if epochDuty[] != duty:
dutyFound = true
if nextEpochHasSameDuties:
map.duties.withValue(nextEpoch, epochDuty):
if epochDuty[] != duty:
dutyFound = true
if dutyFound and not alreadyWarned:
info "Sync committee duties re-organization", duty, epoch
@ -331,6 +337,8 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef,
var validatorDuties =
vc.syncCommitteeDuties.getOrDefault(duty.pubkey)
validatorDuties.duties[epoch] = duty
if nextEpochHasSameDuties:
validatorDuties.duties[nextEpoch] = duty
vc.syncCommitteeDuties[duty.pubkey] = validatorDuties
return len(addOrReplaceItems)