Skip to content

Commit f89afb0

Browse files
authored
Handle some errors from hasSeenBit and insertSeenBit differently (#15018)
* Ignore errors from `hasSeenBit` and don't pack unaggregated attestations * changelog <3 * Revert "Ignore errors from `hasSeenBit` and don't pack unaggregated attestations" This reverts commit dc86cb6.
1 parent 3cd2973 commit f89afb0

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

beacon-chain/operations/attestations/kv/unaggregated.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
1010
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation"
1111
"github.com/prysmaticlabs/prysm/v5/runtime/version"
12+
log "github.com/sirupsen/logrus"
1213
)
1314

1415
// SaveUnaggregatedAttestation saves an unaggregated attestation in cache.
@@ -60,7 +61,8 @@ func (c *AttCaches) UnaggregatedAttestations() ([]ethpb.Att, error) {
6061
for _, att := range unAggregatedAtts {
6162
seen, err := c.hasSeenBit(att)
6263
if err != nil {
63-
return nil, err
64+
log.WithError(err).Debug("Could not check if unaggregated attestation's bit has been seen. Attestation will not be returned")
65+
continue
6466
}
6567
if !seen {
6668
atts = append(atts, att.Clone())
@@ -137,7 +139,7 @@ func (c *AttCaches) DeleteUnaggregatedAttestation(att ethpb.Att) error {
137139
}
138140

139141
if err := c.insertSeenBit(att); err != nil {
140-
return err
142+
log.WithError(err).Debug("Could not insert seen bit of unaggregated attestation. Attestation will be deleted")
141143
}
142144

143145
id, err := attestation.NewId(att, attestation.Full)
@@ -163,7 +165,12 @@ func (c *AttCaches) DeleteSeenUnaggregatedAttestations() (int, error) {
163165
if att == nil || att.IsNil() || att.IsAggregated() {
164166
continue
165167
}
166-
if seen, err := c.hasSeenBit(att); err == nil && seen {
168+
seen, err := c.hasSeenBit(att)
169+
if err != nil {
170+
log.WithError(err).Debug("Could not check if unaggregated attestation's bit has been seen. Attestation will be deleted")
171+
seen = true
172+
}
173+
if seen {
167174
delete(c.unAggregatedAtt, r)
168175
count++
169176
}

beacon-chain/operations/attestations/kv/unaggregated_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ import (
1717
"github.com/prysmaticlabs/prysm/v5/testing/util"
1818
)
1919

20+
func TestKV_Unaggregated_UnaggregatedAttestations(t *testing.T) {
21+
t.Run("not returned when hasSeenBit fails", func(t *testing.T) {
22+
att := util.HydrateAttestation(&ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}})
23+
id, err := attestation.NewId(att, attestation.Data)
24+
require.NoError(t, err)
25+
26+
cache := NewAttCaches()
27+
require.NoError(t, cache.SaveUnaggregatedAttestation(att))
28+
cache.seenAtt.Delete(id.String())
29+
// cache a bitlist whose length is different from the attestation bitlist's length
30+
cache.seenAtt.Set(id.String(), []bitfield.Bitlist{{0b1001}}, c.DefaultExpiration)
31+
32+
atts, err := cache.UnaggregatedAttestations()
33+
require.NoError(t, err)
34+
assert.Equal(t, 0, len(atts))
35+
})
36+
}
37+
2038
func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
2139
tests := []struct {
2240
name string
@@ -155,6 +173,21 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
155173
require.NoError(t, err)
156174
assert.DeepEqual(t, []ethpb.Att{}, returned)
157175
})
176+
177+
t.Run("deleted when insertSeenBit fails", func(t *testing.T) {
178+
att := util.HydrateAttestation(&ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}})
179+
id, err := attestation.NewId(att, attestation.Data)
180+
require.NoError(t, err)
181+
182+
cache := NewAttCaches()
183+
require.NoError(t, cache.SaveUnaggregatedAttestation(att))
184+
cache.seenAtt.Delete(id.String())
185+
// cache a bitlist whose length is different from the attestation bitlist's length
186+
cache.seenAtt.Set(id.String(), []bitfield.Bitlist{{0b1001}}, c.DefaultExpiration)
187+
188+
require.NoError(t, cache.DeleteUnaggregatedAttestation(att))
189+
assert.Equal(t, 0, len(cache.unAggregatedAtt), "Attestation was not deleted")
190+
})
158191
}
159192

160193
func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) {
@@ -232,6 +265,23 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) {
232265
require.NoError(t, err)
233266
assert.DeepEqual(t, []ethpb.Att{}, returned)
234267
})
268+
269+
t.Run("deleted when hasSeenBit fails", func(t *testing.T) {
270+
att := util.HydrateAttestation(&ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}})
271+
id, err := attestation.NewId(att, attestation.Data)
272+
require.NoError(t, err)
273+
274+
cache := NewAttCaches()
275+
require.NoError(t, cache.SaveUnaggregatedAttestation(att))
276+
cache.seenAtt.Delete(id.String())
277+
// cache a bitlist whose length is different from the attestation bitlist's length
278+
cache.seenAtt.Set(id.String(), []bitfield.Bitlist{{0b1001}}, c.DefaultExpiration)
279+
280+
count, err := cache.DeleteSeenUnaggregatedAttestations()
281+
require.NoError(t, err)
282+
assert.Equal(t, 1, count)
283+
assert.Equal(t, 0, len(cache.unAggregatedAtt), "Attestation was not deleted")
284+
})
235285
}
236286

237287
func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Changed
2+
3+
- Ignore errors from `hasSeenBit` and don't pack unaggregated attestations.

0 commit comments

Comments
 (0)