Skip to content

refactor(fork-choice): enumerate payload key union without copying values - #1137

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit-forks/keys-union-merge
Jun 17, 2026
Merged

refactor(fork-choice): enumerate payload key union without copying values#1137
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit-forks/keys-union-merge

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

What

When promoting pending aggregate proofs into the counted pool, the dict comprehension iterated {**known_payloads, **new_payloads} purely to enumerate the union of attestation-data keys. Building that merged dict copies every set value only to discard it (the comprehension re-fetches via .get()). This replaces it with dict.fromkeys((*known_payloads, *new_payloads)), which enumerates the same keys without copying any values.

Why this is behavior- and order-preserving

dict.fromkeys((*known_payloads, *new_payloads)) yields keys in exactly the same order the merged-dict spread did: all counted-pool keys in insertion order, then pending-pool keys not already present, in their insertion order. The resulting merged_aggregated_payloads therefore has identical key insertion order.

This matters because of the LMD determinism invariant: equal-slot fork-choice ties resolve by first-seen insertion order. A set-union (known_payloads.keys() | new_payloads.keys()) was deliberately avoided here because set iteration order is hash-seeded and would not preserve that order.

just check passes (lint, format, type check, codespell, mdformat, lock).

🤖 Generated with Claude Code

…lues

Promoting pending aggregate proofs iterated a throwaway merged dict
built only to walk its keys, copying every set value just to discard it.
Enumerate the key union directly with an order-preserving construction.

The new enumeration yields keys in exactly the same order as the old
merged dict: all counted-pool keys in insertion order, then pending-pool
keys not already present, in their insertion order. This preserves the
LMD determinism invariant, where equal-slot ties resolve by first-seen
insertion order. A set union would not preserve that order.

just check passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger
tcoratger merged commit e82a104 into leanEthereum:main Jun 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant