Skip to content

Commit dd35d2d

Browse files
authored
delay onSlotEnd if there are duties (#5196)
We currently call `onSlotEnd` whenever all in-BN validator duties are completed. VC validator duties are not awaited. When `onSlotEnd` is processed close to the slot start, a VC may therefore miss duties. Adding a delay before `onSlotEnd` improves this situation. The logic can be optimized further if `ActionTracker` would track `knownValidators` from REST separately from in-process ones.
1 parent f98c33a commit dd35d2d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

beacon_chain/nimbus_beacon_node.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,15 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
11441144
# Things we do when slot processing has ended and we're about to wait for the
11451145
# next slot
11461146

1147+
# By waiting until close before slot end, ensure that preparation for next
1148+
# slot does not interfere with propagation of messages and with VC duties.
1149+
const endOffset = aggregateSlotOffset + nanos(
1150+
(NANOSECONDS_PER_SLOT - aggregateSlotOffset.nanoseconds.uint64).int64 div 2)
1151+
let endCutoff = node.beaconClock.fromNow(slot.start_beacon_time + endOffset)
1152+
if endCutoff.inFuture:
1153+
debug "Waiting for slot end", slot, endCutoff = shortLog(endCutoff.offset)
1154+
await sleepAsync(endCutoff.offset)
1155+
11471156
if node.dag.needStateCachesAndForkChoicePruning():
11481157
if node.attachedValidators[].validators.len > 0:
11491158
node.attachedValidators[]

beacon_chain/spec/beacon_time.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const
4848

4949
FAR_FUTURE_BEACON_TIME* = BeaconTime(ns_since_genesis: int64.high())
5050

51-
NANOSECONDS_PER_SLOT = SECONDS_PER_SLOT * 1_000_000_000'u64
51+
NANOSECONDS_PER_SLOT* = SECONDS_PER_SLOT * 1_000_000_000'u64
5252

5353
template ethTimeUnit*(typ: type) {.dirty.} =
5454
func `+`*(x: typ, y: uint64): typ {.borrow.}

0 commit comments

Comments
 (0)