From dc1bec79edfffb54a8f10fac4cc9404b14f31462 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 18 Feb 2021 12:11:20 -0800 Subject: [PATCH] Use Eth2 type CommitteeIndex (#8477) * Use types.CommitteeIndex * Go fmt * Update validator pkg * Fix e2e * Happy fuzz tests * Sync with upstream ethereumapi * Go mod tidy Co-authored-by: Raul Jordan --- beacon-chain/cache/committee.go | 4 ++-- beacon-chain/cache/committee_disabled.go | 2 +- beacon-chain/cache/committee_test.go | 7 ++++--- beacon-chain/core/blocks/attestation.go | 2 +- beacon-chain/core/helpers/attestation.go | 4 ++-- beacon-chain/core/helpers/committee.go | 12 ++++++------ beacon-chain/core/helpers/committee_test.go | 4 ++-- beacon-chain/core/state/transition_test.go | 2 +- .../operations/attestations/kv/aggregated.go | 4 ++-- .../operations/attestations/kv/aggregated_test.go | 2 +- .../operations/attestations/kv/unaggregated.go | 2 +- beacon-chain/operations/attestations/pool.go | 6 +++--- beacon-chain/rpc/beacon/attestations_test.go | 6 +++--- beacon-chain/rpc/beacon/committees.go | 2 +- beacon-chain/rpc/beaconv1/blocks_test.go | 4 ++-- beacon-chain/rpc/validator/attester.go | 2 +- beacon-chain/rpc/validator/proposer_test.go | 4 ++-- beacon-chain/state/stateutil/attestations.go | 4 ++-- beacon-chain/sync/validate_beacon_attestation.go | 10 +++++----- deps.bzl | 4 ++-- endtoend/evaluators/slashing.go | 3 ++- go.mod | 2 +- go.sum | 4 ++-- shared/testutil/attestation.go | 2 +- shared/testutil/block.go | 2 +- validator/client/validator.go | 8 ++++---- 26 files changed, 55 insertions(+), 53 deletions(-) diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 03230ca83d..25f5a1f9f8 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -56,7 +56,7 @@ func NewCommitteesCache() *CommitteeCache { // Committee fetches the shuffled indices by slot and committee index. Every list of indices // represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil. -func (c *CommitteeCache) Committee(slot types.Slot, seed [32]byte, index uint64) ([]uint64, error) { +func (c *CommitteeCache) Committee(slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]uint64, error) { c.lock.RLock() defer c.lock.RUnlock() @@ -82,7 +82,7 @@ func (c *CommitteeCache) Committee(slot types.Slot, seed [32]byte, index uint64) committeeCountPerSlot = item.CommitteeCount / uint64(params.BeaconConfig().SlotsPerEpoch) } - indexOffSet := index + uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeeCountPerSlot)) + indexOffSet := uint64(index) + uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeeCountPerSlot)) start, end := startEndIndices(item, indexOffSet) if end > uint64(len(item.ShuffledIndices)) || end < start { diff --git a/beacon-chain/cache/committee_disabled.go b/beacon-chain/cache/committee_disabled.go index 6e8cf75fe3..ce842fa3aa 100644 --- a/beacon-chain/cache/committee_disabled.go +++ b/beacon-chain/cache/committee_disabled.go @@ -16,7 +16,7 @@ func NewCommitteesCache() *FakeCommitteeCache { // Committee fetches the shuffled indices by slot and committee index. Every list of indices // represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil. -func (c *FakeCommitteeCache) Committee(slot types.Slot, seed [32]byte, index uint64) ([]uint64, error) { +func (c *FakeCommitteeCache) Committee(slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]uint64, error) { return nil, nil } diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index bc7fb2fdcc..8b3e9478ac 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -6,6 +6,7 @@ import ( "strconv" "testing" + types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" @@ -39,7 +40,7 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) { } slot := params.BeaconConfig().SlotsPerEpoch - committeeIndex := uint64(1) + committeeIndex := types.CommitteeIndex(1) indices, err := cache.Committee(slot, item.Seed, committeeIndex) require.NoError(t, err) if indices != nil { @@ -47,11 +48,11 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) { } require.NoError(t, cache.AddCommitteeShuffledList(item)) - wantedIndex := uint64(0) + wantedIndex := types.CommitteeIndex(0) indices, err = cache.Committee(slot, item.Seed, wantedIndex) require.NoError(t, err) - start, end := startEndIndices(item, wantedIndex) + start, end := startEndIndices(item, uint64(wantedIndex)) assert.DeepEqual(t, item.ShuffledIndices[start:end], indices) } diff --git a/beacon-chain/core/blocks/attestation.go b/beacon-chain/core/blocks/attestation.go index ce92c7df4f..980dea78dc 100644 --- a/beacon-chain/core/blocks/attestation.go +++ b/beacon-chain/core/blocks/attestation.go @@ -150,7 +150,7 @@ func ProcessAttestationNoVerifySignature( return nil, err } c := helpers.SlotCommitteeCount(activeValidatorCount) - if att.Data.CommitteeIndex >= c { + if uint64(att.Data.CommitteeIndex) >= c { return nil, fmt.Errorf("committee index %d >= committee count %d", att.Data.CommitteeIndex, c) } diff --git a/beacon-chain/core/helpers/attestation.go b/beacon-chain/core/helpers/attestation.go index aa9be97220..d59e22ce55 100644 --- a/beacon-chain/core/helpers/attestation.go +++ b/beacon-chain/core/helpers/attestation.go @@ -117,11 +117,11 @@ func ComputeSubnetForAttestation(activeValCount uint64, att *ethpb.Attestation) // slots_since_epoch_start = attestation.data.slot % SLOTS_PER_EPOCH // committees_since_epoch_start = get_committee_count_at_slot(state, attestation.data.slot) * slots_since_epoch_start // return (committees_since_epoch_start + attestation.data.index) % ATTESTATION_SUBNET_COUNT -func ComputeSubnetFromCommitteeAndSlot(activeValCount, comIdx uint64, attSlot types.Slot) uint64 { +func ComputeSubnetFromCommitteeAndSlot(activeValCount uint64, comIdx types.CommitteeIndex, attSlot types.Slot) uint64 { slotSinceStart := SlotsSinceEpochStarts(attSlot) comCount := SlotCommitteeCount(activeValCount) commsSinceStart := uint64(slotSinceStart.Mul(comCount)) - computedSubnet := (commsSinceStart + comIdx) % params.BeaconNetworkConfig().AttestationSubnetCount + computedSubnet := (commsSinceStart + uint64(comIdx)) % params.BeaconNetworkConfig().AttestationSubnetCount return computedSubnet } diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index 9b8ddc37a0..4e16b1e5ff 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -68,7 +68,7 @@ func SlotCommitteeCount(activeValidatorCount uint64) uint64 { // index=(slot % SLOTS_PER_EPOCH) * committees_per_slot + index, // count=committees_per_slot * SLOTS_PER_EPOCH, // ) -func BeaconCommitteeFromState(state *stateTrie.BeaconState, slot types.Slot, committeeIndex uint64) ([]uint64, error) { +func BeaconCommitteeFromState(state *stateTrie.BeaconState, slot types.Slot, committeeIndex types.CommitteeIndex) ([]uint64, error) { epoch := SlotToEpoch(slot) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) if err != nil { @@ -94,7 +94,7 @@ func BeaconCommitteeFromState(state *stateTrie.BeaconState, slot types.Slot, com // BeaconCommittee returns the crosslink committee of a given slot and committee index. The // validator indices and seed are provided as an argument rather than a imported implementation // from the spec definition. Having them as an argument allows for cheaper computation run time. -func BeaconCommittee(validatorIndices []uint64, seed [32]byte, slot types.Slot, committeeIndex uint64) ([]uint64, error) { +func BeaconCommittee(validatorIndices []uint64, seed [32]byte, slot types.Slot, committeeIndex types.CommitteeIndex) ([]uint64, error) { indices, err := committeeCache.Committee(slot, seed, committeeIndex) if err != nil { return nil, errors.Wrap(err, "could not interface with committee cache") @@ -105,7 +105,7 @@ func BeaconCommittee(validatorIndices []uint64, seed [32]byte, slot types.Slot, committeesPerSlot := SlotCommitteeCount(uint64(len(validatorIndices))) - epochOffset := committeeIndex + uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeesPerSlot)) + epochOffset := uint64(committeeIndex) + uint64(slot.ModSlot(params.BeaconConfig().SlotsPerEpoch).Mul(committeesPerSlot)) count := committeesPerSlot * uint64(params.BeaconConfig().SlotsPerEpoch) return ComputeCommittee(validatorIndices, seed, epochOffset, count) @@ -156,7 +156,7 @@ func ComputeCommittee( type CommitteeAssignmentContainer struct { Committee []uint64 AttesterSlot types.Slot - CommitteeIndex uint64 + CommitteeIndex types.CommitteeIndex } // CommitteeAssignments is a map of validator indices pointing to the appropriate committee @@ -218,14 +218,14 @@ func CommitteeAssignments( // Compute committees. for j := uint64(0); j < numCommitteesPerSlot; j++ { slot := startSlot + i - committee, err := BeaconCommitteeFromState(state, slot, j /*committee index*/) + committee, err := BeaconCommitteeFromState(state, slot, types.CommitteeIndex(j) /*committee index*/) if err != nil { return nil, nil, err } cac := &CommitteeAssignmentContainer{ Committee: committee, - CommitteeIndex: j, + CommitteeIndex: types.CommitteeIndex(j), AttesterSlot: slot, } for _, vID := range committee { diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index 2b6386e644..33bd814220 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -153,7 +153,7 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) { index uint64 slot types.Slot committee []uint64 - committeeIndex uint64 + committeeIndex types.CommitteeIndex isProposer bool proposerSlot types.Slot }{ @@ -419,7 +419,7 @@ func TestUpdateCommitteeCache_CanUpdate(t *testing.T) { require.NoError(t, UpdateCommitteeCache(state, CurrentEpoch(state))) epoch := types.Epoch(1) - idx := uint64(1) + idx := types.CommitteeIndex(1) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) require.NoError(t, err) diff --git a/beacon-chain/core/state/transition_test.go b/beacon-chain/core/state/transition_test.go index fcbef44d4f..3422d986db 100644 --- a/beacon-chain/core/state/transition_test.go +++ b/beacon-chain/core/state/transition_test.go @@ -669,7 +669,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) { // Precache the shuffled indices for i := uint64(0); i < committeeCount; i++ { - _, err := helpers.BeaconCommitteeFromState(s, 0, i) + _, err := helpers.BeaconCommitteeFromState(s, 0, types.CommitteeIndex(i)) require.NoError(b, err) } diff --git a/beacon-chain/operations/attestations/kv/aggregated.go b/beacon-chain/operations/attestations/kv/aggregated.go index 6229df025a..cb5c76d3b1 100644 --- a/beacon-chain/operations/attestations/kv/aggregated.go +++ b/beacon-chain/operations/attestations/kv/aggregated.go @@ -24,7 +24,7 @@ func (c *AttCaches) AggregateUnaggregatedAttestations() error { // AggregateUnaggregatedAttestationsBySlotIndex aggregates the unaggregated attestations and saves // newly aggregated attestations in the pool. Unaggregated attestations are filtered by slot and // committee index. -func (c *AttCaches) AggregateUnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) error { +func (c *AttCaches) AggregateUnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) error { unaggregatedAtts := c.UnaggregatedAttestationsBySlotIndex(slot, committeeIndex) return c.aggregateUnaggregatedAttestations(unaggregatedAtts) } @@ -154,7 +154,7 @@ func (c *AttCaches) AggregatedAttestations() []*ethpb.Attestation { // AggregatedAttestationsBySlotIndex returns the aggregated attestations in cache, // filtered by committee index and slot. -func (c *AttCaches) AggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) []*ethpb.Attestation { +func (c *AttCaches) AggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) []*ethpb.Attestation { atts := make([]*ethpb.Attestation, 0) c.aggregatedAttLock.RLock() diff --git a/beacon-chain/operations/attestations/kv/aggregated_test.go b/beacon-chain/operations/attestations/kv/aggregated_test.go index 3b3f9e3848..f8f480423b 100644 --- a/beacon-chain/operations/attestations/kv/aggregated_test.go +++ b/beacon-chain/operations/attestations/kv/aggregated_test.go @@ -39,7 +39,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) { func TestKV_Aggregated_AggregateUnaggregatedAttestationsBySlotIndex(t *testing.T) { cache := NewAttCaches() - genData := func(slot types.Slot, committeeIndex uint64) *ethpb.AttestationData { + genData := func(slot types.Slot, committeeIndex types.CommitteeIndex) *ethpb.AttestationData { return testutil.HydrateAttestationData(ðpb.AttestationData{ Slot: slot, CommitteeIndex: committeeIndex, diff --git a/beacon-chain/operations/attestations/kv/unaggregated.go b/beacon-chain/operations/attestations/kv/unaggregated.go index 30df07f572..4f87bc7d7a 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated.go +++ b/beacon-chain/operations/attestations/kv/unaggregated.go @@ -68,7 +68,7 @@ func (c *AttCaches) UnaggregatedAttestations() ([]*ethpb.Attestation, error) { // UnaggregatedAttestationsBySlotIndex returns the unaggregated attestations in cache, // filtered by committee index and slot. -func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) []*ethpb.Attestation { +func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) []*ethpb.Attestation { atts := make([]*ethpb.Attestation, 0) c.unAggregateAttLock.RLock() diff --git a/beacon-chain/operations/attestations/pool.go b/beacon-chain/operations/attestations/pool.go index b33aa88523..6f6e2e3ab6 100644 --- a/beacon-chain/operations/attestations/pool.go +++ b/beacon-chain/operations/attestations/pool.go @@ -13,11 +13,11 @@ import ( type Pool interface { // For Aggregated attestations AggregateUnaggregatedAttestations() error - AggregateUnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) error + AggregateUnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) error SaveAggregatedAttestation(att *ethpb.Attestation) error SaveAggregatedAttestations(atts []*ethpb.Attestation) error AggregatedAttestations() []*ethpb.Attestation - AggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) []*ethpb.Attestation + AggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) []*ethpb.Attestation DeleteAggregatedAttestation(att *ethpb.Attestation) error HasAggregatedAttestation(att *ethpb.Attestation) (bool, error) AggregatedAttestationCount() int @@ -25,7 +25,7 @@ type Pool interface { SaveUnaggregatedAttestation(att *ethpb.Attestation) error SaveUnaggregatedAttestations(atts []*ethpb.Attestation) error UnaggregatedAttestations() ([]*ethpb.Attestation, error) - UnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex uint64) []*ethpb.Attestation + UnaggregatedAttestationsBySlotIndex(slot types.Slot, committeeIndex types.CommitteeIndex) []*ethpb.Attestation DeleteUnaggregatedAttestation(att *ethpb.Attestation) error DeleteSeenUnaggregatedAttestations() (int, error) UnaggregatedAttestationCount() int diff --git a/beacon-chain/rpc/beacon/attestations_test.go b/beacon-chain/rpc/beacon/attestations_test.go index e17660b47c..079f10d497 100644 --- a/beacon-chain/rpc/beacon/attestations_test.go +++ b/beacon-chain/rpc/beacon/attestations_test.go @@ -258,7 +258,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) { count := params.BeaconConfig().SlotsPerEpoch * 4 atts := make([]*ethpb.Attestation, 0, count) for i := types.Slot(0); i < params.BeaconConfig().SlotsPerEpoch; i++ { - for s := uint64(0); s < 4; s++ { + for s := types.CommitteeIndex(0); s < 4; s++ { blockExample := testutil.NewBeaconBlock() blockExample.Block.Slot = i blockExample.Block.Body.Attestations = []*ethpb.Attestation{ @@ -871,14 +871,14 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) { comms := committees[i].Committees for j := 0; j < numValidators; j++ { var indexInCommittee uint64 - var committeeIndex uint64 + var committeeIndex types.CommitteeIndex var committeeLength int var found bool for comIndex, item := range comms { for n, idx := range item.ValidatorIndices { if uint64(j) == idx { indexInCommittee = uint64(n) - committeeIndex = uint64(comIndex) + committeeIndex = types.CommitteeIndex(comIndex) committeeLength = len(item.ValidatorIndices) found = true break diff --git a/beacon-chain/rpc/beacon/committees.go b/beacon-chain/rpc/beacon/committees.go index df2b171b6c..04d120ddb8 100644 --- a/beacon-chain/rpc/beacon/committees.go +++ b/beacon-chain/rpc/beacon/committees.go @@ -152,7 +152,7 @@ func computeCommittees( } committeeItems := make([]*ethpb.BeaconCommittees_CommitteeItem, countAtSlot) for committeeIndex := uint64(0); committeeIndex < countAtSlot; committeeIndex++ { - committee, err := helpers.BeaconCommittee(activeIndices, attesterSeed, slot, committeeIndex) + committee, err := helpers.BeaconCommittee(activeIndices, attesterSeed, slot, types.CommitteeIndex(committeeIndex)) if err != nil { return nil, status.Errorf( codes.Internal, diff --git a/beacon-chain/rpc/beaconv1/blocks_test.go b/beacon-chain/rpc/beaconv1/blocks_test.go index da007c484f..876ae731e0 100644 --- a/beacon-chain/rpc/beaconv1/blocks_test.go +++ b/beacon-chain/rpc/beaconv1/blocks_test.go @@ -40,10 +40,10 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) ( b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32) att1 := testutil.NewAttestation() att1.Data.Slot = i - att1.Data.CommitteeIndex = uint64(i) + att1.Data.CommitteeIndex = types.CommitteeIndex(i) att2 := testutil.NewAttestation() att2.Data.Slot = i - att2.Data.CommitteeIndex = uint64(i + 1) + att2.Data.CommitteeIndex = types.CommitteeIndex(i + 1) b.Block.Body.Attestations = []*ethpb_alpha.Attestation{att1, att2} root, err := b.Block.HashTreeRoot() require.NoError(t, err) diff --git a/beacon-chain/rpc/validator/attester.go b/beacon-chain/rpc/validator/attester.go index da3f176a99..03578028e0 100644 --- a/beacon-chain/rpc/validator/attester.go +++ b/beacon-chain/rpc/validator/attester.go @@ -232,7 +232,7 @@ func (vs *Server) SubscribeCommitteeSubnets(ctx context.Context, req *ethpb.Comm } currEpoch = helpers.SlotToEpoch(req.Slots[i]) } - subnet := helpers.ComputeSubnetFromCommitteeAndSlot(currValsLen, req.CommitteeIds[i], req.Slots[i]) + subnet := helpers.ComputeSubnetFromCommitteeAndSlot(currValsLen, types.CommitteeIndex(req.CommitteeIds[i]), req.Slots[i]) cache.SubnetIDs.AddAttesterSubnetID(req.Slots[i], subnet) if req.IsAggregator[i] { cache.SubnetIDs.AddAggregatorSubnetID(req.Slots[i], subnet) diff --git a/beacon-chain/rpc/validator/proposer_test.go b/beacon-chain/rpc/validator/proposer_test.go index 534a99004f..e26f07565c 100644 --- a/beacon-chain/rpc/validator/proposer_test.go +++ b/beacon-chain/rpc/validator/proposer_test.go @@ -1654,7 +1654,7 @@ func TestProposer_FilterAttestation(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = testutil.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ - CommitteeIndex: uint64(i), + CommitteeIndex: types.CommitteeIndex(i), }, }) } @@ -1671,7 +1671,7 @@ func TestProposer_FilterAttestation(t *testing.T) { for i := 0; i < len(atts); i++ { atts[i] = testutil.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ - CommitteeIndex: uint64(i), + CommitteeIndex: types.CommitteeIndex(i), Source: ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}, }, AggregationBits: bitfield.Bitlist{0b00000110}, diff --git a/beacon-chain/state/stateutil/attestations.go b/beacon-chain/state/stateutil/attestations.go index 74b501e4f9..52df686442 100644 --- a/beacon-chain/state/stateutil/attestations.go +++ b/beacon-chain/state/stateutil/attestations.go @@ -59,7 +59,7 @@ func marshalAttestationData(data *ethpb.AttestationData) []byte { // Committee index. indexBuf := make([]byte, 8) - binary.LittleEndian.PutUint64(indexBuf, data.CommitteeIndex) + binary.LittleEndian.PutUint64(indexBuf, uint64(data.CommitteeIndex)) copy(enc[8:16], indexBuf) copy(enc[16:48], data.BeaconBlockRoot) @@ -96,7 +96,7 @@ func attestationDataRoot(hasher htrutils.HashFn, data *ethpb.AttestationData) ([ // CommitteeIndex. indexBuf := make([]byte, 8) - binary.LittleEndian.PutUint64(indexBuf, data.CommitteeIndex) + binary.LittleEndian.PutUint64(indexBuf, uint64(data.CommitteeIndex)) interRoot := bytesutil.ToBytes32(indexBuf) fieldRoots[1] = interRoot[:] diff --git a/beacon-chain/sync/validate_beacon_attestation.go b/beacon-chain/sync/validate_beacon_attestation.go index 13f31375d3..fe975fc0a1 100644 --- a/beacon-chain/sync/validate_beacon_attestation.go +++ b/beacon-chain/sync/validate_beacon_attestation.go @@ -138,7 +138,7 @@ func (s *Service) validateUnaggregatedAttTopic(ctx context.Context, a *eth.Attes return pubsub.ValidationIgnore } count := helpers.SlotCommitteeCount(valCount) - if a.Data.CommitteeIndex > count { + if uint64(a.Data.CommitteeIndex) > count { return pubsub.ValidationReject } subnet := helpers.ComputeSubnetForAttestation(valCount, a) @@ -190,20 +190,20 @@ func (s *Service) validateUnaggregatedAttWithState(ctx context.Context, a *eth.A } // Returns true if the attestation was already seen for the participating validator for the slot. -func (s *Service) hasSeenCommitteeIndicesSlot(slot types.Slot, committeeID uint64, aggregateBits []byte) bool { +func (s *Service) hasSeenCommitteeIndicesSlot(slot types.Slot, committeeID types.CommitteeIndex, aggregateBits []byte) bool { s.seenAttestationLock.RLock() defer s.seenAttestationLock.RUnlock() - b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(committeeID)...) + b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(uint64(committeeID))...) b = append(b, aggregateBits...) _, seen := s.seenAttestationCache.Get(string(b)) return seen } // Set committee's indices and slot as seen for incoming attestations. -func (s *Service) setSeenCommitteeIndicesSlot(slot types.Slot, committeeID uint64, aggregateBits []byte) { +func (s *Service) setSeenCommitteeIndicesSlot(slot types.Slot, committeeID types.CommitteeIndex, aggregateBits []byte) { s.seenAttestationLock.Lock() defer s.seenAttestationLock.Unlock() - b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(committeeID)...) + b := append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(uint64(committeeID))...) b = append(b, aggregateBits...) s.seenAttestationCache.Add(string(b), true) } diff --git a/deps.bzl b/deps.bzl index 746cb4aa46..6971879ae5 100644 --- a/deps.bzl +++ b/deps.bzl @@ -2578,8 +2578,8 @@ def prysm_deps(): name = "com_github_prysmaticlabs_ethereumapis", build_file_generation = "off", importpath = "github.com/prysmaticlabs/ethereumapis", - sum = "h1:xmydM87tg/CpJO4yA59yibQGYZA2i8pEoPE2BxSzMlE=", - version = "v0.0.0-20210211220440-bfff608b8ba9", + sum = "h1:c6x9r/6CYbuBsEF0BNJ5f0WhIq7guAGtxB9Mbxp/8Ok=", + version = "v0.0.0-20210218172602-3f05f78bea9d", ) go_repository( name = "com_github_prysmaticlabs_go_bitfield", diff --git a/endtoend/evaluators/slashing.go b/endtoend/evaluators/slashing.go index 0c17e2cf24..8a5f3e86ce 100644 --- a/endtoend/evaluators/slashing.go +++ b/endtoend/evaluators/slashing.go @@ -6,6 +6,7 @@ import ( ptypes "github.com/gogo/protobuf/types" "github.com/pkg/errors" + ethTypes "github.com/prysmaticlabs/eth2-types" eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/go-bitfield" corehelpers "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" @@ -121,7 +122,7 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error { return errors.Wrap(err, "could not get duties") } - var committeeIndex uint64 + var committeeIndex ethTypes.CommitteeIndex var committee []uint64 for _, duty := range duties.Duties { if duty.AttesterSlot == chainHead.HeadSlot-1 { diff --git a/go.mod b/go.mod index effdcd662a..53508e625d 100644 --- a/go.mod +++ b/go.mod @@ -84,7 +84,7 @@ require ( github.com/prometheus/procfs v0.3.0 // indirect github.com/prometheus/tsdb v0.10.0 // indirect github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d - github.com/prysmaticlabs/ethereumapis v0.0.0-20210211220440-bfff608b8ba9 + github.com/prysmaticlabs/ethereumapis v0.0.0-20210218172602-3f05f78bea9d github.com/prysmaticlabs/go-bitfield v0.0.0-20210202205921-7fcea7c45dc8 github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c github.com/rs/cors v1.7.0 diff --git a/go.sum b/go.sum index c896fce34d..6b60a21f63 100644 --- a/go.sum +++ b/go.sum @@ -1028,8 +1028,8 @@ github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20201126065335-1fb46e307951/go github.com/prysmaticlabs/eth2-types v0.0.0-20210127031309-22cbe426eba6/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU= github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d h1:6ooFkN9g9oAJq+VZWseIpj/tQqyVU0DuLFs66Ro43BQ= github.com/prysmaticlabs/eth2-types v0.0.0-20210210115503-cf4ec6600a2d/go.mod h1:kOmQ/zdobQf7HUohDTifDNFEZfNaSCIY5fkONPL+dWU= -github.com/prysmaticlabs/ethereumapis v0.0.0-20210211220440-bfff608b8ba9 h1:xmydM87tg/CpJO4yA59yibQGYZA2i8pEoPE2BxSzMlE= -github.com/prysmaticlabs/ethereumapis v0.0.0-20210211220440-bfff608b8ba9/go.mod h1:YS3iOCGE+iVDE007GHWtj+UoPK9hyYA7Fo4mSDNTtiY= +github.com/prysmaticlabs/ethereumapis v0.0.0-20210218172602-3f05f78bea9d h1:c6x9r/6CYbuBsEF0BNJ5f0WhIq7guAGtxB9Mbxp/8Ok= +github.com/prysmaticlabs/ethereumapis v0.0.0-20210218172602-3f05f78bea9d/go.mod h1:YS3iOCGE+iVDE007GHWtj+UoPK9hyYA7Fo4mSDNTtiY= github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s= github.com/prysmaticlabs/go-bitfield v0.0.0-20210202205921-7fcea7c45dc8 h1:18+Qqobq3HAUY0hgIhPGSqmLFnaLLocemmU7+Sj2aYQ= github.com/prysmaticlabs/go-bitfield v0.0.0-20210202205921-7fcea7c45dc8/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s= diff --git a/shared/testutil/attestation.go b/shared/testutil/attestation.go index 2c51a608a4..de6834e37d 100644 --- a/shared/testutil/attestation.go +++ b/shared/testutil/attestation.go @@ -125,7 +125,7 @@ func GenerateAttestations( if err != nil { return nil, err } - for c := uint64(0); c < committeesPerSlot && c < numToGen; c++ { + for c := types.CommitteeIndex(0); uint64(c) < committeesPerSlot && uint64(c) < numToGen; c++ { committee, err := helpers.BeaconCommitteeFromState(bState, slot, c) if err != nil { return nil, err diff --git a/shared/testutil/block.go b/shared/testutil/block.go index 5adc9d5287..df4d353419 100644 --- a/shared/testutil/block.go +++ b/shared/testutil/block.go @@ -310,7 +310,7 @@ func generateAttesterSlashings( randGen := rand.NewDeterministicGenerator() for i := uint64(0); i < numSlashings; i++ { committeeIndex := randGen.Uint64() % params.BeaconConfig().MaxCommitteesPerSlot - committee, err := helpers.BeaconCommitteeFromState(bState, bState.Slot(), committeeIndex) + committee, err := helpers.BeaconCommitteeFromState(bState, bState.Slot(), types.CommitteeIndex(committeeIndex)) if err != nil { return nil, err } diff --git a/validator/client/validator.go b/validator/client/validator.go index 40f05f513d..ec06e5da72 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -444,7 +444,7 @@ func (v *validator) subscribeToSubnets(ctx context.Context, res *ethpb.DutiesRes } subscribeSlots = append(subscribeSlots, attesterSlot) - subscribeCommitteeIDs = append(subscribeCommitteeIDs, committeeIndex) + subscribeCommitteeIDs = append(subscribeCommitteeIDs, uint64(committeeIndex)) subscribeIsAggregator = append(subscribeIsAggregator, aggregator) } } @@ -468,7 +468,7 @@ func (v *validator) subscribeToSubnets(ctx context.Context, res *ethpb.DutiesRes } subscribeSlots = append(subscribeSlots, attesterSlot) - subscribeCommitteeIDs = append(subscribeCommitteeIDs, committeeIndex) + subscribeCommitteeIDs = append(subscribeCommitteeIDs, uint64(committeeIndex)) subscribeIsAggregator = append(subscribeIsAggregator, aggregator) } } @@ -679,8 +679,8 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du // This constructs a validator subscribed key, it's used to track // which subnet has already been pending requested. -func validatorSubscribeKey(slot types.Slot, committeeID uint64) [64]byte { - return bytesutil.ToBytes64(append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(committeeID)...)) +func validatorSubscribeKey(slot types.Slot, committeeID types.CommitteeIndex) [64]byte { + return bytesutil.ToBytes64(append(bytesutil.Bytes32(uint64(slot)), bytesutil.Bytes32(uint64(committeeID))...)) } // This tracks all validators' voting status.