Skip to content

Commit c1f0880

Browse files
authored
reduce per-slot state replays on low-participation networks (#7072)
1 parent 17a5d6c commit c1f0880

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

beacon_chain/nimbus_beacon_node.nim

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,8 @@ proc doppelgangerChecked(node: BeaconNode, epoch: Epoch) =
14131413
validator.doppelgangerChecked(epoch - 1)
14141414

14151415
proc maybeUpdateActionTrackerNextEpoch(
1416-
node: BeaconNode, forkyState: ForkyHashedBeaconState, nextEpoch: Epoch) =
1416+
node: BeaconNode, forkyState: ForkyHashedBeaconState, currentSlot: Slot) =
1417+
let nextEpoch = currentSlot.epoch + 1
14171418
if node.consensusManager[].actionTracker.needsUpdate(
14181419
forkyState, nextEpoch):
14191420
template epochRefFallback() =
@@ -1474,15 +1475,20 @@ proc maybeUpdateActionTrackerNextEpoch(
14741475
effective_balance = forkyState.data.validators.item(
14751476
nextEpochFirstProposer).effective_balance
14761477

1477-
if participation_flags.has_flag(TIMELY_SOURCE_FLAG_INDEX) and
1478+
# Maximal potential accuracy primarily useful during the last slot of
1479+
# each epoch to prepare for a possible proposal the first slot of the
1480+
# next epoch. Otherwise, epochRefFallback is potentially very slow as
1481+
# it can induce a lengthy state replay.
1482+
if (not (currentSlot + 1).is_epoch) or
1483+
(participation_flags.has_flag(TIMELY_SOURCE_FLAG_INDEX) and
14781484
participation_flags.has_flag(TIMELY_TARGET_FLAG_INDEX) and
14791485
effective_balance == MAX_EFFECTIVE_BALANCE.Gwei and
14801486
forkyState.data.slot.epoch != GENESIS_EPOCH and
14811487
forkyState.data.inactivity_scores.item(
14821488
nextEpochFirstProposer) == 0 and
14831489
not effective_balance_might_update(
14841490
forkyState.data.balances.item(nextEpochFirstProposer),
1485-
effective_balance):
1491+
effective_balance)):
14861492
node.consensusManager[].actionTracker.updateActions(
14871493
shufflingRef, nextEpochProposers)
14881494
else:
@@ -1567,7 +1573,7 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
15671573
node.consensusManager[].actionTracker.updateActions(
15681574
epochRef.shufflingRef, epochRef.beacon_proposers)
15691575

1570-
node.maybeUpdateActionTrackerNextEpoch(forkyState, slot.epoch + 1)
1576+
node.maybeUpdateActionTrackerNextEpoch(forkyState, slot)
15711577

15721578
if node.gossipState.card > 0 and targetGossipState.card == 0:
15731579
debug "Disabling topic subscriptions",
@@ -1713,7 +1719,7 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
17131719
# missed sync committee participation via process_sync_aggregate(), but
17141720
# attestation penalties for example, need, specific handling.
17151721
# checked by maybeUpdateActionTrackerNextEpoch.
1716-
node.maybeUpdateActionTrackerNextEpoch(forkyState, slot.epoch + 1)
1722+
node.maybeUpdateActionTrackerNextEpoch(forkyState, slot)
17171723

17181724
let
17191725
nextAttestationSlot =

0 commit comments

Comments
 (0)