Skip to content

Commit

Permalink
Merge pull request #20 from flashbots/proposer-auth
Browse files Browse the repository at this point in the history
Add proposer authentication to builder payload
  • Loading branch information
avalonche authored Sep 4, 2024
2 parents 7bdc742 + c3bc2ec commit d02f906
Show file tree
Hide file tree
Showing 18 changed files with 691 additions and 453 deletions.
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

0 comments on commit d02f906

Please sign in to comment.