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

Add proposer authentication to builder payload #20

Merged
merged 1 commit into from
Sep 4, 2024
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
4 changes: 3 additions & 1 deletion builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sequenceDiagram
OPB-->>BB: PayloadAttributes

Note right of BB: timespan for building blocks
OPS->> BB: /eth/v1/builder/payload/{slot}/{parent_hash}
OPS->> BB: POST /eth/v1/builder/payload
BB-->>OPS: BuilderPayload
OPS->> EES: engine_getPayload
OPS-->>OPS: SimulatePayload
Expand All @@ -43,5 +43,7 @@ To enable the builder:

* `--builder` Enable the Builder module
* `--builder.beacon_endpoints` list of op-node SSE event stream endpoints to subscribe from
* `--builder.signing_key` private key to sign requested block payloads
* `--builder.proposer_signing_address` signing address used to authenticate the proposer

Run `geth --help` for the full list of builder configurations.
9 changes: 5 additions & 4 deletions builder/beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/builder/types"
"github.com/ethereum/go-ethereum/log"
"github.com/r3labs/sse"
)

type IBeaconClient interface {
SubscribeToPayloadAttributesEvents(payloadAttrC chan BuilderPayloadAttributes)
SubscribeToPayloadAttributesEvents(payloadAttrC chan types.PayloadAttributes)
Start() error
Stop()
}

type NilBeaconClient struct{}

func (b *NilBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan BuilderPayloadAttributes) {
func (b *NilBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan types.PayloadAttributes) {
}

func (b *NilBeaconClient) Start() error { return nil }
Expand All @@ -43,14 +44,14 @@ func NewOpBeaconClient(endpoint string) *OpBeaconClient {
}
}

func (opbc *OpBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan BuilderPayloadAttributes) {
func (opbc *OpBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan types.PayloadAttributes) {
eventsURL := fmt.Sprintf("%s/events", opbc.endpoint)
log.Info("subscribing to payload_attributes events", "url", eventsURL)

for {
client := sse.NewClient(eventsURL)
err := client.SubscribeWithContext(opbc.ctx, "payload_attributes", func(msg *sse.Event) {
data := new(BuilderPayloadAttributes)
data := new(types.PayloadAttributes)
err := json.Unmarshal(msg.Data, data)
if err != nil {
log.Error("could not unmarshal payload_attributes event", "err", err)
Expand Down
11 changes: 6 additions & 5 deletions builder/beacon_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/builder/types"
"gotest.tools/assert"
)

type mockBeaconNode struct {
payloadAttributes BuilderPayloadAttributes
payloadAttributes types.PayloadAttributes
}

func (b *mockBeaconNode) Stop() {}

func (b *mockBeaconNode) SubscribeToPayloadAttributesEvents(payloadAttrC chan BuilderPayloadAttributes) {
func (b *mockBeaconNode) SubscribeToPayloadAttributesEvents(payloadAttrC chan types.PayloadAttributes) {
go func() {
payloadAttrC <- b.payloadAttributes
}()
}

func (b *mockBeaconNode) Start() error { return nil }

func newMockBeaconNode(payloadAttributes BuilderPayloadAttributes) *mockBeaconNode {
func newMockBeaconNode(payloadAttributes types.PayloadAttributes) *mockBeaconNode {
return &mockBeaconNode{
payloadAttributes: payloadAttributes,
}
}

func TestMockBeaconNode(t *testing.T) {
mockBeaconNode := newMockBeaconNode(BuilderPayloadAttributes{Slot: 123})
payloadAttrC := make(chan BuilderPayloadAttributes, 1) // Use buffered channel
mockBeaconNode := newMockBeaconNode(types.PayloadAttributes{Slot: 123})
payloadAttrC := make(chan types.PayloadAttributes, 1) // Use buffered channel

mockBeaconNode.SubscribeToPayloadAttributesEvents(payloadAttrC)

Expand Down
Loading