示例#1
0
def test_get_aggregate_from_valid_committee_attestations(
        sample_attestation_params, privkeys, genesis_state, config):
    committee_size = 16
    empty_bitfield = get_empty_bitfield(committee_size)
    base_attestation = Attestation.create(**sample_attestation_params)
    attestations = []
    expected_bitfield = empty_bitfield

    for i in range(4, 16, 2):
        attestations.append(
            base_attestation.mset(
                "aggregation_bits",
                set_voted(empty_bitfield, i),
                "signature",
                sign_transaction(
                    object=base_attestation.data,
                    privkey=privkeys[i],
                    state=genesis_state,
                    slot=genesis_state.slot,
                    signature_domain=SignatureDomain.DOMAIN_BEACON_ATTESTER,
                    slots_per_epoch=config.SLOTS_PER_EPOCH,
                ),
            ))
        expected_bitfield = set_voted(expected_bitfield, i)

    aggregate_attestation = get_aggregate_from_valid_committee_attestations(
        attestations)

    assert aggregate_attestation.aggregation_bits == expected_bitfield
示例#2
0
 def _get_aggregates(self, slot: Slot, committee_index: CommitteeIndex,
                     config: Eth2Config) -> Iterable[Attestation]:
     """
     Return the aggregate attestation of the given committee.
     """
     # TODO: The aggregator should aggregate the late attestations?
     aggregatable_attestations = self.get_aggregatable_attestations(
         slot, committee_index)
     attestation_groups = groupby(aggregatable_attestations,
                                  key=lambda attestation: attestation.data)
     for _, group in attestation_groups:
         yield get_aggregate_from_valid_committee_attestations(tuple(group))