Skip to content

Commit 25c7c6b

Browse files
authored
Switch FCR balance source on epoch start rather than epoch end (#8029)
Balance source is now captured only when the new epoch starts, based on the historical checkpoint locked in at slot 31. See `get_previous_balance_source`, `update_fast_confirmation_variables`: - ethereum/consensus-specs#4747
1 parent 699c49c commit 25c7c6b

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

beacon_chain/fork_choice/fork_choice.nim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func init*(
5757
slot: finalized.checkpoint.epoch.start_slot,
5858
root: finalized.checkpoint.root),
5959
current_epoch_observed_justified: finalized.balance_source,
60+
previous_epoch_greatest_unrealized_checkpoint: finalized.checkpoint,
6061
previous_slot_head: finalized.checkpoint.root,
6162
current_slot_head: finalized.checkpoint.root)
6263

@@ -135,8 +136,7 @@ proc update_confirmed(self: var ForkChoiceBackend, confirmed: BlockId) =
135136
self.confirmed = confirmed
136137

137138
proc update_unrealized_justified(self: var ForkChoice, dag: ChainDAGRef) =
138-
template justified: Checkpoint = self.checkpoints.justified.checkpoint
139-
let unrealized = self.backend.proto_array.unrealized_justified(justified)
139+
let unrealized = self.backend.previous_epoch_greatest_unrealized_checkpoint
140140
if unrealized == self.backend.current_epoch_observed_justified.checkpoint:
141141
return
142142

@@ -177,15 +177,20 @@ proc on_tick(
177177
self.backend.previous_slot_head = self.backend.current_slot_head
178178

179179
if (current_slot + 1).is_epoch:
180-
# Update observed justified checkpoint at the beginning of the
181-
# last slot of an epoch
182-
self.update_unrealized_justified(dag)
180+
# Update greatest unrealized justified checkpoint
181+
# at the last slot of an epoch
182+
template justified: Checkpoint = self.checkpoints.justified.checkpoint
183+
self.backend.previous_epoch_greatest_unrealized_checkpoint =
184+
self.backend.proto_array.unrealized_justified(justified)
183185

184186
elif current_slot.is_epoch:
185187
# Pull-up unrealized justified / finalized checkpoints from previous epoch
186188
for realized in self.backend.proto_array.realizePendingCheckpoints():
187189
? self.update_checkpoints(dag, realized, current_slot)
188190

191+
# Update observed justified checkpoints at the start of an epoch
192+
self.update_unrealized_justified(dag)
193+
189194
else:
190195
discard
191196
ok()

beacon_chain/fork_choice/fork_choice_types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type
145145
proto_array*: ProtoArray
146146
confirmed*: BlockId
147147
current_epoch_observed_justified*: BalanceSource
148+
previous_epoch_greatest_unrealized_checkpoint*: Checkpoint
148149
previous_slot_head*, current_slot_head*: Eth2Digest
149150
votes*: seq[VoteTracker]
150151
balances*: seq[ForkChoiceBalance]

beacon_chain/rpc/rest_debug_api.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
107107
confirmed_root: forkChoice.get_safe_beacon_block_root,
108108
current_epoch_observed_justified_checkpoint:
109109
forkChoice.backend.current_epoch_observed_justified.checkpoint,
110+
previous_epoch_greatest_unrealized_checkpoint:
111+
forkChoice.backend.previous_epoch_greatest_unrealized_checkpoint,
110112
previous_slot_head: forkChoice.backend.previous_slot_head,
111113
current_slot_head: forkChoice.backend.current_slot_head))
112114

beacon_chain/spec/eth2_apis/rest_types.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ type
594594
RestExtraData* = object
595595
confirmed_root*: Eth2Digest
596596
current_epoch_observed_justified_checkpoint*: Checkpoint
597+
previous_epoch_greatest_unrealized_checkpoint*: Checkpoint
597598
previous_slot_head*, current_slot_head*: Eth2Digest
598599

599600
GetForkChoiceResponse* = object

0 commit comments

Comments
 (0)