Skip to content

Commit

Permalink
Attestation pool: continue if bad (#8550)
Browse files Browse the repository at this point in the history
* Continue saving attestation when one is bad

* Gazelle

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
  • Loading branch information
terencechain and rauljordan committed Mar 4, 2021
1 parent d215607 commit 1c7c62c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions beacon-chain/operations/attestations/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ go_library(
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

Expand Down
6 changes: 5 additions & 1 deletion beacon-chain/operations/attestations/kv/aggregated.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
log "github.com/sirupsen/logrus"
)

// AggregateUnaggregatedAttestations aggregates the unaggregated attestations and saves the
Expand Down Expand Up @@ -132,7 +133,10 @@ func (c *AttCaches) SaveAggregatedAttestation(att *ethpb.Attestation) error {
func (c *AttCaches) SaveAggregatedAttestations(atts []*ethpb.Attestation) error {
for _, att := range atts {
if err := c.SaveAggregatedAttestation(att); err != nil {
return err
log.WithError(err).Debug("Could not save aggregated attestation")
if err := c.DeleteAggregatedAttestation(att); err != nil {
log.WithError(err).Debug("Could not delete aggregated attestation")
}
}
}
return nil
Expand Down
35 changes: 35 additions & 0 deletions beacon-chain/operations/attestations/kv/aggregated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,41 @@ func TestKV_Aggregated_SaveAggregatedAttestations(t *testing.T) {
}
}

func TestKV_Aggregated_SaveAggregatedAttestations_SomeGoodSomeBad(t *testing.T) {
tests := []struct {
name string
atts []*ethpb.Attestation
count int
wantErrString string
}{
{
name: "the first attestation is bad",
atts: []*ethpb.Attestation{
testutil.HydrateAttestation(&ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1},
AggregationBits: bitfield.Bitlist{0b1100}}),
testutil.HydrateAttestation(&ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1},
AggregationBits: bitfield.Bitlist{0b1101}}),
},
count: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cache := NewAttCaches()
assert.Equal(t, 0, len(cache.aggregatedAtt), "Invalid start pool, atts: %d", len(cache.unAggregatedAtt))
err := cache.SaveAggregatedAttestations(tt.atts)
if tt.wantErrString != "" {
assert.ErrorContains(t, tt.wantErrString, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.count, len(cache.aggregatedAtt), "Wrong attestation count")
assert.Equal(t, tt.count, cache.AggregatedAttestationCount(), "Wrong attestation count")
})
}
}

func TestKV_Aggregated_AggregatedAttestations(t *testing.T) {
cache := NewAttCaches()

Expand Down

0 comments on commit 1c7c62c

Please sign in to comment.