only request `nextPeriod` sync duties close to end of `currentPeriod` (#5409)

Currently we always request duties for current and next sync period.
As sync periods are quite long (~27 hrs on Mainnet), having access to
the duties so early doesn't help too much. To avoid running into errors
when the BN does not have the duties available around period boundary,
delay requesting them until the current period is close to finish.

`SYNC_COMMITTEE_SUBNET_COUNT` epochs are what the spec says should be
the lookahead timing of starting to subscribe to sync committee gossip.
Reusing the constant here for consistency.

This fixes these warning messages in the first slot of a new period.

```
rocketpool_validator   | WRN 2023-09-07 20:19:35.439+00:00 Beacon node has incompatible configuration reason="Epoch value is far from the future;400;getSyncCommitteeDuties(first);invalid-request" node=http://eth2:5052[Nimbus/v23.8.0-872b19-stateofus] node_index=0 node_roles=AGBSDT
rocketpool_validator   | WRN 2023-09-07 20:19:35.440+00:00 Unable to get sync committee duties        period=889 epoch=227584 reason="Epoch value is far from the future;400;getSyncCommitteeDuties(first);invalid-request" service=duties_service
rocketpool_validator   | NOT 2023-09-07 20:19:35.441+00:00 Beacon node is in sync                     head_slot=7274495 sync_distance=1 is_optimistic=false node=http://eth2:5052[Nimbus/v23.8.0-872b19-stateofus] node_index=0 node_roles=AGBSDT
```
This commit is contained in:
Etan Kissling 2023-09-13 08:58:28 +02:00 committed by GitHub
parent cd68c71c6c
commit d7aaf1b809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -371,8 +371,19 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} =
var counts: array[2, tuple[period: SyncCommitteePeriod, count: int]] var counts: array[2, tuple[period: SyncCommitteePeriod, count: int]]
counts[0] = (currentPeriod, counts[0] = (currentPeriod,
await service.pollForSyncCommitteeDuties(currentPeriod)) await service.pollForSyncCommitteeDuties(currentPeriod))
const
numDelayEpochs = 4 # Chosen empirically
numLookaheadEpochs =
max(EPOCHS_PER_SYNC_COMMITTEE_PERIOD, numDelayEpochs) -
numDelayEpochs + 1
if (currentEpoch + numLookaheadEpochs) >= nextPeriod.start_epoch:
counts[1] = (nextPeriod, counts[1] = (nextPeriod,
await service.pollForSyncCommitteeDuties(nextPeriod)) await service.pollForSyncCommitteeDuties(nextPeriod))
else:
# Skip fetching `nextPeriod` until sync committees are likely known,
# as determined by `numDelayEpochs` from sync committee period start.
counts[1] = (nextPeriod, 0)
if (counts[0].count == 0) and (counts[1].count == 0): if (counts[0].count == 0) and (counts[1].count == 0):
debug "No new sync committee duties received", slot = currentSlot debug "No new sync committee duties received", slot = currentSlot