Skip to content

Commit bfcb2b0

Browse files
authored
Merge pull request #193 from SozinM/msozin/add-bproxy-and-websocket-proxy
Add bproxy and websocket proxy
2 parents 6d91044 + 43cbbed commit bfcb2b0

File tree

3 files changed

+148
-9
lines changed

3 files changed

+148
-9
lines changed

playground/catalog.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func init() {
2525
register(&OpRbuilder{})
2626
register(&FlashblocksRPC{})
2727
register(&Contender{})
28+
register(&BProxy{})
29+
register(&WebsocketProxy{})
2830
}
2931

3032
func FindComponent(name string) ServiceGen {

playground/components.go

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"strconv"
8+
"strings"
89
"time"
910

1011
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -100,13 +101,35 @@ func (o *OpRbuilder) Name() string {
100101

101102
type FlashblocksRPC struct {
102103
FlashblocksWSService string
104+
BaseOverlay bool
105+
UseWebsocketProxy bool // Whether to add /ws path for websocket proxy
103106
}
104107

105108
func (f *FlashblocksRPC) Run(service *Service, ctx *ExContext) {
106-
service.WithImage("flashbots/flashblocks-rpc").
107-
WithTag("sha-7caffb9").
108-
WithArgs(
109-
"node",
109+
websocketURL := ConnectWs(f.FlashblocksWSService, "flashblocks")
110+
if f.UseWebsocketProxy {
111+
websocketURL += "/ws"
112+
}
113+
114+
if f.BaseOverlay {
115+
// Base doesn't have built image, so we use mikawamp/base-reth-node
116+
service.WithImage("docker.io/mikawamp/base-reth-node").
117+
WithTag("latest").
118+
WithEntrypoint("/app/base-reth-node").
119+
WithArgs(
120+
"node",
121+
"--websocket-url", websocketURL,
122+
)
123+
} else {
124+
service.WithImage("flashbots/flashblocks-rpc").
125+
WithTag("sha-7caffb9").
126+
WithArgs(
127+
"node",
128+
"--flashblocks.enabled",
129+
"--flashblocks.websocket-url", websocketURL,
130+
)
131+
}
132+
service.WithArgs(
110133
"--authrpc.port", `{{Port "authrpc" 8551}}`,
111134
"--authrpc.addr", "0.0.0.0",
112135
"--authrpc.jwtsecret", "/data/jwtsecret",
@@ -119,8 +142,6 @@ func (f *FlashblocksRPC) Run(service *Service, ctx *ExContext) {
119142
"--color", "never",
120143
"--metrics", `0.0.0.0:{{Port "metrics" 9090}}`,
121144
"--port", `{{Port "rpc" 30303}}`,
122-
"--flashblocks.enabled",
123-
"--flashblocks.websocket-url", ConnectWs(f.FlashblocksWSService, "flashblocks"),
124145
).
125146
WithArtifact("/data/jwtsecret", "jwtsecret").
126147
WithArtifact("/data/l2-genesis.json", "l2-genesis.json").
@@ -137,6 +158,73 @@ func (f *FlashblocksRPC) Name() string {
137158
return "flashblocks-rpc"
138159
}
139160

161+
type BProxy struct {
162+
TargetAuthrpc string
163+
Peers []string
164+
Flashblocks bool
165+
FlashblocksBuilderURL string
166+
}
167+
168+
func (f* BProxy) Run(service *Service, ctx *ExContext) {
169+
peers := []string{}
170+
for _, peer := range f.Peers {
171+
peers = append(peers, Connect(peer, "authrpc"))
172+
}
173+
service.WithImage("ghcr.io/flashbots/bproxy").
174+
WithTag("v0.0.91").
175+
WithArgs(
176+
"serve",
177+
"--authrpc-backend", f.TargetAuthrpc,
178+
"--authrpc-backend-timeout", "5s",
179+
"--authrpc-client-idle-connection-timeout", "15m",
180+
"--authrpc-deduplicate-fcus",
181+
"--authrpc-enabled",
182+
"--authrpc-listen-address", `0.0.0.0:{{Port "authrpc" 8651}}`,
183+
"--authrpc-log-requests",
184+
"--authrpc-log-responses",
185+
"--authrpc-max-backend-connections-per-host", "1",
186+
"--authrpc-max-request-size", "150",
187+
"--authrpc-max-response-size", "1150",
188+
"--authrpc-peers", strings.Join(peers, ","),
189+
"--authrpc-remove-backend-from-peers",
190+
"--authrpc-use-priority-queue",
191+
).
192+
WithArtifact("/data/jwtsecret", "jwtsecret")
193+
194+
if f.Flashblocks {
195+
service.WithArgs(
196+
"--flashblocks-backend", f.FlashblocksBuilderURL,
197+
"--flashblocks-enabled",
198+
"--flashblocks-listen-address", `0.0.0.0:{{Port "flashblocks" 1114}}`,
199+
"--flashblocks-log-messages",
200+
)
201+
}
202+
203+
}
204+
205+
func (f *BProxy) Name() string {
206+
return "bproxy"
207+
}
208+
209+
type WebsocketProxy struct {
210+
Upstream string
211+
}
212+
213+
func (w *WebsocketProxy) Run(service *Service, ctx *ExContext) {
214+
service.WithImage("docker.io/mikawamp/websocket-rpc").
215+
WithTag("latest").
216+
WithArgs(
217+
"--listen-addr", `0.0.0.0:{{Port "flashblocks" 1115}}`,
218+
"--upstream-ws", ConnectWs(w.Upstream, "flashblocks"),
219+
"--enable-compression",
220+
"--client-ping-enabled",
221+
)
222+
}
223+
224+
func (w *WebsocketProxy) Name() string {
225+
return "websocket-proxy"
226+
}
227+
140228
type OpBatcher struct {
141229
L1Node string
142230
L2Node string

playground/recipe_opstack.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ type OpRecipe struct {
3030
// flashblocksBuilderURL is the URL of the builder that returns the flashblocks. This is meant to be used
3131
// for external builders.
3232
flashblocksBuilderURL string
33+
34+
// Indicates that flashblocks-rpc should use base image
35+
baseOverlay bool
36+
37+
// whether to enable websocket proxy
38+
enableWebsocketProxy bool
3339
}
3440

3541
func (o *OpRecipe) Name() string {
@@ -47,7 +53,9 @@ func (o *OpRecipe) Flags() *flag.FlagSet {
4753
flags.Uint64Var(&o.blockTime, "block-time", defaultOpBlockTimeSeconds, "Block time to use for the rollup")
4854
flags.Uint64Var(&o.batcherMaxChannelDuration, "batcher-max-channel-duration", 2, "Maximum channel duration to use for the batcher")
4955
flags.BoolVar(&o.flashblocks, "flashblocks", false, "Whether to enable flashblocks")
56+
flags.BoolVar(&o.baseOverlay, "base-overlay", false, "Whether to use base implementation for flashblocks-rpc")
5057
flags.StringVar(&o.flashblocksBuilderURL, "flashblocks-builder", "", "External URL of builder flashblocks stream")
58+
flags.BoolVar(&o.enableWebsocketProxy, "enable-websocket-proxy", false, "Whether to enable websocket proxy")
5159
return flags
5260
}
5361

@@ -70,6 +78,7 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
7078

7179
flashblocksBuilderURLRef := o.flashblocksBuilderURL
7280
externalBuilderRef := o.externalBuilder
81+
peers := []string{}
7382

7483
opGeth := &OpGeth{}
7584
svcManager.AddService("op-geth", opGeth)
@@ -96,21 +105,61 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
96105
flashblocksBuilderURLRef = ConnectWs("op-rbuilder", "flashblocks")
97106
}
98107

108+
if o.flashblocks {
109+
peers = append(peers, "flashblocks-rpc")
110+
}
111+
112+
// Only enable bproxy if flashblocks is enabled (since flashblocks-rpc is the only service that needs it)
113+
if o.flashblocks {
114+
svcManager.AddService("bproxy", &BProxy{
115+
TargetAuthrpc: externalBuilderRef,
116+
Peers: peers,
117+
Flashblocks: o.flashblocks,
118+
FlashblocksBuilderURL: flashblocksBuilderURLRef,
119+
})
120+
}
121+
122+
// Only enable websocket-proxy if the flag is set
123+
if o.enableWebsocketProxy {
124+
svcManager.AddService("websocket-proxy", &WebsocketProxy{
125+
Upstream: "rollup-boost",
126+
})
127+
}
128+
99129
elNode := "op-geth"
100130
if o.externalBuilder != "" {
101131
elNode = "rollup-boost"
102132

133+
// Use bproxy if flashblocks is enabled, otherwise use external builder directly
134+
builderRef := externalBuilderRef
135+
flashblocksBuilderRef := flashblocksBuilderURLRef
136+
if o.flashblocks {
137+
builderRef = Connect("bproxy", "authrpc")
138+
flashblocksBuilderRef = ConnectWs("bproxy", "flashblocks")
139+
}
140+
103141
svcManager.AddService("rollup-boost", &RollupBoost{
104142
ELNode: "op-geth",
105-
Builder: externalBuilderRef,
143+
Builder: builderRef,
106144
Flashblocks: o.flashblocks,
107-
FlashblocksBuilderURL: flashblocksBuilderURLRef,
145+
FlashblocksBuilderURL: flashblocksBuilderRef,
108146
})
109147
}
110148

149+
111150
if o.flashblocks {
151+
// Determine which service to use for flashblocks websocket connection
152+
flashblocksWSService := "rollup-boost"
153+
useWebsocketProxy := false
154+
if o.enableWebsocketProxy {
155+
flashblocksWSService = "websocket-proxy"
156+
useWebsocketProxy = true
157+
}
158+
112159
svcManager.AddService("flashblocks-rpc", &FlashblocksRPC{
113-
FlashblocksWSService: "rollup-boost", // rollup-boost provides the websocket stream
160+
FlashblocksWSService: flashblocksWSService,
161+
BaseOverlay: o.baseOverlay,
162+
UseWebsocketProxy: useWebsocketProxy,
114163
})
115164
}
116165

0 commit comments

Comments
 (0)