Delete unused helpers.AttestingIndices (#6509)

* Delete unused helpers.AttestingIndices
* Merge branch 'master' into rm-AttestingIndices
* Merge branch 'master' into rm-AttestingIndices
* Merge branch 'master' into rm-AttestingIndices
* Merge branch 'master' into rm-AttestingIndices
This commit is contained in:
Preston Van Loon
2020-07-08 00:30:29 -07:00
committed by GitHub
parent a02553815f
commit c1ccadae55
2 changed files with 0 additions and 122 deletions

View File

@@ -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

View File

@@ -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] = &ethpb.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 := &ethpb.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 = &ethpb.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] = &ethpb.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 := &ethpb.AttestationData{Target: &ethpb.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)