Merge pull request #2844 from sigp/opt-import

Optimistically import any post-merge block
This commit is contained in:
Danny Ryan 2022-03-03 09:46:15 -07:00 committed by GitHub
commit 0b883a8692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,10 +81,17 @@ def is_execution_block(block: BeaconBlock) -> bool:
```python ```python
def is_optimistic_candidate_block(opt_store: OptimisticStore, current_slot: Slot, block: BeaconBlock) -> bool: def is_optimistic_candidate_block(opt_store: OptimisticStore, current_slot: Slot, block: BeaconBlock) -> bool:
if is_execution_block(opt_store.blocks[block.parent_root]):
return True
justified_root = opt_store.block_states[opt_store.head_block_root].current_justified_checkpoint.root justified_root = opt_store.block_states[opt_store.head_block_root].current_justified_checkpoint.root
justified_is_execution_block = is_execution_block(opt_store.blocks[justified_root]) if is_execution_block(opt_store.blocks[justified_root]):
block_is_deep = block.slot + SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY <= current_slot return True
return justified_is_execution_block or block_is_deep
if block.slot + SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY <= current_slot:
return True
return False
``` ```
Let only a node which returns `is_optimistic(opt_store, head) is True` be an *optimistic Let only a node which returns `is_optimistic(opt_store, head) is True` be an *optimistic
@ -99,14 +106,21 @@ behaviours without regard for optimistic sync.
### When to optimistically import blocks ### When to optimistically import blocks
A block MAY be optimistically imported when A block MAY be optimistically imported when
`is_optimistic_candidate_block(opt_store, current_slot, block)` returns `is_optimistic_candidate_block(opt_store, current_slot, block)` returns `True`.
`True`. This ensures that blocks are only optimistically imported if either: This ensures that blocks are only optimistically imported if one or more of the
following are true:
1. The parent of the block has execution enabled.
1. The justified checkpoint has execution enabled. 1. The justified checkpoint has execution enabled.
1. The current slot (as per the system clock) is at least 1. The current slot (as per the system clock) is at least
`SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` ahead of the slot of the block being `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` ahead of the slot of the block being
imported. imported.
In effect, there are restrictions on when a *merge block* can be optimistically
imported. The merge block is the first block in any chain where
`is_execution_block(block) == True`. Any descendant of a merge block may be
imported optimistically at any time.
*See [Fork Choice Poisoning](#fork-choice-poisoning) for the motivations behind *See [Fork Choice Poisoning](#fork-choice-poisoning) for the motivations behind
these conditions.* these conditions.*