Skip to content

Commit

Permalink
Builder config hub
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Oct 24, 2024
1 parent 11f0b9f commit ea95969
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
9 changes: 8 additions & 1 deletion cmd/httpserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var flags []cli.Flag = []cli.Flag{
Value: "127.0.0.1:8645",
Usage: "address to send local ordeflow to",
},
&cli.StringFlag{
Name: "builder-confighub-endpoint",
Value: "127.0.0.1:14892",
Usage: "address of the builder config hub enpoint (directly or throught the cvm-proxy)",
},

// certificate config
&cli.DurationFlag{
Expand Down Expand Up @@ -144,6 +149,8 @@ func main() {
builderEndpoint := cCtx.String("builder-endpoint")
certDuration := cCtx.Duration("cert-duration")
certHosts := cCtx.StringSlice("cert-hosts")
builderConfigHubEndpoint := cCtx.String("builder-confighub-endpoint")

proxyConfig := &proxy.Config{
Log: log,
UsersListenAddr: usersListenAddr,
Expand All @@ -154,7 +161,7 @@ func main() {
CertValidDuration: certDuration,
CertHosts: certHosts,

BuilderConfigHub: proxy.MockBuilderConfigHub{},
BuilderConfigHub: proxy.NewBuilderConfigHub(builderConfigHubEndpoint),
}

proxy, err := proxy.New(*proxyConfig)
Expand Down
75 changes: 67 additions & 8 deletions proxy/confighub.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,83 @@
// Package proxy provides the main proxy server.
package proxy

import "github.com/ethereum/go-ethereum/common"
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"

type BuilderInfo struct {
Cert []byte
OrderflowSigner common.Address
"github.com/ethereum/go-ethereum/common"
)

type ConfighubOrderflowProxyCredentials struct {
TLSCert string `json:"tls_cert"`
EcdsaPubkeyAddress common.Address `json:"ecdsa_pubkey_address"`
}

type ConfighubBuilder struct {
IP string `json:"ip"`
OrderflowProxy ConfighubOrderflowProxyCredentials `json:"orderflow_proxy"`
}

type BuilderConfigHub interface {
PublishConfig(info BuilderInfo) error
GetBuilders() ([]BuilderInfo, error)
RegisterCredentials(args ConfighubOrderflowProxyCredentials) error
Builders() ([]ConfighubBuilder, error)
}

type MockBuilderConfigHub struct{}

func (m MockBuilderConfigHub) PublishConfig(info BuilderInfo) error {
func (m MockBuilderConfigHub) RegisterCredentials(info ConfighubOrderflowProxyCredentials) error {
return nil
}

func (m MockBuilderConfigHub) GetBuilders() ([]BuilderInfo, error) {
func (m MockBuilderConfigHub) Builders() ([]ConfighubBuilder, error) {
return nil, nil
}

type builderConfigHubImpl struct {
endpoint string
}

func NewBuilderConfigHub(endpoint string) BuilderConfigHub {
return &builderConfigHubImpl{
endpoint: endpoint,
}
}

func (b *builderConfigHubImpl) RegisterCredentials(info ConfighubOrderflowProxyCredentials) error {
body, err := json.Marshal(info)
if err != nil {
return err
}
resp, err := http.Post(b.endpoint+"/api/l1-builder/v1/register_credentials/orderflow-proxy", "application/json", bytes.NewReader(body))
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
return fmt.Errorf("builder config hub returned error, code: %d, body: %s", resp.StatusCode, string(respBody))
}
return nil
}

func (b *builderConfigHubImpl) Builders() ([]ConfighubBuilder, error) {
resp, err := http.Get(b.endpoint + "/api/l1-builder/v1/builders")
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var result []ConfighubBuilder
err = json.Unmarshal(body, &result)
if err != nil {
return nil, err
}
return result, nil
}
8 changes: 4 additions & 4 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (prx *Proxy) GenerateAndPublish() error {

prx.log.Info("Generated ordeflow signer", "address", orderflowSigner)

selfInfo := BuilderInfo{
Cert: cert,
OrderflowSigner: orderflowSigner,
selfInfo := ConfighubOrderflowProxyCredentials{
TLSCert: string(cert),
EcdsaPubkeyAddress: orderflowSigner,
}

err = prx.Config.BuilderConfigHub.PublishConfig(selfInfo)
err = prx.Config.BuilderConfigHub.RegisterCredentials(selfInfo)
if err != nil {
return err
}
Expand Down

0 comments on commit ea95969

Please sign in to comment.