From 6f68c1a46e268a6e812da1c6cacaf46c53e6f146 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 16 Jun 2023 08:33:13 +0200 Subject: [PATCH] query sync duties for correct slot (#5083) VC currently misses sync committee duties for first slot of most epochs because the 1 slot offset is not taken into account. Duties for the next slot must be used during any given current slot. We use the correct slot for processing the duty, but do not use the correct slot for fetching. --- .../validator_client/duties_service.nim | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/beacon_chain/validator_client/duties_service.nim b/beacon_chain/validator_client/duties_service.nim index 3ee98d050..86fe35070 100644 --- a/beacon_chain/validator_client/duties_service.nim +++ b/beacon_chain/validator_client/duties_service.nim @@ -409,7 +409,9 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} = let vc = service.client let currentSlot = vc.getCurrentSlot().get(Slot(0)) - currentEpoch = currentSlot.epoch() + # https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/altair/validator.md#sync-committee + dutySlot = currentSlot + 1 + dutyEpoch = dutySlot.epoch() if vc.attachedValidators[].count() != 0: let @@ -417,15 +419,14 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} = block: var res: seq[tuple[epoch: Epoch, period: SyncCommitteePeriod]] let - currentPeriod = currentSlot.sync_committee_period() - lookaheadSlot = currentSlot + - SUBSCRIPTION_LOOKAHEAD_EPOCHS * SLOTS_PER_EPOCH - lookaheadPeriod = lookaheadSlot.sync_committee_period() + dutyPeriod = dutySlot.sync_committee_period() + lookaheadEpoch = dutyEpoch + SUBSCRIPTION_LOOKAHEAD_EPOCHS + lookaheadPeriod = lookaheadEpoch.sync_committee_period() res.add( - (epoch: currentSlot.epoch(), - period: currentPeriod) + (epoch: dutyEpoch, + period: dutyPeriod) ) - if lookaheadPeriod > currentPeriod: + if lookaheadPeriod > dutyPeriod: res.add( (epoch: lookaheadPeriod.start_epoch(), period: lookaheadPeriod) @@ -446,7 +447,7 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} = if total == 0: debug "No new sync committee member's duties received", - slot = currentSlot + slot = dutySlot let subscriptions = block: @@ -470,10 +471,10 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} = let res = await vc.prepareSyncCommitteeSubnets(subscriptions) if res == 0: warn "Failed to subscribe validators to sync committee subnets", - slot = currentSlot, epoch = currentEpoch, + slot = dutySlot, epoch = dutyEpoch, subscriptions_count = len(subscriptions) - service.pruneSyncCommitteeDuties(currentSlot) + service.pruneSyncCommitteeDuties(dutySlot) proc pruneBeaconProposers(service: DutiesServiceRef, epoch: Epoch) = let vc = service.client