From c2ff09441d4cfdac5b9bccb28291c9bc304af921 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 1 Mar 2022 18:34:53 +1100 Subject: [PATCH 1/3] Allow any non-merge block --- sync/optimistic.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sync/optimistic.md b/sync/optimistic.md index 8e6acc442..4f6637cbc 100644 --- a/sync/optimistic.md +++ b/sync/optimistic.md @@ -81,10 +81,17 @@ def is_execution_block(block: BeaconBlock) -> bool: ```python 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_is_execution_block = is_execution_block(opt_store.blocks[justified_root]) - block_is_deep = block.slot + SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY <= current_slot - return justified_is_execution_block or block_is_deep + if is_execution_block(opt_store.blocks[justified_root]): + return True + + 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 @@ -99,14 +106,21 @@ behaviours without regard for optimistic sync. ### When to optimistically import blocks A block MAY be optimistically imported when -`is_optimistic_candidate_block(opt_store, current_slot, block)` returns -`True`. This ensures that blocks are only optimistically imported if either: +`is_optimistic_candidate_block(opt_store, current_slot, block)` returns `True`. +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 current slot (as per the system clock) is at least `SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY` ahead of the slot of the block being 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 transition block may +be imported optimistically at any time. + *See [Fork Choice Poisoning](#fork-choice-poisoning) for the motivations behind these conditions.* From f071931e46f30de86721fe18298746d7d814bd52 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 1 Mar 2022 18:46:39 +1100 Subject: [PATCH 2/3] Address indenting --- sync/optimistic.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sync/optimistic.md b/sync/optimistic.md index 4f6637cbc..8b3c1a730 100644 --- a/sync/optimistic.md +++ b/sync/optimistic.md @@ -81,17 +81,17 @@ def is_execution_block(block: BeaconBlock) -> bool: ```python 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 + 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 if is_execution_block(opt_store.blocks[justified_root]): - return True + return True - if block.slot + SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY <= current_slot: - return True + if block.slot + SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY <= current_slot: + return True - return False + return False ``` Let only a node which returns `is_optimistic(opt_store, head) is True` be an *optimistic From bf25d323fc77535f7a168452756257b92b78a54e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 2 Mar 2022 19:03:06 +1100 Subject: [PATCH 3/3] Use merge consistently --- sync/optimistic.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sync/optimistic.md b/sync/optimistic.md index 8b3c1a730..3237c3f65 100644 --- a/sync/optimistic.md +++ b/sync/optimistic.md @@ -118,8 +118,8 @@ following are true: 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 transition block may -be imported optimistically at any time. +`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 these conditions.*