diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index a5d6d3a97d..fec80ad251 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -143,33 +143,6 @@ func ComputeCommittee( return shuffledList[start:end], err } -// AttestingIndices returns the attesting participants indices from the attestation data. The -// committee is provided as an argument rather than a direct implementation from the spec definition. -// Having the committee as an argument allows for re-use of beacon committees when possible. -// -// Spec pseudocode definition: -// def get_attesting_indices(state: BeaconState, -// data: AttestationData, -// bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE]) -> Set[ValidatorIndex]: -// """ -// Return the set of attesting indices corresponding to ``data`` and ``bits``. -// """ -// committee = get_beacon_committee(state, data.slot, data.index) -// return set(index for i, index in enumerate(committee) if bits[i]) -func AttestingIndices(bf bitfield.Bitfield, committee []uint64) ([]uint64, error) { - indices := make([]uint64, 0, len(committee)) - indicesSet := make(map[uint64]bool, len(committee)) - for i, idx := range committee { - if !indicesSet[idx] { - if bf.BitAt(uint64(i)) { - indices = append(indices, idx) - } - } - indicesSet[idx] = true - } - return indices, nil -} - // CommitteeAssignmentContainer represents a committee, index, and attester slot for a given epoch. type CommitteeAssignmentContainer struct { Committee []uint64 diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index d7c687ee64..22c8d86133 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -85,101 +85,6 @@ func TestComputeCommittee_WithoutCache(t *testing.T) { } } -func TestAttestationParticipants_NoCommitteeCache(t *testing.T) { - committeeSize := uint64(16) - validators := make([]*ethpb.Validator, committeeSize*params.BeaconConfig().SlotsPerEpoch) - for i := 0; i < len(validators); i++ { - validators[i] = ðpb.Validator{ - ExitEpoch: params.BeaconConfig().FarFutureEpoch, - } - } - - state, err := beaconstate.InitializeFromProto(&pb.BeaconState{ - Slot: params.BeaconConfig().SlotsPerEpoch, - Validators: validators, - RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), - }) - if err != nil { - t.Fatal(err) - } - - attestationData := ðpb.AttestationData{} - - tests := []struct { - attestationSlot uint64 - bitfield bitfield.Bitlist - wanted []uint64 - }{ - { - attestationSlot: 3, - bitfield: bitfield.Bitlist{0x07}, - wanted: []uint64{344, 221}, - }, - { - attestationSlot: 2, - bitfield: bitfield.Bitlist{0x05}, - wanted: []uint64{207}, - }, - { - attestationSlot: 11, - bitfield: bitfield.Bitlist{0x07}, - wanted: []uint64{409, 213}, - }, - } - - for _, tt := range tests { - attestationData.Target = ðpb.Checkpoint{Epoch: 0} - attestationData.Slot = tt.attestationSlot - - committee, err := BeaconCommitteeFromState(state, tt.attestationSlot, 0 /* committee index */) - if err != nil { - t.Error(err) - } - result, err := AttestingIndices(tt.bitfield, committee) - if err != nil { - t.Errorf("Failed to get attestation participants: %v", err) - } - - if !reflect.DeepEqual(tt.wanted, result) { - t.Errorf( - "Result indices was an unexpected value. Wanted %d, got %d", - tt.wanted, - result, - ) - } - } -} - -func TestAttestationParticipants_EmptyBitfield(t *testing.T) { - validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount) - for i := 0; i < len(validators); i++ { - validators[i] = ðpb.Validator{ - ExitEpoch: params.BeaconConfig().FarFutureEpoch, - } - } - - state, err := beaconstate.InitializeFromProto(&pb.BeaconState{ - Validators: validators, - RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), - }) - if err != nil { - t.Fatal(err) - } - attestationData := ðpb.AttestationData{Target: ðpb.Checkpoint{}} - - committee, err := BeaconCommitteeFromState(state, attestationData.Slot, attestationData.CommitteeIndex) - if err != nil { - t.Fatal(err) - } - indices, err := AttestingIndices(bitfield.NewBitlist(128), committee) - if err != nil { - t.Fatal(err) - } - if len(indices) != 0 { - t.Errorf("Attesting indices are non-zero despite an empty bitfield being provided; Size %d", len(indices)) - } -} - func TestVerifyBitfieldLength_OK(t *testing.T) { bf := bitfield.Bitlist{0xFF, 0x01} committeeSize := uint64(8)