Skip to content

Commit d93016d

Browse files
authored
receiver proxy properly registers signing address (#51)
## πŸ“ Summary <!--- A general summary of your changes --> ## β›± Motivation and Context <!--- Why is this change required? What problem does it solve? --> ## πŸ“š References <!-- Any interesting external links to documentation, articles, tweets which add value to the PR --> --- ## βœ… I have run these commands * [ ] `make lint` * [ ] `make test` * [ ] `go mod tidy`
1 parent 451a6a3 commit d93016d

File tree

4 files changed

+94
-20
lines changed

4 files changed

+94
-20
lines changed

β€Žcmd/receiver-proxy/main.goβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ func runMain(cCtx *cli.Context) error {
239239
}
240240
}()
241241

242+
err = instance.RegisterSecrets(registerContext)
243+
registerCancel()
244+
if err != nil {
245+
log.Error("Failed to publish secrets", "err", err)
246+
return err
247+
}
248+
242249
userListenAddr := cCtx.String(flagUserListenAddr)
243250
systemListenAddr := cCtx.String(flagSystemListenAddr)
244251

β€Žproxy/confighub.goβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
type ConfighubOrderflowProxyCredentials struct {
17-
TLSCert string `json:"tls_cert"` // for backward compatibility
17+
TLSCert string `json:"tls_cert,omitempty"` // for backward compatibility
1818
EcdsaPubkeyAddress common.Address `json:"ecdsa_pubkey_address"`
1919
}
2020

β€Žproxy/receiver_proxy.goβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package proxy
22

