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 dutyproposer to bcast #418

Merged
merged 1 commit into from
Apr 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
10 changes: 9 additions & 1 deletion core/bcast/bcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type eth2Provider interface {
eth2client.AttestationsSubmitter
eth2client.BeaconBlockSubmitter
}

// New returns a new broadcaster instance.
Expand Down Expand Up @@ -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")
}
}
32 changes: 32 additions & 0 deletions core/bcast/bcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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: &eth2p0.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()
}