mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Fix filtering by committee index post-Electra in ListAttestationsV2 (#15148)
This commit is contained in:
@@ -68,7 +68,7 @@ func (s *Server) ListAttestations(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
includeAttestation = shouldIncludeAttestation(att.GetData(), rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
includeAttestation = shouldIncludeAttestation(att, rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
if includeAttestation {
|
||||
attStruct := structs.AttFromConsensus(att)
|
||||
filteredAtts = append(filteredAtts, attStruct)
|
||||
@@ -124,21 +124,21 @@ func (s *Server) ListAttestationsV2(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
includeAttestation = shouldIncludeAttestation(attElectra.GetData(), rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
includeAttestation = shouldIncludeAttestation(attElectra, rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
if includeAttestation {
|
||||
attStruct := structs.AttElectraFromConsensus(attElectra)
|
||||
filteredAtts = append(filteredAtts, attStruct)
|
||||
}
|
||||
} else if v < version.Electra && att.Version() < version.Electra {
|
||||
attOld, ok := att.(*eth.Attestation)
|
||||
attPhase0, ok := att.(*eth.Attestation)
|
||||
if !ok {
|
||||
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
includeAttestation = shouldIncludeAttestation(attOld.GetData(), rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
includeAttestation = shouldIncludeAttestation(attPhase0, rawSlot, slot, rawCommitteeIndex, committeeIndex)
|
||||
if includeAttestation {
|
||||
attStruct := structs.AttFromConsensus(attOld)
|
||||
attStruct := structs.AttFromConsensus(attPhase0)
|
||||
filteredAtts = append(filteredAtts, attStruct)
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func (s *Server) ListAttestationsV2(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Helper function to determine if an attestation should be included
|
||||
func shouldIncludeAttestation(
|
||||
data *eth.AttestationData,
|
||||
att eth.Att,
|
||||
rawSlot string,
|
||||
slot uint64,
|
||||
rawCommitteeIndex string,
|
||||
@@ -167,10 +167,10 @@ func shouldIncludeAttestation(
|
||||
) bool {
|
||||
committeeIndexMatch := true
|
||||
slotMatch := true
|
||||
if rawCommitteeIndex != "" && data.CommitteeIndex != primitives.CommitteeIndex(committeeIndex) {
|
||||
if rawCommitteeIndex != "" && att.GetCommitteeIndex() != primitives.CommitteeIndex(committeeIndex) {
|
||||
committeeIndexMatch = false
|
||||
}
|
||||
if rawSlot != "" && data.Slot != primitives.Slot(slot) {
|
||||
if rawSlot != "" && att.GetData().Slot != primitives.Slot(slot) {
|
||||
slotMatch = false
|
||||
}
|
||||
return committeeIndexMatch && slotMatch
|
||||
|
||||
@@ -310,13 +310,16 @@ func TestListAttestations(t *testing.T) {
|
||||
})
|
||||
})
|
||||
t.Run("Post-Electra", func(t *testing.T) {
|
||||
cb := primitives.NewAttestationCommitteeBits()
|
||||
cb.SetBitAt(1, true)
|
||||
cb1 := primitives.NewAttestationCommitteeBits()
|
||||
cb1.SetBitAt(1, true)
|
||||
cb2 := primitives.NewAttestationCommitteeBits()
|
||||
cb2.SetBitAt(2, true)
|
||||
|
||||
attElectra1 := ðpbv1alpha1.AttestationElectra{
|
||||
AggregationBits: []byte{1, 10},
|
||||
Data: ðpbv1alpha1.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 1,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot1"), 32),
|
||||
Source: ðpbv1alpha1.Checkpoint{
|
||||
Epoch: 1,
|
||||
@@ -327,14 +330,14 @@ func TestListAttestations(t *testing.T) {
|
||||
Root: bytesutil.PadTo([]byte("targetroot1"), 32),
|
||||
},
|
||||
},
|
||||
CommitteeBits: cb,
|
||||
CommitteeBits: cb1,
|
||||
Signature: bytesutil.PadTo([]byte("signature1"), 96),
|
||||
}
|
||||
attElectra2 := ðpbv1alpha1.AttestationElectra{
|
||||
AggregationBits: []byte{1, 10},
|
||||
Data: ðpbv1alpha1.AttestationData{
|
||||
Slot: 1,
|
||||
CommitteeIndex: 4,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot2"), 32),
|
||||
Source: ðpbv1alpha1.Checkpoint{
|
||||
Epoch: 1,
|
||||
@@ -345,14 +348,14 @@ func TestListAttestations(t *testing.T) {
|
||||
Root: bytesutil.PadTo([]byte("targetroot2"), 32),
|
||||
},
|
||||
},
|
||||
CommitteeBits: cb,
|
||||
CommitteeBits: cb2,
|
||||
Signature: bytesutil.PadTo([]byte("signature2"), 96),
|
||||
}
|
||||
attElectra3 := ðpbv1alpha1.AttestationElectra{
|
||||
AggregationBits: bitfield.NewBitlist(8),
|
||||
Data: ðpbv1alpha1.AttestationData{
|
||||
Slot: 2,
|
||||
CommitteeIndex: 2,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot3"), 32),
|
||||
Source: ðpbv1alpha1.Checkpoint{
|
||||
Epoch: 1,
|
||||
@@ -363,14 +366,14 @@ func TestListAttestations(t *testing.T) {
|
||||
Root: bytesutil.PadTo([]byte("targetroot3"), 32),
|
||||
},
|
||||
},
|
||||
CommitteeBits: cb,
|
||||
CommitteeBits: cb1,
|
||||
Signature: bytesutil.PadTo([]byte("signature3"), 96),
|
||||
}
|
||||
attElectra4 := ðpbv1alpha1.AttestationElectra{
|
||||
AggregationBits: bitfield.NewBitlist(8),
|
||||
Data: ðpbv1alpha1.AttestationData{
|
||||
Slot: 2,
|
||||
CommitteeIndex: 4,
|
||||
CommitteeIndex: 0,
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("blockroot4"), 32),
|
||||
Source: ðpbv1alpha1.Checkpoint{
|
||||
Epoch: 1,
|
||||
@@ -381,7 +384,7 @@ func TestListAttestations(t *testing.T) {
|
||||
Root: bytesutil.PadTo([]byte("targetroot4"), 32),
|
||||
},
|
||||
},
|
||||
CommitteeBits: cb,
|
||||
CommitteeBits: cb2,
|
||||
Signature: bytesutil.PadTo([]byte("signature4"), 96),
|
||||
}
|
||||
bs, err := util.NewBeaconStateElectra()
|
||||
@@ -442,7 +445,7 @@ func TestListAttestations(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("index request", func(t *testing.T) {
|
||||
url := "http://example.com?committee_index=4"
|
||||
url := "http://example.com?committee_index=2"
|
||||
request := httptest.NewRequest(http.MethodGet, url, nil)
|
||||
writer := httptest.NewRecorder()
|
||||
writer.Body = &bytes.Buffer{}
|
||||
@@ -459,11 +462,11 @@ func TestListAttestations(t *testing.T) {
|
||||
assert.Equal(t, 2, len(atts))
|
||||
assert.Equal(t, "electra", resp.Version)
|
||||
for _, a := range atts {
|
||||
assert.Equal(t, "4", a.Data.CommitteeIndex)
|
||||
assert.Equal(t, "0x0400000000000000", a.CommitteeBits)
|
||||
}
|
||||
})
|
||||
t.Run("both slot + index request", func(t *testing.T) {
|
||||
url := "http://example.com?slot=2&committee_index=4"
|
||||
url := "http://example.com?slot=2&committee_index=2"
|
||||
request := httptest.NewRequest(http.MethodGet, url, nil)
|
||||
writer := httptest.NewRecorder()
|
||||
writer.Body = &bytes.Buffer{}
|
||||
@@ -481,7 +484,7 @@ func TestListAttestations(t *testing.T) {
|
||||
assert.Equal(t, "electra", resp.Version)
|
||||
for _, a := range atts {
|
||||
assert.Equal(t, "2", a.Data.Slot)
|
||||
assert.Equal(t, "4", a.Data.CommitteeIndex)
|
||||
assert.Equal(t, "0x0400000000000000", a.CommitteeBits)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
3
changelog/radek_att-pool-handler-committee.md
Normal file
3
changelog/radek_att-pool-handler-committee.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- Fix filtering by committee index post-Electra in `ListAttestationsV2`.
|
||||
Reference in New Issue
Block a user