Skip to content

Commit

Permalink
add dutyAgg to bcast
Browse files Browse the repository at this point in the history
  • Loading branch information
xenowits committed Sep 13, 2022
1 parent eed2dad commit bf3a6f7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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

0 comments on commit bf3a6f7

Please sign in to comment.