Skip to content

Commit

Permalink
add all supported methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Oct 28, 2024
1 parent 533855c commit 91e8a7a
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 90 deletions.
27 changes: 19 additions & 8 deletions proxy/new_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"crypto/tls"
"log/slog"
"net/http"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/flashbots/go-utils/rpcclient"
"github.com/flashbots/go-utils/signature"
)
Expand All @@ -19,19 +21,23 @@ type NewProxy struct {
PublicCertPEM []byte
Certificate tls.Certificate

LocalBuilder rpcclient.RPCClient
localBuilder rpcclient.RPCClient

PublicHandler http.Handler
LocalHandler http.Handler
CertHandler http.Handler // this endpoint just returns generated certificate

UpdatePeers chan []ConfighubBuilder
updatePeers chan []ConfighubBuilder
shareQueue chan *ParsedRequest

peersMu sync.RWMutex
lastFetchedPeers []ConfighubBuilder
}

type NewProxyConstantConfig struct {
Log *slog.Logger
Name string
Log *slog.Logger
Name string
FlashbotsSignerAddress common.Address
}

type NewProxyConfig struct {
Expand Down Expand Up @@ -67,7 +73,7 @@ func NewNewProxy(config NewProxyConfig) (*NewProxy, error) {
OrderflowSigner: orderflowSigner,
PublicCertPEM: cert,
Certificate: certificate,
LocalBuilder: localBuilder,
localBuilder: localBuilder,
}

publicHandler, err := prx.PublicJSONRPCHandler()
Expand All @@ -91,13 +97,13 @@ func NewNewProxy(config NewProxyConfig) (*NewProxy, error) {
shareQeueuCh := make(chan *ParsedRequest)
updatePeersCh := make(chan []ConfighubBuilder)
prx.shareQueue = shareQeueuCh
prx.UpdatePeers = updatePeersCh
prx.updatePeers = updatePeersCh
queue := ShareQueue{
name: prx.Name,
log: prx.Log,
queue: shareQeueuCh,
updatePeers: updatePeersCh,
localBuilder: prx.LocalBuilder,
localBuilder: prx.localBuilder,
singer: prx.OrderflowSigner,
}
go queue.Run()
Expand Down Expand Up @@ -125,8 +131,13 @@ func (prx *NewProxy) RequestNewPeers() error {
if err != nil {
return err
}

prx.peersMu.Lock()
prx.lastFetchedPeers = builders
prx.peersMu.Unlock()

select {
case prx.UpdatePeers <- builders:
case prx.updatePeers <- builders:
default:
}
return nil
Expand Down
32 changes: 16 additions & 16 deletions proxy/new_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func StartTestOrderflowProxy(name string) (*OrderflowProxyTestSetup, error) {
if err != nil {
return nil, err
}
go publicProxyServer.ServeTLS(publicListener, "", "")
go publicProxyServer.ServeTLS(publicListener, "", "") //nolint: errcheck
publicServerEndpoint := fmt.Sprintf("https://localhost:%d", publicListener.Addr().(*net.TCPAddr).Port)
ip := fmt.Sprintf("127.0.0.1:%d", publicListener.Addr().(*net.TCPAddr).Port)

Expand All @@ -90,7 +90,7 @@ func StartTestOrderflowProxy(name string) (*OrderflowProxyTestSetup, error) {
if err != nil {
return nil, err
}
go localProxyServer.ServeTLS(localListener, "", "")
go localProxyServer.ServeTLS(localListener, "", "") //nolint:errcheck
localServerEndpoint := fmt.Sprintf("https://localhost:%d", localListener.Addr().(*net.TCPAddr).Port)

certProxyServer := httptest.NewServer(proxy.CertHandler)
Expand Down Expand Up @@ -223,6 +223,14 @@ func expectNoRequest(t *testing.T, ch chan *RequestData) {
}
}

func proxiesUpdatePeers(t *testing.T) {
for _, instance := range proxies {
err := instance.proxy.RequestNewPeers()
require.NoError(t, err)
}
time.Sleep(time.Millisecond * 50)
}

func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
signer, err := signature.NewSignerFromHexPrivateKey("0xd63b3c447fdea415a05e4c0b859474d14105a88178efdf350bc9f7b05be3cc58")
require.NoError(t, err)
Expand All @@ -235,11 +243,9 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
builderHubPeers = nil
err = proxies[0].proxy.RegisterSecrets()
require.NoError(t, err)
err = proxies[0].proxy.RequestNewPeers()
require.NoError(t, err)
time.Sleep(time.Millisecond * 50)
proxiesUpdatePeers(t)

_, err = client.Call(context.Background(), SendBundleMethod, &rpctypes.EthSendBundleArgs{
_, err = client.Call(context.Background(), EthSendBundleMethod, &rpctypes.EthSendBundleArgs{
BlockNumber: 1000,
})
require.NoError(t, err)
Expand All @@ -252,12 +258,9 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
// add one more peer
err = proxies[1].proxy.RegisterSecrets()
require.NoError(t, err)
proxiesUpdatePeers(t)

err = proxies[0].proxy.RequestNewPeers()
require.NoError(t, err)
time.Sleep(time.Millisecond * 50)

_, err = client.Call(context.Background(), SendBundleMethod, &rpctypes.EthSendBundleArgs{
_, err = client.Call(context.Background(), EthSendBundleMethod, &rpctypes.EthSendBundleArgs{
BlockNumber: 1000,
})
require.NoError(t, err)
Expand All @@ -271,12 +274,9 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
// add another peer
err = proxies[2].proxy.RegisterSecrets()
require.NoError(t, err)
proxiesUpdatePeers(t)

err = proxies[0].proxy.RequestNewPeers()
require.NoError(t, err)
time.Sleep(time.Millisecond * 50)

_, err = client.Call(context.Background(), SendBundleMethod, &rpctypes.EthSendBundleArgs{
_, err = client.Call(context.Background(), EthSendBundleMethod, &rpctypes.EthSendBundleArgs{
BlockNumber: 1000,
})
require.NoError(t, err)
Expand Down
18 changes: 9 additions & 9 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ func (prx *Proxy) GenerateAndPublish() error {

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

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

err = prx.Config.BuilderConfigHub.RegisterCredentials(selfInfo)
if err != nil {
return err
}
//selfInfo := ConfighubOrderflowProxyCredentials{
// TLSCert: string(cert),
// EcdsaPubkeyAddress: orderflowSigner,
//}

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

certificate, err := tls.X509KeyPair(cert, key)
if err != nil {
Expand Down
Loading

0 comments on commit 91e8a7a

Please sign in to comment.