Skip to content

Commit d43de09

Browse files
committed
fasthttp for sharing
1 parent cac0b4d commit d43de09

File tree

8 files changed

+202
-89
lines changed

8 files changed

+202
-89
lines changed

cmd/test-e2e-latency/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func main() {
7575
requests := cCtx.Int("num-requests")
7676

7777
return runE2ELatencyTest(client, receiverPort, senders, requests)
78-
7978
},
8079
}
8180

@@ -122,7 +121,7 @@ func (s *sharedState) ServeHTTP(w http.ResponseWriter, r *http.Request) {
122121
}
123122

124123
var request jsonRPCRequest
125-
err = json.Unmarshal(body, &request)
124+
err := json.Unmarshal(body, &request)
126125
if err != nil {
127126
return
128127
}
@@ -135,7 +134,6 @@ func (s *sharedState) ServeHTTP(w http.ResponseWriter, r *http.Request) {
135134
s.mu.Lock()
136135
s.receivedAt[decoded] = receivedAt
137136
s.mu.Unlock()
138-
139137
}
140138

141139
func (s *sharedState) RunSender(client rpcclient.RPCClient, start, count int, wg *sync.WaitGroup) {
@@ -163,7 +161,7 @@ func (s *sharedState) RunSender(client rpcclient.RPCClient, start, count int, wg
163161
}
164162
}
165163

