Skip to content

Commit a487a05

Browse files
authored
Add Flashblocks rpc (#179)
* Add Flashblocks rpc * More fixes?
1 parent b44f9a3 commit a487a05

File tree

5 files changed

+105
-26
lines changed

5 files changed

+105
-26
lines changed

main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var withPrometheus bool
2929
var networkName string
3030
var labels playground.MapStringFlag
3131
var disableLogs bool
32+
var platform string
3233

3334
var rootCmd = &cobra.Command{
3435
Use: "playground",
@@ -177,6 +178,7 @@ func main() {
177178
recipeCmd.Flags().StringVar(&networkName, "network", "", "network name")
178179
recipeCmd.Flags().Var(&labels, "labels", "list of labels to apply to the resources")
179180
recipeCmd.Flags().BoolVar(&disableLogs, "disable-logs", false, "disable logs")
181+
recipeCmd.Flags().StringVar(&platform, "platform", "", "docker platform to use")
180182

181183
cookCmd.AddCommand(recipeCmd)
182184
}
@@ -255,7 +257,18 @@ func runIt(recipe playground.Recipe) error {
255257
}
256258
}
257259

258-
dockerRunner, err := playground.NewLocalRunner(artifacts.Out, svcManager, overrides, interactive, !bindExternal, networkName, labels, !disableLogs)
260+
cfg := &playground.RunnerConfig{
261+
Out: artifacts.Out,
262+
Manifest: svcManager,
263+
Overrides: overrides,
264+
Interactive: interactive,
265+
BindHostPortsLocally: !bindExternal,
266+
NetworkName: networkName,
267+
Labels: labels,
268+
LogInternally: !disableLogs,
269+
Platform: platform,
270+
}
271+
dockerRunner, err := playground.NewLocalRunner(cfg)
259272
if err != nil {
260273
return fmt.Errorf("failed to create docker runner: %w", err)
261274
}

playground/catalog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func init() {
2222
register(&BuilderHubMockProxy{})
2323
register(&nullService{})
2424
register(&OpRbuilder{})
25+
register(&FlashblocksRPC{})
2526
}
2627

2728
func FindComponent(name string) ServiceGen {

playground/components.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,45 @@ func (o *OpRbuilder) Name() string {
9393
return "op-rbuilder"
9494
}
9595

96+
type FlashblocksRPC struct {
97+
FlashblocksWSService string
98+
}
99+
100+
func (f *FlashblocksRPC) Run(service *Service, ctx *ExContext) {
101+
service.WithImage("flashbots/flashblocks-rpc").
102+
WithTag("sha-7caffb9").
103+
WithArgs(
104+
"node",
105+
"--authrpc.port", `{{Port "authrpc" 8551}}`,
106+
"--authrpc.addr", "0.0.0.0",
107+
"--authrpc.jwtsecret", "/data/jwtsecret",
108+
"--http",
109+
"--http.addr", "0.0.0.0",
110+
"--http.port", `{{Port "http" 8545}}`,
111+
"--chain", "/data/l2-genesis.json",
112+
"--datadir", "/data_op_reth",
113+
"--disable-discovery",
114+
"--color", "never",
115+
"--metrics", `0.0.0.0:{{Port "metrics" 9090}}`,
116+
"--port", `{{Port "rpc" 30303}}`,
117+
"--flashblocks.enabled",
118+
"--flashblocks.websocket-url", ConnectWs(f.FlashblocksWSService, "flashblocks"),
119+
).
120+
WithArtifact("/data/jwtsecret", "jwtsecret").
121+
WithArtifact("/data/l2-genesis.json", "l2-genesis.json").
122+
WithVolume("data", "/data_flashblocks_rpc")
123+
124+
if ctx.Bootnode != nil {
125+
service.WithArgs(
126+
"--trusted-peers", ctx.Bootnode.Connect(),
127+
)
128+
}
129+
}
130+
131+
func (f *FlashblocksRPC) Name() string {
132+
return "flashblocks-rpc"
133+
}
134+
96135
type OpBatcher struct {
97136
L1Node string
98137
L2Node string

playground/local_runner.go

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ type LocalRunner struct {
8080

8181
// logInternally outputs the logs of the service to the artifacts folder
8282
logInternally bool
83+
84+
// platform is the docker platform to use for the services
85+
platform string
8386
}
8487

8588
type task struct {
@@ -109,24 +112,35 @@ func newDockerClient() (*client.Client, error) {
109112
return client, nil
110113
}
111114

112-
// TODO: add a runner config struct
113-
func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string, interactive bool, bindHostPortsLocally bool, networkName string, labels map[string]string, logInternally bool) (*LocalRunner, error) {
115+
type RunnerConfig struct {
116+
Out *output
117+
Manifest *Manifest
118+
Overrides map[string]string
119+
Interactive bool
120+
BindHostPortsLocally bool
121+
NetworkName string
122+
Labels map[string]string
123+
LogInternally bool
124+
Platform string
125+
}
126+
127+
func NewLocalRunner(cfg *RunnerConfig) (*LocalRunner, error) {
114128
client, err := newDockerClient()
115129
if err != nil {
116130
return nil, fmt.Errorf("failed to create docker client: %w", err)
117131
}
118132

119133
// merge the overrides with the manifest overrides
120-
if overrides == nil {
121-
overrides = make(map[string]string)
134+
if cfg.Overrides == nil {
135+
cfg.Overrides = make(map[string]string)
122136
}
123-
for k, v := range manifest.overrides {
124-
overrides[k] = v
137+
for k, v := range cfg.Manifest.overrides {
138+
cfg.Overrides[k] = v
125139
}
126140

127141
// Create the concrete instances to run
128142
instances := []*instance{}
129-
for _, service := range manifest.Services {
143+
for _, service := range cfg.Manifest.Services {
130144
component := FindComponent(service.ComponentName)
131145
if component == nil {
132146
return nil, fmt.Errorf("component not found '%s'", service.ComponentName)
@@ -135,8 +149,8 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
135149
service: service,
136150
component: component,
137151
}
138-
if logInternally {
139-
log_output, err := out.LogOutput(service.Name)
152+
if cfg.LogInternally {
153+
log_output, err := cfg.Out.LogOutput(service.Name)
140154
if err != nil {
141155
return nil, fmt.Errorf("error getting log output: %w", err)
142156
}
@@ -160,11 +174,11 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
160174
return nil, fmt.Errorf("service '%s' must implement the ReleaseService interface", ss.Name)
161175
}
162176
releaseArtifact := releaseService.ReleaseArtifact()
163-
bin, err := DownloadRelease(out.homeDir, releaseArtifact)
177+
bin, err := DownloadRelease(cfg.Out.homeDir, releaseArtifact)
164178
if err != nil {
165179
return nil, fmt.Errorf("failed to download release artifact for service '%s': %w", ss.Name, err)
166180
}
167-
overrides[ss.Name] = bin
181+
cfg.Overrides[ss.Name] = bin
168182
}
169183
}
170184

@@ -173,7 +187,7 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
173187
// - a path to an executable: In that case, we need to run it on the host machine
174188
// and use the override map <- We only check this case, and if it is not a path, we assume
175189
// it is a docker image. If it is not a docker image either, the error will be catched during the execution
176-
for k, v := range overrides {
190+
for k, v := range cfg.Overrides {
177191
if _, err := os.Stat(v); err != nil {
178192
// this is a path to an executable, remove it from the overrides since we
179193
// assume it s a docker image and add it to manifest
@@ -182,45 +196,46 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
182196
return nil, fmt.Errorf("invalid override docker image %s, expected image:tag", v)
183197
}
184198

185-
srv := manifest.MustGetService(k)
199+
srv := cfg.Manifest.MustGetService(k)
186200
srv.Image = parts[0]
187201
srv.Tag = parts[1]
188202

189-
delete(overrides, k)
203+
delete(cfg.Overrides, k)
190204
continue
191205
}
192206
}
193207

194208
tasks := map[string]*task{}
195-
for _, svc := range manifest.Services {
209+
for _, svc := range cfg.Manifest.Services {
196210
tasks[svc.Name] = &task{
197211
status: taskStatusPending,
198212
logs: nil,
199213
}
200214
}
201215

202-
if networkName == "" {
203-
networkName = defaultNetworkName
216+
if cfg.NetworkName == "" {
217+
cfg.NetworkName = defaultNetworkName
204218
}
205219
d := &LocalRunner{
206-
out: out,
207-
manifest: manifest,
220+
out: cfg.Out,
221+
manifest: cfg.Manifest,
208222
client: client,
209223
reservedPorts: map[int]bool{},
210-
overrides: overrides,
224+
overrides: cfg.Overrides,
211225
handles: []*exec.Cmd{},
212226
tasks: tasks,
213227
taskUpdateCh: make(chan struct{}),
214228
exitErr: make(chan error, 2),
215-
bindHostPortsLocally: bindHostPortsLocally,
229+
bindHostPortsLocally: cfg.BindHostPortsLocally,
216230
sessionID: uuid.New().String(),
217-
networkName: networkName,
231+
networkName: cfg.NetworkName,
218232
instances: instances,
219-
labels: labels,
220-
logInternally: logInternally,
233+
labels: cfg.Labels,
234+
logInternally: cfg.LogInternally,
235+
platform: cfg.Platform,
221236
}
222237

223-
if interactive {
238+
if cfg.Interactive {
224239
go d.printStatus()
225240

226241
select {
@@ -656,6 +671,10 @@ func (d *LocalRunner) toDockerComposeService(s *Service) (map[string]interface{}
656671
"labels": labels,
657672
}
658673

674+
if d.platform != "" {
675+
service["platform"] = d.platform
676+
}
677+
659678
if len(envs) > 0 {
660679
service["environment"] = envs
661680
}

playground/recipe_opstack.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ func (o *OpRecipe) Apply(ctx *ExContext, artifacts *Artifacts) *Manifest {
106106
FlashblocksBuilderURL: flashblocksBuilderURLRef,
107107
})
108108
}
109+
110+
if o.flashblocks {
111+
svcManager.AddService("flashblocks-rpc", &FlashblocksRPC{
112+
FlashblocksWSService: "rollup-boost", // rollup-boost provides the websocket stream
113+
})
114+
}
115+
109116
svcManager.AddService("op-node", &OpNode{
110117
L1Node: "el",
111118
L1Beacon: "beacon",

0 commit comments

Comments
 (0)