don't consider blocks with slots earlier than finalized in on_block fork choice (optimization)

This commit is contained in:
Danny Ryan 2020-01-20 18:10:39 -07:00
parent f1697d03e7
commit e98c1b4154
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 5 additions and 1 deletions

View File

@ -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