Skip to content

Commit

Permalink
Remove check for duplicates in pending attestation queue
Browse files Browse the repository at this point in the history
The current queue will only save 1 unaggregated attestation for a pending block because we wrap the object into a SignedAggregatedAttestationAndProof with a zeroed aggregator.
  • Loading branch information
potuz committed Mar 27, 2024
1 parent 97edffa commit 662d937
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions beacon-chain/sync/pending_attestations_queue.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sync

import (
"bytes"
"context"
"encoding/hex"
"sync"
Expand Down Expand Up @@ -157,7 +158,8 @@ func (s *Service) processAttestations(ctx context.Context, attestations []*ethpb

// This defines how pending attestations is saved in the map. The key is the
// root of the missing block. The value is the list of pending attestations
// that voted for that block root.
// that voted for that block root. The caller of this function is responsible
// for not sending repeated attestations to the pending queue.
func (s *Service) savePendingAtt(att *ethpb.SignedAggregateAttestationAndProof) {
root := bytesutil.ToBytes32(att.Message.Aggregate.Data.BeaconBlockRoot)

Expand All @@ -178,17 +180,32 @@ func (s *Service) savePendingAtt(att *ethpb.SignedAggregateAttestationAndProof)
s.blkRootToPendingAtts[root] = []*ethpb.SignedAggregateAttestationAndProof{att}
return
}

// Skip if the attestation from the same aggregator already exists in the pending queue.
// Skip if the attestation from the same aggregator already exists in
// the pending queue.
for _, a := range s.blkRootToPendingAtts[root] {
if a.Message.AggregatorIndex == att.Message.AggregatorIndex {
if attsAreEqual(att, a) {
return
}
}

s.blkRootToPendingAtts[root] = append(s.blkRootToPendingAtts[root], att)
}

func attsAreEqual(a, b *ethpb.SignedAggregateAttestationAndProof) bool {
if a.Signature != nil {
return b.Signature != nil && a.Message.AggregatorIndex == b.Message.AggregatorIndex
}
if b.Signature != nil {
return false
}
if a.Message.Aggregate.Data.Slot != b.Message.Aggregate.Data.Slot {
return false
}
if a.Message.Aggregate.Data.CommitteeIndex != b.Message.Aggregate.Data.CommitteeIndex {
return false
}
return bytes.Equal(a.Message.Aggregate.AggregationBits, b.Message.Aggregate.AggregationBits)
}

// This validates the pending attestations in the queue are still valid.
// If not valid, a node will remove it in the queue in place. The validity
// check specifies the pending attestation could not fall one epoch behind
Expand Down

0 comments on commit 662d937

Please sign in to comment.