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
ServiceName = "duties_service"
SUBSCRIPTION_LOOKAHEAD_EPOCHS* = 4'u64
logScope: service = ServiceName
@ -439,16 +440,41 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
let
currentSlot = sres.get()
currentEpoch = currentSlot.epoch()
nextEpoch = currentEpoch + 1'u64
if vc.attachedValidators[].count() != 0:
var counts: array[2, tuple[epoch: Epoch, count: int]]
counts[0] =
(currentEpoch, await vc.pollForSyncCommitteeDuties(currentEpoch))
counts[1] =
(nextEpoch, await vc.pollForSyncCommitteeDuties(nextEpoch))
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()
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",
slot = currentSlot
@ -457,6 +483,7 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
var res: seq[RestSyncCommitteeSubscription]
for item in counts:
if item.count > 0:
let untilEpoch = start_epoch(item.period + 1'u64)
let subscriptionsInfo =
vc.syncMembersSubscriptionInfoForEpoch(item.epoch)
for subInfo in subscriptionsInfo:
@ -464,12 +491,11 @@ proc pollForSyncCommitteeDuties* (vc: ValidatorClientRef) {.async.} =
validator_index: subInfo.validator_index,
sync_committee_indices:
subInfo.validator_sync_committee_indices,
until_epoch:
(currentEpoch + EPOCHS_PER_SYNC_COMMITTEE_PERIOD -
currentEpoch.since_sync_committee_period_start()).Epoch
until_epoch: untilEpoch
)
res.add(sub)
res
if len(subscriptions) > 0:
let res = await vc.prepareSyncCommitteeSubnets(subscriptions)
if res != 0: