Skip to content

Commit

Permalink
Merge pull request #1880 from paulhauner/patch-24
Browse files Browse the repository at this point in the history
Fork choice: avoid redundant call to get_ancestor
  • Loading branch information
djrtwo authored Jun 11, 2020
2 parents c3a69bf + 1dc6b55 commit 67c9c06
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions specs/phase0/fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,19 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
# Update finalized checkpoint
if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch:
store.finalized_checkpoint = state.finalized_checkpoint
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)

# Update justified if new justified is later than store justified
# or if store justified is not in chain with finalized checkpoint
if (
state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch
or get_ancestor(store, store.justified_checkpoint.root, finalized_slot) != store.finalized_checkpoint.root
):
store.justified_checkpoint = state.current_justified_checkpoint

# Potentially update justified if different from store
if store.justified_checkpoint != state.current_justified_checkpoint:
# Update justified if new justified is later than store justified
if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = state.current_justified_checkpoint
return

# Update justified if store justified is not in chain with finalized checkpoint
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot)
if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
store.justified_checkpoint = state.current_justified_checkpoint
```

#### `on_attestation`
Expand Down

0 comments on commit 67c9c06

Please sign in to comment.