From e98c1b415445e239c98e3382ed4ba475ee5e3c84 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 20 Jan 2020 18:10:39 -0700 Subject: [PATCH] don't consider blocks with slots earlier than finalized in on_block fork choice (optimization) --- specs/phase0/fork-choice.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index 64d48d4b5..39d9bd402 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -279,9 +279,13 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: assert get_current_slot(store) >= block.slot # Add new block to the store store.blocks[hash_tree_root(block)] = block - # Check block is a descendant of the finalized block + + # Check that block is later than the finalized epoch slot (optimization to reduce calls to get_ancestor) finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + assert block.slot > finalized_slot + # Check block is a descendant of the finalized block assert get_ancestor(store, hash_tree_root(block), finalized_slot) == store.finalized_checkpoint.root + # Check the block is valid and compute the post-state state = state_transition(pre_state, signed_block, True) # Add new state for this block to the store