Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save unaggregated att in beacon_aggregate_and_proof subscriber #6109

Merged
merged 9 commits into from
Jun 3, 2020
6 changes: 6 additions & 0 deletions beacon-chain/sync/subscriber_beacon_aggregate_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
)

// beaconAggregateProofSubscriber forwards the incoming validated aggregated attestation and proof to the
Expand All @@ -33,5 +34,10 @@ func (r *Service) beaconAggregateProofSubscriber(ctx context.Context, msg proto.
},
})

// An unaggregated attestation can make it here. It’s valid, the aggregator it just itself, although it means poor performance for the subnet.
if !helpers.IsAggregated(a.Message.Aggregate) {
return r.attPool.SaveUnaggregatedAttestation(a.Message.Aggregate)
}

return r.attPool.SaveAggregatedAttestation(a.Message.Aggregate)
}
23 changes: 22 additions & 1 deletion beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
)

func TestBeaconAggregateProofSubscriber_CanSave(t *testing.T) {
func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing.T) {
c, err := lru.New(10)
if err != nil {
t.Fatal(err)
Expand All @@ -32,3 +32,24 @@ func TestBeaconAggregateProofSubscriber_CanSave(t *testing.T) {
t.Error("Did not save aggregated attestation")
}
}

func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testing.T) {
c, err := lru.New(10)
if err != nil {
t.Fatal(err)
}
r := &Service{
attPool: attestations.NewPool(),
seenAttestationCache: c,
attestationNotifier: (&mock.ChainService{}).OperationNotifier(),
}

a := &ethpb.SignedAggregateAttestationAndProof{Message: &ethpb.AggregateAttestationAndProof{Aggregate: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, AggregationBits: bitfield.Bitlist{0x03}}, AggregatorIndex: 100}}
if err := r.beaconAggregateProofSubscriber(context.Background(), a); err != nil {
t.Fatal(err)
}

if !reflect.DeepEqual(r.attPool.UnaggregatedAttestations(), []*ethpb.Attestation{a.Message.Aggregate}) {
t.Error("Did not save unaggregated attestation")
}
}