diff --git a/shared/attestationutil/attestation_utils.go b/shared/attestationutil/attestation_utils.go index 5f39f24ff..7caf9f0b6 100644 --- a/shared/attestationutil/attestation_utils.go +++ b/shared/attestationutil/attestation_utils.go @@ -67,7 +67,7 @@ func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, commi // 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 { - indices := make([]uint64, 0, len(committee)) + indices := make([]uint64, 0, bf.Count()) for _, idx := range bf.BitIndices() { if idx < len(committee) { indices = append(indices, committee[idx]) diff --git a/shared/attestationutil/attestation_utils_test.go b/shared/attestationutil/attestation_utils_test.go index de07ca61c..6ba75b14b 100644 --- a/shared/attestationutil/attestation_utils_test.go +++ b/shared/attestationutil/attestation_utils_test.go @@ -114,9 +114,10 @@ func TestIsValidAttestationIndices(t *testing.T) { } func BenchmarkAttestingIndices_PartialCommittee(b *testing.B) { - bf := bitfield.Bitlist{0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b100} + bf := bitfield.Bitlist{0b11111111, 0b11111111, 0b10000111, 0b11111111, 0b100} committee := []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34} + b.ResetTimer() for i := 0; i < b.N; i++ { _ = attestationutil.AttestingIndices(bf, committee) }