Add condition check in `on_tick` to ensure that `store.justified_checkpoint` is a descendant of `store.finalized_checkpoint`

This commit is contained in:
Hsiao-Wei Wang 2021-07-14 20:02:21 +08:00
parent 421166544a
commit 63ca480ea3
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E
1 changed files with 6 additions and 2 deletions

View File

@ -327,8 +327,12 @@ def on_tick(store: Store, time: uint64) -> None:
# Not a new epoch, return # Not a new epoch, return
if not (current_slot > previous_slot and compute_slots_since_epoch_start(current_slot) == 0): if not (current_slot > previous_slot and compute_slots_since_epoch_start(current_slot) == 0):
return return
# Update store.justified_checkpoint if a better checkpoint is known
# Update store.justified_checkpoint if a better checkpoint on the store.finalized_checkpoint chain
if store.best_justified_checkpoint.epoch > store.justified_checkpoint.epoch: if store.best_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
ancestor_at_finalized_slot = get_ancestor(store, store.best_justified_checkpoint.root, finalized_slot)
if ancestor_at_finalized_slot == store.finalized_checkpoint.root:
store.justified_checkpoint = store.best_justified_checkpoint store.justified_checkpoint = store.best_justified_checkpoint
``` ```