From 7e0110d842addca86bb02ac7a9fb7b697f87ff34 Mon Sep 17 00:00:00 2001 From: Dhruv Bodani Date: Tue, 12 Apr 2022 22:46:54 +0530 Subject: [PATCH] add dutyproposer to bcast --- core/bcast/bcast.go | 10 +++++++++- core/bcast/bcast_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/core/bcast/bcast.go b/core/bcast/bcast.go index bd7a6674c..e3a579a7a 100644 --- a/core/bcast/bcast.go +++ b/core/bcast/bcast.go @@ -29,6 +29,7 @@ import ( type eth2Provider interface { eth2client.AttestationsSubmitter + eth2client.BeaconBlockSubmitter } // New returns a new broadcaster instance. @@ -63,7 +64,14 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, } return b.eth2Cl.SubmitAttestations(ctx, []*eth2p0.Attestation{att}) + case core.DutyProposer: + block, err := core.DecodeBlockAggSignedData(aggData) + if err != nil { + return err + } + + return b.eth2Cl.SubmitBeaconBlock(ctx, block) default: - return errors.New("unsuppered duty type") + return errors.New("unsupported duty type") } } diff --git a/core/bcast/bcast_test.go b/core/bcast/bcast_test.go index d2bb3173c..282edb5c5 100644 --- a/core/bcast/bcast_test.go +++ b/core/bcast/bcast_test.go @@ -19,6 +19,7 @@ import ( "context" "testing" + "github.com/attestantio/go-eth2-client/spec" eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/stretchr/testify/require" @@ -54,3 +55,34 @@ func TestBroadcastAttestation(t *testing.T) { <-ctx.Done() } + +func TestBroadcastBeaconBlock(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + mock, err := beaconmock.New() + require.NoError(t, err) + + block1 := &spec.VersionedSignedBeaconBlock{ + Version: spec.DataVersionPhase0, + Phase0: ð2p0.SignedBeaconBlock{ + Message: testutil.RandomPhase0BeaconBlock(), + Signature: testutil.RandomEth2Signature(), + }, + } + aggData, err := core.EncodeBlockAggSignedData(block1) + require.NoError(t, err) + + mock.SubmitBeaconBlockFunc = func(ctx context.Context, block2 *spec.VersionedSignedBeaconBlock) error { + require.Equal(t, block1, block2) + cancel() + + return ctx.Err() + } + + bcaster, err := bcast.New(mock) + require.NoError(t, err) + + err = bcaster.Broadcast(ctx, core.Duty{Type: core.DutyProposer}, "", aggData) + require.ErrorIs(t, err, context.Canceled) + + <-ctx.Done() +}