From 1a584998eeece2a24d1c65ca232490f623f3169d Mon Sep 17 00:00:00 2001 From: james-prysm Date: Thu, 27 Feb 2025 15:27:24 -0600 Subject: [PATCH] adding fix and unit tests --- .../sync/pending_attestations_queue.go | 2 +- .../sync/pending_attestations_queue_test.go | 65 +++++++++++++++++++ .../james-prysm_fix-wrong-committee-seen.md | 3 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 changelog/james-prysm_fix-wrong-committee-seen.md diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index 7d9d3137e182..5ee5b71119f3 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -197,7 +197,7 @@ func (s *Service) processUnaggregated(ctx context.Context, att ethpb.Att) { return } } - s.setSeenCommitteeIndicesSlot(data.Slot, data.CommitteeIndex, att.GetAggregationBits()) + s.setSeenCommitteeIndicesSlot(data.Slot, att.GetCommitteeIndex(), att.GetAggregationBits()) valCount, err := helpers.ActiveValidatorCount(ctx, preState, slots.ToEpoch(data.Slot)) if err != nil { diff --git a/beacon-chain/sync/pending_attestations_queue_test.go b/beacon-chain/sync/pending_attestations_queue_test.go index 551f2e21784b..00468b18a321 100644 --- a/beacon-chain/sync/pending_attestations_queue_test.go +++ b/beacon-chain/sync/pending_attestations_queue_test.go @@ -706,3 +706,68 @@ func Test_attsAreEqual_Committee(t *testing.T) { assert.Equal(t, false, attsAreEqual(att1, att2)) }) } + +func Test_SeenCommitteeIndicesSlot(t *testing.T) { + t.Run("phase 0 success", func(t *testing.T) { + s := &Service{ + seenUnAggregatedAttestationCache: lruwrpr.New(1), + } + data := ðpb.AttestationData{Slot: 1, CommitteeIndex: 44} + att := ðpb.Attestation{ + AggregationBits: bitfield.Bitlist{0x01}, + Data: data, + } + s.setSeenCommitteeIndicesSlot(data.Slot, att.GetCommitteeIndex(), att.GetAggregationBits()) + b := append(bytesutil.Bytes32(uint64(1)), bytesutil.Bytes32(uint64(44))...) + b = append(b, bytesutil.SafeCopyBytes(att.GetAggregationBits())...) + _, ok := s.seenUnAggregatedAttestationCache.Get(string(b)) + require.Equal(t, true, ok) + }) + t.Run("electra success", func(t *testing.T) { + s := &Service{ + seenUnAggregatedAttestationCache: lruwrpr.New(1), + } + // committee index is 0 post electra for attestation electra + data := ðpb.AttestationData{Slot: 1, CommitteeIndex: 0} + cb := primitives.NewAttestationCommitteeBits() + cb.SetBitAt(uint64(63), true) + att := ðpb.AttestationElectra{ + AggregationBits: bitfield.Bitlist{0x01}, + Data: data, + CommitteeBits: cb, + } + ci := att.GetCommitteeIndex() + s.setSeenCommitteeIndicesSlot(data.Slot, ci, att.GetAggregationBits()) + b := append(bytesutil.Bytes32(uint64(1)), bytesutil.Bytes32(uint64(63))...) + b = append(b, bytesutil.SafeCopyBytes(att.GetAggregationBits())...) + _, ok := s.seenUnAggregatedAttestationCache.Get(string(b)) + require.Equal(t, true, ok) + }) + t.Run("electra fails using wrong getter ", func(t *testing.T) { + s := &Service{ + seenUnAggregatedAttestationCache: lruwrpr.New(1), + } + // committee index is 0 post electra for attestation electra + data := ðpb.AttestationData{Slot: 1, CommitteeIndex: 0} + cb := primitives.NewAttestationCommitteeBits() + cb.SetBitAt(uint64(63), true) + att := ðpb.AttestationElectra{ + AggregationBits: bitfield.Bitlist{0x01}, + Data: data, + CommitteeBits: cb, + } + ci := data.CommitteeIndex + s.setSeenCommitteeIndicesSlot(data.Slot, ci, att.GetAggregationBits()) + b := append(bytesutil.Bytes32(uint64(1)), bytesutil.Bytes32(uint64(63))...) + b = append(b, bytesutil.SafeCopyBytes(att.GetAggregationBits())...) + _, ok := s.seenUnAggregatedAttestationCache.Get(string(b)) + require.Equal(t, false, ok) + + // using the incorrect value searches it up + b = append(bytesutil.Bytes32(uint64(1)), bytesutil.Bytes32(uint64(0))...) + b = append(b, bytesutil.SafeCopyBytes(att.GetAggregationBits())...) + _, ok = s.seenUnAggregatedAttestationCache.Get(string(b)) + require.Equal(t, true, ok) + }) + +} diff --git a/changelog/james-prysm_fix-wrong-committee-seen.md b/changelog/james-prysm_fix-wrong-committee-seen.md new file mode 100644 index 000000000000..4a8a5bc7aed4 --- /dev/null +++ b/changelog/james-prysm_fix-wrong-committee-seen.md @@ -0,0 +1,3 @@ +### Fixed + +- fix inserting the wrong committee index into the seen cache for electra attestations \ No newline at end of file