Skip to content

Commit af9b5d9

Browse files
committed
Use validator guide compute_on_chain_aggregate in testing
1 parent 947767f commit af9b5d9

File tree

1 file changed

+2
-57
lines changed

1 file changed

+2
-57
lines changed

tests/core/pyspec/eth2spec/test/helpers/attestations.py

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -225,51 +225,6 @@ def participants_filter(comm):
225225
)
226226

227227

228-
def _get_aggregate_committee_indices(spec, attestations):
229-
"""
230-
Aggregate all unique committee indices from the given attestations.
231-
"""
232-
all_committee_indices = set()
233-
for attestation in attestations:
234-
committee_indices = spec.get_committee_indices(attestation.committee_bits)
235-
assert len(committee_indices) == 1
236-
all_committee_indices.add(committee_indices[0])
237-
238-
return all_committee_indices
239-
240-
241-
def _aggregate_aggregation_bits_and_signatures(spec, state, slot, aggregate, attestations):
242-
"""
243-
Aggregate the aggregation bits and signatures from the attestations,
244-
incorporating the calculation of aggregation bits offset directly.
245-
"""
246-
# initialize aggregation bits for the aggregate attestation
247-
aggregate.aggregation_bits = get_empty_eip7549_aggregation_bits(
248-
spec, state, aggregate.committee_bits, slot)
249-
250-
signatures = []
251-
252-
offset = 0
253-
attestations = sorted(attestations, key=lambda att: spec.get_committee_indices(att.committee_bits)[0])
254-
for attestation in attestations:
255-
# retrieve the single committee index for the attestation.
256-
committee_index = spec.get_committee_indices(attestation.committee_bits)[0]
257-
258-
# update the aggregate's aggregation bits based on each attestation.
259-
for i, bit in enumerate(attestation.aggregation_bits):
260-
aggregate.aggregation_bits[offset + i] = bit
261-
262-
# collect signatures for aggregation.
263-
signatures.append(attestation.signature)
264-
265-
# update offset
266-
committee = spec.get_beacon_committee(state, slot, committee_index)
267-
offset += len(committee)
268-
269-
# aggregate signatures from all attestations.
270-
aggregate.signature = bls.Aggregate(signatures)
271-
272-
273228
def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None):
274229
"""
275230
Return the aggregate attestation post Electra.
@@ -282,19 +237,9 @@ def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=
282237
beacon_block_root=beacon_block_root,
283238
))
284239
if not attestations:
285-
return None
286-
287-
# initialize the aggregate attestation.
288-
aggregate = spec.Attestation(data=attestations[0].data)
289-
290-
# fill in committee_bits
291-
all_committee_indices = _get_aggregate_committee_indices(spec, attestations)
292-
for committee_index in all_committee_indices:
293-
aggregate.committee_bits[committee_index] = True
294-
295-
_aggregate_aggregation_bits_and_signatures(spec, state, slot_to_attest, aggregate, attestations)
240+
raise Exception("No valid attestations found")
296241

297-
return aggregate
242+
return spec.compute_on_chain_aggregate(attestations)
298243

299244

300245
def next_slots_with_attestations(spec,

0 commit comments

Comments
 (0)