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

core/bcast: add support for DutyAggregator #1123

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/bcast/bcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, pubkey core.
log.Info(ctx, "Beacon committee subscription successfully submitted to beacon node", nil)
}

return err
case core.DutyAggregator:
aggAndProof, ok := aggData.(core.SignedAggregateAndProof)
if !ok {
return errors.New("invalid aggregate and proof")
}

err = b.eth2Cl.SubmitAggregateAttestations(ctx, []*eth2p0.SignedAggregateAndProof{&aggAndProof.SignedAggregateAndProof})
if err == nil {
log.Info(ctx, "Attestation aggregation successfully submitted to beacon node", nil)
}

return err
default:
return errors.New("unsupported duty type")
Expand Down
25 changes: 25 additions & 0 deletions core/bcast/bcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,28 @@ func TestBroadcastBeaconCommitteeSubscriptionV1(t *testing.T) {

<-ctx.Done()
}

func TestBroadcastAggregateAttestation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
mock, err := beaconmock.New()
require.NoError(t, err)

aggAndProof := testutil.RandomSignedAggregateAndProof()
data := core.SignedAggregateAndProof{SignedAggregateAndProof: *aggAndProof}

mock.SubmitAggregateAttestationsFunc = func(ctx context.Context, aggregateAndProofs []*eth2p0.SignedAggregateAndProof) error {
require.Equal(t, aggAndProof, aggregateAndProofs[0])
cancel()

return ctx.Err()
}

bcaster, err := bcast.New(ctx, mock)
require.NoError(t, err)

err = bcaster.Broadcast(ctx, core.Duty{Type: core.DutyAggregator}, "", data)
require.Error(t, err)
require.ErrorIs(t, err, context.Canceled)

<-ctx.Done()
}
15 changes: 15 additions & 0 deletions testutil/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,21 @@ func RandomSignedBeaconCommitteeSubscription(vIdx, slot, commIdx int) core.Signe
}
}

func RandomSignedAggregateAndProof() *eth2p0.SignedAggregateAndProof {
return &eth2p0.SignedAggregateAndProof{
Message: RandomAggregateAndProof(),
Signature: RandomEth2Signature(),
}
}

func RandomAggregateAndProof() *eth2p0.AggregateAndProof {
return &eth2p0.AggregateAndProof{
AggregatorIndex: RandomVIdx(),
Aggregate: RandomAttestation(),
SelectionProof: RandomEth2Signature(),
}
}

func RandomSyncAggregate(t *testing.T) *altair.SyncAggregate {
t.Helper()

Expand Down