From 5e717a456d3046433a4add9f40f38bef9a303342 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 17 Nov 2020 15:30:09 +0000 Subject: [PATCH] More polish and fixes --- specs/lightclient/sync-protocol.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/specs/lightclient/sync-protocol.md b/specs/lightclient/sync-protocol.md index 6977d5862..99f25d875 100644 --- a/specs/lightclient/sync-protocol.md +++ b/specs/lightclient/sync-protocol.md @@ -43,6 +43,7 @@ This document suggests a minimal light client design for the beacon chain that u | Name | Value | | - | - | +| `MIN_SYNC_COMMITTEE_PARTICIPANTS` | `1` | | `MAX_VALID_LIGHT_CLIENT_UPDATES` | `uint64(2**64 - 1)` | ### Time parameters @@ -75,7 +76,7 @@ class LightClientUpdate(Container): # Sync committee aggregate signature sync_committee_bits: Bitlist[MAX_SYNC_COMMITTEE_SIZE] sync_committee_signature: BLSSignature - # Fork version corresponding to the aggregate signature + # Fork version for the aggregate signature fork_version ``` @@ -122,6 +123,7 @@ def is_valid_light_client_update(store: LightClientStore, update: LightClientUpd # Verify sync committee bitfield length sync_committee = new_snapshot.current_sync_committee assert len(update.sync_committee_bits) == len(sync_committee) + assert sum(update.sync_committee_bits) > MIN_SYNC_COMMITTEE_PARTICIPANTS # Verify sync committee aggregate signature participant_pubkeys = [pubkey for (bit, pubkey) in zip(update.sync_committee_bits, sync_committee.pubkeys) if bit] @@ -136,15 +138,16 @@ def is_valid_light_client_update(store: LightClientStore, update: LightClientUpd ```python def process_light_client_update(store: LightClientStore, update: LightClientUpdate, current_slot: Slot) -> None: + # Validate update assert is_valid_light_client_update(store, update) + valid_updates.append(update) + if sum(update.sync_committee_bits) * 3 > len(update.sync_committee_bits) * 2: + # Immediate update when quorum is reached store.snapshot = update.snapshot valid_updates = [] - else: - valid_updates.append(update) - - # Force an update after the update timeout has elapsed - if current_slot > old_snapshot.header.slot + LIGHT_CLIENT_UPDATE_TIMEOUT: - best_update = max(valid_updates, key=lambda update: sum(update.sync_committee_bits)) - store.snapshot = best_update.new_snapshot + elif current_slot > old_snapshot.header.slot + LIGHT_CLIENT_UPDATE_TIMEOUT: + # Forced best update when the update timeout has elapsed + store.snapshot = max(valid_updates, key=lambda update: sum(update.sync_committee_bits)).new_snapshot + valid_updates = [] ```