setSeenCommitteeIndicesSlot -> setSeenCommitteeIndicesEpoch

This commit is contained in:
terence tsao
2020-04-30 11:45:43 -07:00
parent 6f6d24820b
commit bd638ae556
2 changed files with 11 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ func (r *Service) committeeIndexBeaconAttestationSubscriber(ctx context.Context,
if a.Data == nil {
return errors.New("nil attestation")
}
r.setSeenCommitteeIndicesSlot(a.Data.Slot, a.Data.CommitteeIndex, a.AggregationBits)
r.setSeenCommitteeIndicesEpoch(helpers.SlotToEpoch(a.Data.Slot), a.Data.CommitteeIndex, a.AggregationBits)
exists, err := r.attPool.HasAggregatedAttestation(a)
if err != nil {

View File

@@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -56,8 +57,8 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
if att.Data == nil {
return false
}
// Verify this the first attestation received for the participating validator for the slot.
if s.hasSeenCommitteeIndicesSlot(att.Data.Slot, att.Data.CommitteeIndex, att.AggregationBits) {
// Verify this the first attestation received for the participating validator for the epoch.
if s.hasSeenCommitteeIndicesEpoch(helpers.SlotToEpoch(att.Data.Slot), att.Data.CommitteeIndex, att.AggregationBits) {
return false
}
@@ -99,28 +100,28 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
return false
}
s.setSeenCommitteeIndicesSlot(att.Data.Slot, att.Data.CommitteeIndex, att.AggregationBits)
s.setSeenCommitteeIndicesEpoch(helpers.SlotToEpoch(att.Data.Slot), att.Data.CommitteeIndex, att.AggregationBits)
msg.ValidatorData = att
return true
}
// Returns true if the attestation was already seen for the participating validator for the slot.
func (s *Service) hasSeenCommitteeIndicesSlot(slot uint64, committeeID uint64, aggregateBits []byte) bool {
// Returns true if the attestation was already seen for the participating validator for the epoch.
func (s *Service) hasSeenCommitteeIndicesEpoch(epoch uint64, committeeID uint64, aggregateBits []byte) bool {
s.seenAttestationLock.RLock()
defer s.seenAttestationLock.RUnlock()
b := append(bytesutil.Bytes32(slot), bytesutil.Bytes32(committeeID)...)
b := append(bytesutil.Bytes32(epoch), bytesutil.Bytes32(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 uint64, committeeID uint64, aggregateBits []byte) {
// Set committee's indices and epoch as seen for incoming attestations.
func (s *Service) setSeenCommitteeIndicesEpoch(epoch uint64, committeeID uint64, aggregateBits []byte) {
s.seenAttestationLock.Lock()
defer s.seenAttestationLock.Unlock()
b := append(bytesutil.Bytes32(slot), bytesutil.Bytes32(committeeID)...)
b := append(bytesutil.Bytes32(epoch), bytesutil.Bytes32(committeeID)...)
b = append(b, aggregateBits...)
s.seenAttestationCache.Add(string(b), true)
}