166-
func runE2ELatencyTest(client rpcclient.RPCClient, receiverPort int, senders, requests int) error {
164+
func runE2ELatencyTest(client rpcclient.RPCClient, receiverPort, senders, requests int) error {
167165
state := &sharedState{
168166
sentAt: make(map[uint64]time.Time),
169167
receivedAt: make(map[uint64]time.Time),

go.mod

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ require (
99
github.com/cenkalti/backoff v2.2.1+incompatible
1010
github.com/ethereum/go-ethereum v1.15.5
1111
github.com/flashbots/go-utils v0.14.0
12+
github.com/goccy/go-json v0.10.5
1213
github.com/google/uuid v1.6.0
1314
github.com/hashicorp/golang-lru/v2 v2.0.7
1415
github.com/stretchr/testify v1.10.0
1516
github.com/urfave/cli/v2 v2.27.5
16-
golang.org/x/net v0.34.0
17+
github.com/valyala/fasthttp v1.62.0
18+
golang.org/x/net v0.40.0
1719
golang.org/x/time v0.9.0
1820
)
1921

2022
require (
23+
github.com/andybalholm/brotli v1.1.1 // indirect
2124
github.com/bits-and-blooms/bitset v1.17.0 // indirect
2225
github.com/consensys/bavard v0.1.22 // indirect
2326
github.com/consensys/gnark-crypto v0.14.0 // indirect
@@ -28,19 +31,20 @@ require (
2831
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
2932
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
3033
github.com/ethereum/go-verkle v0.2.2 // indirect
31-
github.com/goccy/go-json v0.10.5 // indirect
3234
github.com/holiman/uint256 v1.3.2 // indirect
35+
github.com/klauspost/compress v1.18.0 // indirect
3336
github.com/mmcloughlin/addchain v0.4.0 // indirect
3437
github.com/pmezard/go-difflib v1.0.0 // indirect
3538
github.com/russross/blackfriday/v2 v2.1.0 // indirect
3639
github.com/supranational/blst v0.3.14 // indirect
40+
github.com/valyala/bytebufferpool v1.0.0 // indirect
3741
github.com/valyala/fastrand v1.1.0 // indirect
3842
github.com/valyala/histogram v1.2.0 // indirect
3943
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
40-
golang.org/x/crypto v0.32.0 // indirect
41-
golang.org/x/sync v0.10.0 // indirect
42-
golang.org/x/sys v0.29.0 // indirect
43-
golang.org/x/text v0.21.0 // indirect
44+
golang.org/x/crypto v0.38.0 // indirect
45+
golang.org/x/sync v0.14.0 // indirect
46+
golang.org/x/sys v0.33.0 // indirect
47+
golang.org/x/text v0.25.0 // indirect
4448
gopkg.in/yaml.v3 v3.0.1 // indirect
4549
rsc.io/tmplfunc v0.0.3 // indirect
4650
)

go.sum

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjC
44
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
55
github.com/VictoriaMetrics/metrics v1.35.1 h1:o84wtBKQbzLdDy14XeskkCZih6anG+veZ1SwJHFGwrU=
66
github.com/VictoriaMetrics/metrics v1.35.1/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8=
7+
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
8+
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
79
github.com/bits-and-blooms/bitset v1.17.0 h1:1X2TS7aHz1ELcC0yU1y2stUs/0ig5oMU6STFZGrhvHI=
810
github.com/bits-and-blooms/bitset v1.17.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
911
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
@@ -49,6 +51,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
4951
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
5052
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
5153
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
54+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
55+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
5256
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
5357
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
5458
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -84,22 +88,28 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F
8488
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
8589
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
8690
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
91+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
92+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
93+
github.com/valyala/fasthttp v1.62.0 h1:8dKRBX/y2rCzyc6903Zu1+3qN0H/d2MsxPPmVNamiH0=
94+
github.com/valyala/fasthttp v1.62.0/go.mod h1:FCINgr4GKdKqV8Q0xv8b+UxPV+H/O5nNFo3D+r54Htg=
8795
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
8896
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
8997
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
9098
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
9199
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
92100
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
93-
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
94-
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
95-
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
96-
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
97-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
98-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
99-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
100-
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
101-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
102-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
101+
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
102+
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
103+
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
104+
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
105+
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
106+
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
107+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
108+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
109+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
110+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
111+
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
112+
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
103113
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
104114
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
105115
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

proxy/receiver_api.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ type ParsedRequest struct {
374374
ethCancelBundle *rpctypes.EthCancelBundleArgs
375375
ethSendRawTransaction *rpctypes.EthSendRawTransactionArgs
376376
bidSubsidiseBlock *rpctypes.BidSubsisideBlockArgs
377+
378+
serializedJSONRPCRequest []byte
379+
signatureHeader string
377380
}
378381

379382
func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest ParsedRequest) error {
@@ -408,6 +411,14 @@ func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest
408411
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "rate_limiting")
409412
startAt = time.Now()
410413

414+
err := SerializeParsedRequestForSharing(&parsedRequest, prx.OrderflowSigner)
415+
if err != nil {
416+
prx.Log.Warn("Failed to serialize request for sharing", slog.Any("error", err))
417+
}
418+
419+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "serialize_parsed_request")
420+
startAt = time.Now()
421+
411422
select {
412423
case <-ctx.Done():
413424
prx.Log.Error("Shared queue is stalling")

proxy/receiver_proxy.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ func NewReceiverProxy(config ReceiverProxyConfig) (*ReceiverProxy, error) {
136136
updatePeersCh := make(chan []ConfighubBuilder)
137137
prx.shareQueue = shareQeueuCh
138138
prx.updatePeers = updatePeersCh
139+
139140
queue := ShareQueue{
140-
name: prx.Name,
141-
log: prx.Log,
142-
queue: shareQeueuCh,
143-
updatePeers: updatePeersCh,
144-
localBuilder: prx.localBuilder,
145-
signer: prx.OrderflowSigner,
146-
workersPerPeer: config.ConnectionsPerPeer,
141+
name: prx.Name,
142+
log: prx.Log,
143+
queue: shareQeueuCh,
144+
updatePeers: updatePeersCh,
145+
localBuilderEndpoint: config.LocalBuilderEndpoint,
146+
signer: prx.OrderflowSigner,
147+
workersPerPeer: config.ConnectionsPerPeer,
147148
}
148149
go queue.Run()
149150

proxy/sender_proxy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func NewSenderProxy(config SenderProxyConfig) (*SenderProxy, error) {
7070
log: prx.Log,
7171
queue: prx.shareQueue,
7272
updatePeers: prx.updatePeers,
73-
localBuilder: nil,
7473
signer: prx.OrderflowSigner,
7574
workersPerPeer: config.ConnectionsPerPeer,
7675
}

0 commit comments

Comments
 (0)