From aa8caee2e39bd618bc5baf7c35f978cc204657c1 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 8 Jul 2022 21:59:09 -0700 Subject: [PATCH] Add `compute_sync_committee_period_at_slot` --- specs/altair/sync-protocol.md | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/specs/altair/sync-protocol.md b/specs/altair/sync-protocol.md index 6f6e728e4..44fe978f8 100644 --- a/specs/altair/sync-protocol.md +++ b/specs/altair/sync-protocol.md @@ -21,6 +21,7 @@ - [`is_better_update`](#is_better_update) - [`get_safety_threshold`](#get_safety_threshold) - [`get_subtree_index`](#get_subtree_index) + - [`compute_sync_committee_period_at_slot`](#compute_sync_committee_period_at_slot) - [Light client state updates](#light-client-state-updates) - [`process_slot_for_light_client_store`](#process_slot_for_light_client_store) - [`validate_light_client_update`](#validate_light_client_update) @@ -135,12 +136,12 @@ def is_better_update(new_update: LightClientUpdate, old_update: LightClientUpdat # Compare sync committee finality if new_has_finality: new_has_sync_committee_finality = ( - compute_sync_committee_period(compute_epoch_at_slot(new_update.finalized_header.slot)) == - compute_sync_committee_period(compute_epoch_at_slot(new_update.attested_header.slot)) + compute_sync_committee_period_at_slot(new_update.finalized_header.slot) == + compute_sync_committee_period_at_slot(new_update.attested_header.slot) ) old_has_sync_committee_finality = ( - compute_sync_committee_period(compute_epoch_at_slot(old_update.finalized_header.slot)) == - compute_sync_committee_period(compute_epoch_at_slot(old_update.attested_header.slot)) + compute_sync_committee_period_at_slot(old_update.finalized_header.slot) == + compute_sync_committee_period_at_slot(old_update.attested_header.slot) ) if new_has_sync_committee_finality != old_has_sync_committee_finality: return new_has_sync_committee_finality > old_has_sync_committee_finality @@ -172,6 +173,13 @@ def get_subtree_index(generalized_index: GeneralizedIndex) -> uint64: return uint64(generalized_index % 2**(floorlog2(generalized_index))) ``` +### `compute_sync_committee_period_at_slot` + +```python +def compute_sync_committee_period_at_slot(slot: Slot) -> uint64: + return compute_sync_committee_period(compute_epoch_at_slot(slot)) +``` + ## Light client state updates A light client maintains its state in a `store` object of type `LightClientStore` and receives `update` objects of type `LightClientUpdate`. Every `update` triggers `process_light_client_update(store, update, current_slot, genesis_validators_root)` where `current_slot` is the current slot based on a local clock. `process_slot_for_light_client_store` is triggered every time the current slot increments. @@ -207,12 +215,12 @@ def validate_light_client_update(store: LightClientStore, # Verify update does not skip a sync committee period assert current_slot >= update.signature_slot > update.attested_header.slot >= update.finalized_header.slot - store_period = compute_sync_committee_period(compute_epoch_at_slot(store.finalized_header.slot)) - signature_period = compute_sync_committee_period(compute_epoch_at_slot(update.signature_slot)) + store_period = compute_sync_committee_period_at_slot(store.finalized_header.slot) + signature_period = compute_sync_committee_period_at_slot(update.signature_slot) assert signature_period in (store_period, store_period + 1) # Verify update is relevant - attested_period = compute_sync_committee_period(compute_epoch_at_slot(update.attested_header.slot)) + attested_period = compute_sync_committee_period_at_slot(update.attested_header.slot) assert update.attested_header.slot > store.finalized_header.slot # Verify that the `finality_branch`, if present, confirms `finalized_header` @@ -269,8 +277,8 @@ def validate_light_client_update(store: LightClientStore, ```python def apply_light_client_update(store: LightClientStore, update: LightClientUpdate) -> None: - store_period = compute_sync_committee_period(compute_epoch_at_slot(store.finalized_header.slot)) - finalized_period = compute_sync_committee_period(compute_epoch_at_slot(update.finalized_header.slot)) + store_period = compute_sync_committee_period_at_slot(store.finalized_header.slot) + finalized_period = compute_sync_committee_period_at_slot(update.finalized_header.slot) if finalized_period == store_period + 1: store.current_sync_committee = store.next_sync_committee store.next_sync_committee = update.next_sync_committee