Revert "Subscriber: use target epoch for hasSeen cache" (#6944)

* Revert "Subscriber: use target epoch for hasSeen cache (#6908)"

This reverts commit 3275a86ece.
This commit is contained in:
terence tsao 2020-08-09 11:52:37 -07:00 committed by GitHub
parent f575a81afd
commit 7591240366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

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

View File

@ -69,8 +69,8 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
return pubsub.ValidationIgnore return pubsub.ValidationIgnore
} }
// Verify this the first attestation received for the participating validator for the target epoch. // Verify this the first attestation received for the participating validator for the slot.
if s.hasSeenCommitteeIndicesEpoch(att.Data.Target.Epoch, att.Data.CommitteeIndex, att.AggregationBits) { if s.hasSeenCommitteeIndicesSlot(att.Data.Slot, att.Data.CommitteeIndex, att.AggregationBits) {
return pubsub.ValidationIgnore return pubsub.ValidationIgnore
} }
// Reject an attestation if it references an invalid block. // Reject an attestation if it references an invalid block.
@ -138,28 +138,28 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
} }
} }
s.setSeenCommitteeIndicesEpoch(att.Data.Target.Epoch, att.Data.CommitteeIndex, att.AggregationBits) s.setSeenCommitteeIndicesSlot(att.Data.Slot, att.Data.CommitteeIndex, att.AggregationBits)
msg.ValidatorData = att msg.ValidatorData = att
return pubsub.ValidationAccept return pubsub.ValidationAccept
} }
// Returns true if the attestation was already seen for the participating validator for the target epoch. // Returns true if the attestation was already seen for the participating validator for the slot.
func (s *Service) hasSeenCommitteeIndicesEpoch(epoch uint64, committeeID uint64, aggregateBits []byte) bool { func (s *Service) hasSeenCommitteeIndicesSlot(slot uint64, committeeID uint64, aggregateBits []byte) bool {
s.seenAttestationLock.RLock() s.seenAttestationLock.RLock()
defer s.seenAttestationLock.RUnlock() defer s.seenAttestationLock.RUnlock()
b := append(bytesutil.Bytes32(epoch), bytesutil.Bytes32(committeeID)...) b := append(bytesutil.Bytes32(slot), bytesutil.Bytes32(committeeID)...)
b = append(b, aggregateBits...) b = append(b, aggregateBits...)
_, seen := s.seenAttestationCache.Get(string(b)) _, seen := s.seenAttestationCache.Get(string(b))
return seen return seen
} }
// Set committee's indices and target epoch as seen for incoming attestations. // Set committee's indices and slot as seen for incoming attestations.
func (s *Service) setSeenCommitteeIndicesEpoch(epoch uint64, committeeID uint64, aggregateBits []byte) { func (s *Service) setSeenCommitteeIndicesSlot(slot uint64, committeeID uint64, aggregateBits []byte) {
s.seenAttestationLock.Lock() s.seenAttestationLock.Lock()
defer s.seenAttestationLock.Unlock() defer s.seenAttestationLock.Unlock()
b := append(bytesutil.Bytes32(epoch), bytesutil.Bytes32(committeeID)...) b := append(bytesutil.Bytes32(slot), bytesutil.Bytes32(committeeID)...)
b = append(b, aggregateBits...) b = append(b, aggregateBits...)
s.seenAttestationCache.Add(string(b), true) s.seenAttestationCache.Add(string(b), true)
} }