mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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 <raul@prysmaticlabs.com>
This commit is contained in:
4
beacon-chain/cache/committee.go
vendored
4
beacon-chain/cache/committee.go
vendored
@@ -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 {
|
||||
|
||||
2
beacon-chain/cache/committee_disabled.go
vendored
2
beacon-chain/cache/committee_disabled.go
vendored
@@ -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
|
||||
}
|
||||
|
||||
|
||||
7
beacon-chain/cache/committee_test.go
vendored
7
beacon-chain/cache/committee_test.go
vendored
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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[:]
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
4
deps.bzl
4
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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
2
go.mod
2
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
|
||||
|
||||
4
go.sum
4
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=
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user