Skip to content

Commit

Permalink
query sync duties for correct slot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etan-status committed Jun 15, 2023
1 parent 98ab0af commit 05f2095
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions beacon_chain/validator_client/duties_service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,24 @@ 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
dutyPeriods =
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)
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 05f2095

Please sign in to comment.