Skip to content

Commit e9fd199

Browse files
tcoratgerclaude
andauthored
refactor(block-production): rename phase-2 locals in build_block (#1135)
The block-building loop reused the phase-1 selection accumulators aggregated_attestations / aggregated_signatures for the phase-2 collapsed-per-data outputs by rebinding them to empty lists mid-method. Reusing one name for two semantically different values in a single scope is a misreading hazard and violates the descriptive-naming rule. Give the collapsed outputs distinct names merged_attestations / merged_signatures, initialized at the method level so the no-payloads path still builds an empty block. The phase-1 accumulators now live inside the payloads branch where they are used. Behavior is identical. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7700513 commit e9fd199

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/lean_spec/spec/forks/lstar/block_production.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,19 @@ def build_block(
7676
The final block, its post-state, the included attestations,
7777
and the merged proof backing each one.
7878
"""
79-
aggregated_attestations: list[AggregatedAttestation] = []
80-
aggregated_signatures: list[SingleMessageAggregate] = []
79+
# Collapsed per-data output: one attestation and one merged proof per data.
80+
# Empty when there are no payloads, so the block carries no attestations.
81+
merged_attestations: list[AggregatedAttestation] = []
82+
merged_signatures: list[SingleMessageAggregate] = []
8183

8284
# Advance the pre-state to this block's slot once.
8385
advanced_state = self.process_slots(state, slot)
8486

8587
if aggregated_payloads:
88+
# Per-pass selection: may emit several proofs per data before collapsing.
89+
aggregated_attestations: list[AggregatedAttestation] = []
90+
aggregated_signatures: list[SingleMessageAggregate] = []
91+
8692
# Anchor on the checkpoint this chain treats as justified.
8793
#
8894
# On genesis the parent is justified at slot 0 by header processing.
@@ -243,9 +249,7 @@ def build_block(
243249
):
244250
signatures_by_attestation_data[attestation.data].append(signature)
245251

246-
# Rebuild the output lists, one entry per distinct data.
247-
aggregated_attestations = []
248-
aggregated_signatures = []
252+
# Build the collapsed output lists, one entry per distinct data.
249253
for attestation_data, grouped_signatures in signatures_by_attestation_data.items():
250254
if len(grouped_signatures) == 1:
251255
# One proof already covers this data, so use it as-is.
@@ -273,8 +277,8 @@ def build_block(
273277
slot=attestation_data.slot,
274278
)
275279

276-
aggregated_signatures.append(signature)
277-
aggregated_attestations.append(
280+
merged_signatures.append(signature)
281+
merged_attestations.append(
278282
self.aggregated_attestation_class(
279283
aggregation_bits=signature.participants, data=attestation_data
280284
)
@@ -287,7 +291,7 @@ def build_block(
287291
parent_root=parent_root,
288292
state_root=Bytes32.zero(),
289293
body=self.block_body_class(
290-
attestations=self.aggregated_attestations_class(data=aggregated_attestations),
294+
attestations=self.aggregated_attestations_class(data=merged_attestations),
291295
),
292296
)
293297

@@ -298,4 +302,4 @@ def build_block(
298302
post_state = self.process_block(advanced_state, final_block)
299303
final_block = final_block.model_copy(update={"state_root": hash_tree_root(post_state)})
300304

301-
return final_block, post_state, aggregated_attestations, aggregated_signatures
305+
return final_block, post_state, merged_attestations, merged_signatures

0 commit comments

Comments
 (0)