This commit is contained in:
Eugene Kabanov 2022-11-17 13:09:20 +02:00 committed by GitHub
parent ef2b434ec9
commit a2fc515db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import common, api, block_service
const const
ServiceName = "duties_service" ServiceName = "duties_service"
SUBSCRIPTION_LOOKAHEAD_EPOCHS* = 4'u64
logScope: service = ServiceName logScope: service = ServiceName
@ -439,16 +440,41 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
let let
currentSlot = sres.get() currentSlot = sres.get()
currentEpoch = currentSlot.epoch() currentEpoch = currentSlot.epoch()
nextEpoch = currentEpoch + 1'u64
if vc.attachedValidators[].count() != 0: if vc.attachedValidators[].count() != 0:
var counts: array[2, tuple[epoch: Epoch, count: int]] let
counts[0] = dutyPeriods =
(currentEpoch, await vc.pollForSyncCommitteeDuties(currentEpoch)) block:
counts[1] = var res: seq[tuple[epoch: Epoch, period: SyncCommitteePeriod]]
(nextEpoch, await vc.pollForSyncCommitteeDuties(nextEpoch)) let
currentPeriod = currentSlot.sync_committee_period()
lookaheadSlot = currentSlot +
SUBSCRIPTION_LOOKAHEAD_EPOCHS * SLOTS_PER_EPOCH
lookaheadPeriod = lookaheadSlot.sync_committee_period()
res.add(
(epoch: currentSlot.epoch(),
period: currentPeriod)
)
if lookAheadPeriod > currentPeriod:
res.add(
(epoch: lookaheadPeriod.start_epoch(),
period: lookAheadPeriod)
)
res
if (counts[0].count == 0) and (counts[1].count == 0): (counts, total) =
block:
var res: seq[tuple[epoch: Epoch, period: SyncCommitteePeriod,
count: int]]
var total = 0
if len(dutyPeriods) > 0:
for (epoch, period) in dutyPeriods:
let count = await vc.pollForSyncCommitteeDuties(epoch)
res.add((epoch: epoch, period: period, count: count))
total += count
(res, total)
if total == 0:
debug "No new sync committee member's duties received", debug "No new sync committee member's duties received",
slot = currentSlot slot = currentSlot
@ -457,6 +483,7 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
var res: seq[RestSyncCommitteeSubscription] var res: seq[RestSyncCommitteeSubscription]
for item in counts: for item in counts:
if item.count > 0: if item.count > 0:
let untilEpoch = start_epoch(item.period + 1'u64)
let subscriptionsInfo = let subscriptionsInfo =
vc.syncMembersSubscriptionInfoForEpoch(item.epoch) vc.syncMembersSubscriptionInfoForEpoch(item.epoch)
for subInfo in subscriptionsInfo: for subInfo in subscriptionsInfo:
@ -464,12 +491,11 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
validator_index: subInfo.validator_index, validator_index: subInfo.validator_index,
sync_committee_indices: sync_committee_indices:
subInfo.validator_sync_committee_indices, subInfo.validator_sync_committee_indices,
until_epoch: until_epoch: untilEpoch
(currentEpoch + EPOCHS_PER_SYNC_COMMITTEE_PERIOD -
currentEpoch.since_sync_committee_period_start()).Epoch
) )
res.add(sub) res.add(sub)
res res
if len(subscriptions) > 0: if len(subscriptions) > 0:
let res = await vc.prepareSyncCommitteeSubnets(subscriptions) let res = await vc.prepareSyncCommitteeSubnets(subscriptions)
if res != 0: if res != 0: