github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/sync/subscriber_beacon_attestation.go (about)

     1  package sync
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/pkg/errors"
     8  	types "github.com/prysmaticlabs/eth2-types"
     9  	"github.com/prysmaticlabs/prysm/beacon-chain/cache"
    10  	"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
    11  	eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    12  	"github.com/prysmaticlabs/prysm/shared/params"
    13  	"github.com/prysmaticlabs/prysm/shared/sliceutil"
    14  	"google.golang.org/protobuf/proto"
    15  )
    16  
    17  func (s *Service) committeeIndexBeaconAttestationSubscriber(_ context.Context, msg proto.Message) error {
    18  	a, ok := msg.(*eth.Attestation)
    19  	if !ok {
    20  		return fmt.Errorf("message was not type *eth.Attestation, type=%T", msg)
    21  	}
    22  
    23  	if a.Data == nil {
    24  		return errors.New("nil attestation")
    25  	}
    26  	s.setSeenCommitteeIndicesSlot(a.Data.Slot, a.Data.CommitteeIndex, a.AggregationBits)
    27  
    28  	exists, err := s.cfg.AttPool.HasAggregatedAttestation(a)
    29  	if err != nil {
    30  		return errors.Wrap(err, "Could not determine if attestation pool has this atttestation")
    31  	}
    32  	if exists {
    33  		return nil
    34  	}
    35  
    36  	return s.cfg.AttPool.SaveUnaggregatedAttestation(a)
    37  }
    38  
    39  func (s *Service) persistentSubnetIndices() []uint64 {
    40  	return cache.SubnetIDs.GetAllSubnets()
    41  }
    42  
    43  func (s *Service) aggregatorSubnetIndices(currentSlot types.Slot) []uint64 {
    44  	endEpoch := helpers.SlotToEpoch(currentSlot) + 1
    45  	endSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(endEpoch))
    46  	var commIds []uint64
    47  	for i := currentSlot; i <= endSlot; i++ {
    48  		commIds = append(commIds, cache.SubnetIDs.GetAggregatorSubnetIDs(i)...)
    49  	}
    50  	return sliceutil.SetUint64(commIds)
    51  }
    52  
    53  func (s *Service) attesterSubnetIndices(currentSlot types.Slot) []uint64 {
    54  	endEpoch := helpers.SlotToEpoch(currentSlot) + 1
    55  	endSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(endEpoch))
    56  	var commIds []uint64
    57  	for i := currentSlot; i <= endSlot; i++ {
    58  		commIds = append(commIds, cache.SubnetIDs.GetAttesterSubnetIDs(i)...)
    59  	}
    60  	return sliceutil.SetUint64(commIds)
    61  }