33
import (
4+
"context"
45
"log/slog"
56
"net/http"
67
"sync"
@@ -216,3 +217,34 @@ func (prx *ReceiverProxy) RequestNewPeers() error {
216217
func (prx *ReceiverProxy) FlushArchiveQueue() {
217218
prx.archiveFlushQueue <- struct{}{}
218219
}
220+
221+
func (prx *ReceiverProxy) RegisterSecrets(ctx context.Context) error {
222+
const maxRetries = 10
223+
const timeBetweenRetries = time.Second * 10
224+
225+
retry := 0
226+
for {
227+
if ctx.Err() != nil {
228+
return ctx.Err()
229+
}
230+
err := prx.ConfigHub.RegisterCredentials(ctx, ConfighubOrderflowProxyCredentials{
231+
TLSCert: "",
232+
EcdsaPubkeyAddress: prx.OrderflowSigner.Address(),
233+
})
234+
if err == nil {
235+
prx.Log.Info("Credentials registered on config hub")
236+
return nil
237+
}
238+
239+
retry += 1
240+
if retry >= maxRetries {
241+
return err
242+
}
243+
prx.Log.Error("Fail to register credentials", slog.Any("error", err))
244+
select {
245+
case <-ctx.Done():
246+
return ctx.Err()
247+
case <-time.After(timeBetweenRetries):
248+
}
249+
}
250+
}

β€Žproxy/receiver_proxy_test.goβ€Ž

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,34 @@ var (
4444
flashbotsSigner *signature.Signer
4545
)
4646

47-
func testAddBuilderhubPeer(proxyIndex int) {
47+
func testAddBuilderhubPeer(t *testing.T, proxyIndex int) {
48+
t.Helper()
4849
proxy := proxies[proxyIndex]
4950

51+
// first we ask proxy to register its own credentials on the builderhub (its will register signign key address)
52+
err := proxy.proxy.RegisterSecrets(context.Background())
53+
if err != nil {
54+
t.Fatal("Failed to register secret", err)
55+
}
56+
57+
// next we add instance data for a valid TLS certificate
5058
ip := proxy.ip
5159
name := proxy.proxy.Name
5260

53-
req := ConfighubOrderflowProxyCredentials{
54-
EcdsaPubkeyAddress: proxy.proxy.OrderflowSigner.Address(),
61+
index := -1
62+
for i, peer := range builderHubPeers {
63+
if peer.Name == name && peer.IP == ip {
64+
index = i
65+
break
66+
}
67+
}
68+
if index == -1 {
69+
t.Fatal("Peer is not properly registered on the builerhub")
5570
}
5671

57-
builderHubPeers = append(builderHubPeers, ConfighubBuilder{
58-
Name: name,
59-
DNSName: ip,
60-
OrderflowProxy: req,
61-
Instance: ConfighubInstanceData{
62-
TLSCert: string(proxy.PublicCertPEM),
63-
},
64-
})
72+
builderHubPeers[index].Instance = ConfighubInstanceData{
73+
TLSCert: string(proxy.PublicCertPEM),
74+
}
6575
}
6676

6777
func ServeHTTPRequestToChan(channel chan *RequestData) *httptest.Server {
@@ -168,7 +178,32 @@ func TestMain(m *testing.M) {
168178

169179
archiveServerRequests = make(chan *RequestData)
170180
builderHub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
171-
if r.URL.Path == "/api/l1-builder/v1/builders" {
181+
body, _ := io.ReadAll(r.Body)
182+
183+
if r.URL.Path == "/api/l1-builder/v1/register_credentials/orderflow_proxy" {
184+
var req ConfighubOrderflowProxyCredentials
185+
err := json.Unmarshal(body, &req)
186+
if err != nil {
187+
w.WriteHeader(http.StatusBadRequest)
188+
_, _ = w.Write([]byte(err.Error()))
189+
}
190+
var (
191+
ip string
192+
name string
193+
)
194+
for _, proxy := range proxies {
195+
if proxy.proxy.OrderflowSigner.Address() == req.EcdsaPubkeyAddress {
196+
ip = proxy.ip
197+
name = proxy.proxy.Name
198+
break
199+
}
200+
}
201+
builderHubPeers = append(builderHubPeers, ConfighubBuilder{
202+
Name: name,
203+
IP: ip,
204+
OrderflowProxy: req,
205+
})
206+
} else if r.URL.Path == "/api/l1-builder/v1/builders" {
172207
res, err := json.Marshal(builderHubPeers)
173208
if err != nil {
174209
panic(err)
@@ -294,7 +329,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
294329

295330
// we start with no peers
296331
builderHubPeers = nil
297-
testAddBuilderhubPeer(0)
332+
testAddBuilderhubPeer(t, 0)
298333
proxiesUpdatePeers(t)
299334

300335
blockNumber := hexutil.Uint64(1000)
@@ -312,7 +347,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
312347
slog.Info("Adding first peer")
313348

314349
// add one more peer
315-
testAddBuilderhubPeer(1)
350+
testAddBuilderhubPeer(t, 1)
316351
proxiesUpdatePeers(t)
317352

318353
blockNumber = hexutil.Uint64(1001)
@@ -331,7 +366,7 @@ func TestProxyBundleRequestWithPeerUpdate(t *testing.T) {
331366
// add another peer
332367
slog.Info("Adding second peer")
333368

334-
testAddBuilderhubPeer(2)
369+
testAddBuilderhubPeer(t, 2)
335370
proxiesUpdatePeers(t)
336371

337372
blockNumber = hexutil.Uint64(1002)
@@ -375,7 +410,7 @@ func TestProxySendToArchive(t *testing.T) {
375410

376411
// we start with no peers
377412
builderHubPeers = nil
378-
testAddBuilderhubPeer(0)
413+
testAddBuilderhubPeer(t, 0)
379414
proxiesUpdatePeers(t)
380415

381416
apiNow = func() time.Time {
@@ -458,7 +493,7 @@ func TestProxyShareBundleReplacementUUIDAndCancellation(t *testing.T) {
458493

459494
// we start with no peers
460495
builderHubPeers = nil
461-
testAddBuilderhubPeer(0)
496+
testAddBuilderhubPeer(t, 0)
462497
proxiesUpdatePeers(t)
463498

464499
// first call
@@ -538,7 +573,7 @@ func TestProxyBidSubsidiseBlockCall(t *testing.T) {
538573
// we add all proxies to the list of peers
539574
builderHubPeers = nil
540575
for i := range proxies {
541-
testAddBuilderhubPeer(i)
576+
testAddBuilderhubPeer(t, i)
542577
}
543578
proxiesUpdatePeers(t)
544579

@@ -564,7 +599,7 @@ func TestValidateLocalBundles(t *testing.T) {
564599

565600
// we start with no peers
566601
builderHubPeers = nil
567-
testAddBuilderhubPeer(0)
602+
testAddBuilderhubPeer(t, 0)
568603
proxiesUpdatePeers(t)
569604

570605
apiNow = func() time.Time {

0 commit comments

Comments
Β (0)