mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Skip duplicated aggregated attestation in pending queue (#7326)
* Skip duplicated aggregated atts * Test * Fixed a regression test * Merge branch 'master' of github.com:prysmaticlabs/prysm into skip-dup-aggregator * Go fmt * Merge refs/heads/master into skip-dup-aggregator
This commit is contained in:
@@ -142,6 +142,13 @@ func (s *Service) savePendingAtt(att *ethpb.SignedAggregateAttestationAndProof)
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
s.blkRootToPendingAtts[root] = append(s.blkRootToPendingAtts[root], att)
|
||||
}
|
||||
|
||||
|
||||
@@ -245,14 +245,17 @@ func TestValidatePendingAtts_CanPruneOldAtts(t *testing.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: uint64(i),
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(i), BeaconBlockRoot: r1[:]}}}})
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: uint64(i*2 + i),
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(i), BeaconBlockRoot: r2[:]}}}})
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: uint64(i*3 + i),
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(i), BeaconBlockRoot: r3[:]}}}})
|
||||
}
|
||||
@@ -276,3 +279,30 @@ func TestValidatePendingAtts_CanPruneOldAtts(t *testing.T) {
|
||||
// Verify the keys are deleted.
|
||||
assert.Equal(t, 0, len(s.blkRootToPendingAtts), "Did not delete block keys")
|
||||
}
|
||||
|
||||
func TestValidatePendingAtts_NoDuplicatingAggregatorIndex(t *testing.T) {
|
||||
s := &Service{
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
}
|
||||
|
||||
r1 := [32]byte{'A'}
|
||||
r2 := [32]byte{'B'}
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: 1,
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(1), BeaconBlockRoot: r1[:]}}}})
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: 2,
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(2), BeaconBlockRoot: r2[:]}}}})
|
||||
s.savePendingAtt(ðpb.SignedAggregateAttestationAndProof{
|
||||
Message: ðpb.AggregateAttestationAndProof{
|
||||
AggregatorIndex: 2,
|
||||
Aggregate: ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{Slot: uint64(3), BeaconBlockRoot: r2[:]}}}})
|
||||
|
||||
assert.Equal(t, 1, len(s.blkRootToPendingAtts[r1]), "Did not save pending atts")
|
||||
assert.Equal(t, 1, len(s.blkRootToPendingAtts[r2]), "Did not save pending atts")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user