コード例 #1
0
def get_attestation_participants(state: 'BeaconState',
                                 slot: int,
                                 shard: int,
                                 participation_bitfield: bytes,
                                 epoch_length: int) -> Iterable[int]:
    """
    Return the participants' indices at the ``slot`` of shard ``shard``
    from ``participation_bitfield``.
    """
    # Find the relevant committee
    # Filter by slot
    shard_committees_at_slot = get_shard_committees_at_slot(
        state,
        slot,
        epoch_length,
    )
    # Filter by shard
    shard_committees = tuple(
        [
            shard_committee
            for shard_committee in shard_committees_at_slot
            if shard_committee.shard == shard
        ]
    )

    try:
        shard_committee = shard_committees[0]
    except IndexError:
        raise ValidationError("shard_committees should not be empty.")

    if len(participation_bitfield) != get_bitfield_length(len(shard_committee.committee)):
        raise ValidationError(
            'Invalid bitfield length,'
            "\texpected: %s, found: %s" % (
                get_bitfield_length(len(shard_committee.committee)),
                len(participation_bitfield),
            )
        )

    # Find the participating attesters in the committee
    for bitfield_index, validator_index in enumerate(shard_committee.committee):
        if has_voted(participation_bitfield, bitfield_index):
            yield validator_index
コード例 #2
0
ファイル: test_bitfields.py プロジェクト: stringray55/py-evm
def test_bitfield_length(attester_count, bitfield_length):
    assert get_bitfield_length(attester_count) == bitfield_length