Skip to content

Commit

Permalink
setSeenCommitteeIndicesSlot -> setSeenCommitteeIndicesEpoch
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Apr 30, 2020
1 parent 6f6d248 commit bd638ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions beacon-chain/sync/validate_committee_index_beacon_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}

0 comments on commit bd638ae

Please sign in to comment.