Skip to content

Commit 135febc

Browse files
authored
Bump is_better_update to match latest spec (#6914)
Add `signature_slot` comparison to `is_better_update` LC data comparator for robustness in edge cases, and sync style with latest specs. - ethereum/consensus-specs#4124
1 parent 5e5b9ba commit 135febc

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Diff for: beacon_chain/spec/helpers.nim

+14-10
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func get_safety_threshold*(store: ForkyLightClientStore): uint64 =
279279
store.current_max_active_participants
280280
) div 2
281281

282-
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/altair/light-client/sync-protocol.md#is_better_update
282+
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.3/specs/altair/light-client/sync-protocol.md#is_better_update
283283
type LightClientUpdateMetadata* = object
284284
attested_slot*, finalized_slot*, signature_slot*: Slot
285285
has_sync_committee*, has_finality*: bool
@@ -326,10 +326,10 @@ func is_better_data*(new_meta, old_meta: LightClientUpdateMetadata): bool =
326326
old_has_supermajority =
327327
hasSupermajoritySyncParticipation(old_meta.num_active_participants)
328328
if new_has_supermajority != old_has_supermajority:
329-
return new_has_supermajority > old_has_supermajority
330-
if not new_has_supermajority:
331-
if new_meta.num_active_participants != old_meta.num_active_participants:
332-
return new_meta.num_active_participants > old_meta.num_active_participants
329+
return new_has_supermajority
330+
if not new_has_supermajority and
331+
new_meta.num_active_participants != old_meta.num_active_participants:
332+
return new_meta.num_active_participants > old_meta.num_active_participants
333333

334334
# Compare presence of relevant sync committee
335335
let
@@ -340,11 +340,11 @@ func is_better_data*(new_meta, old_meta: LightClientUpdateMetadata): bool =
340340
old_meta.attested_slot.sync_committee_period ==
341341
old_meta.signature_slot.sync_committee_period
342342
if new_has_relevant_sync_committee != old_has_relevant_sync_committee:
343-
return new_has_relevant_sync_committee > old_has_relevant_sync_committee
343+
return new_has_relevant_sync_committee
344344

345345
# Compare indication of any finality
346346
if new_meta.has_finality != old_meta.has_finality:
347-
return new_meta.has_finality > old_meta.has_finality
347+
return new_meta.has_finality
348348

349349
# Compare sync committee finality
350350
if new_meta.has_finality:
@@ -356,14 +356,18 @@ func is_better_data*(new_meta, old_meta: LightClientUpdateMetadata): bool =
356356
old_meta.finalized_slot.sync_committee_period ==
357357
old_meta.attested_slot.sync_committee_period
358358
if new_has_sync_committee_finality != old_has_sync_committee_finality:
359-
return new_has_sync_committee_finality > old_has_sync_committee_finality
359+
return new_has_sync_committee_finality
360360

361361
# Tiebreaker 1: Sync committee participation beyond supermajority
362362
if new_meta.num_active_participants != old_meta.num_active_participants:
363363
return new_meta.num_active_participants > old_meta.num_active_participants
364364

365-
# Tiebreaker 2: Prefer older data (fewer changes to best data)
366-
new_meta.attested_slot < old_meta.attested_slot
365+
# Tiebreaker 2: Prefer older data (fewer changes to best)
366+
if new_meta.attested_slot != old_meta.attested_slot:
367+
return new_meta.attested_slot < old_meta.attested_slot
368+
369+
# Tiebreaker 3: Prefer updates with earlier signature slots
370+
new_meta.signature_slot < old_meta.signature_slot
367371

368372
template is_better_update*[
369373
A, B: SomeForkyLightClientUpdate | ForkedLightClientUpdate](

0 commit comments

Comments
 (0)