From bd638ae55675d711f67f98afc8a348803e72cd3a Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 30 Apr 2020 11:45:43 -0700 Subject: [PATCH] setSeenCommitteeIndicesSlot -> setSeenCommitteeIndicesEpoch --- ...iber_committee_index_beacon_attestation.go | 2 +- ...date_committee_index_beacon_attestation.go | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/beacon-chain/sync/subscriber_committee_index_beacon_attestation.go b/beacon-chain/sync/subscriber_committee_index_beacon_attestation.go index fe1a4580ee..8234f2c95d 100644 --- a/beacon-chain/sync/subscriber_committee_index_beacon_attestation.go +++ b/beacon-chain/sync/subscriber_committee_index_beacon_attestation.go @@ -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 { diff --git a/beacon-chain/sync/validate_committee_index_beacon_attestation.go b/beacon-chain/sync/validate_committee_index_beacon_attestation.go index 11b839d642..5b0a2a799b 100644 --- a/beacon-chain/sync/validate_committee_index_beacon_attestation.go +++ b/beacon-chain/sync/validate_committee_index_beacon_attestation.go @@ -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) }