Skip to content

Commit 472899d

Browse files
fkondejcanercidam
andauthored
Add mkosi flashbots-images VM to playground (#302)
Co-authored-by: Caner Çıdam <canercidam01@gmail.com>
1 parent 75cd558 commit 472899d

24 files changed

+669
-50
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/charmbracelet/lipgloss v1.0.0
1010
github.com/docker/docker v28.0.1+incompatible
1111
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0
12-
github.com/ethereum/go-ethereum v1.16.3
12+
github.com/ethereum/go-ethereum v1.16.8
1313
github.com/fatih/color v1.18.0
1414
github.com/flashbots/go-boost-utils v1.9.1-0.20250819134059-e5294cb450c9
1515
github.com/flashbots/go-template v1.0.0
@@ -79,7 +79,7 @@ require (
7979
github.com/goccy/go-json v0.10.4 // indirect
8080
github.com/gofrs/flock v0.12.1 // indirect
8181
github.com/gogo/protobuf v1.3.2 // indirect
82-
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
82+
github.com/golang/snappy v1.0.0 // indirect
8383
github.com/google/go-cmp v0.7.0 // indirect
8484
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 // indirect
8585
github.com/google/uuid v1.6.0 // indirect
@@ -170,7 +170,7 @@ require (
170170
golang.org/x/sys v0.38.0 // indirect
171171
golang.org/x/term v0.37.0 // indirect
172172
golang.org/x/text v0.31.0 // indirect
173-
golang.org/x/time v0.11.0 // indirect
173+
golang.org/x/time v0.9.0 // indirect
174174
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
175175
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
176176
google.golang.org/grpc v1.71.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
202202
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
203203
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
204204
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
205-
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e h1:4bw4WeyTYPp0smaXiJZCNnLrvVBqirQVreixayXezGc=
206-
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
205+
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
206+
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
207207
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
208208
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
209209
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -567,8 +567,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
567567
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
568568
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
569569
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
570-
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
571-
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
570+
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
571+
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
572572
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
573573
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
574574
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=

playground/artifacts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ var opStateJovian []byte
6868
//go:embed config.yaml.tmpl
6969
var clConfigContent []byte
7070

71+
//go:embed utils/builderhub-config.yaml
72+
var defaultBuilderHubConfig []byte
73+
7174
// l2ForkConfig holds the selected L2 fork configuration files
7275
type l2ForkConfig struct {
7376
genesis []byte // L2 genesis JSON
@@ -249,6 +252,7 @@ func (b *ArtifactsBuilder) Build(out *output) error {
249252

250253
genesisTime := time.Now().Add(time.Duration(b.genesisDelay) * time.Second)
251254
config := params.BeaconConfig()
255+
config.ElectraForkEpoch = 0
252256

253257
gen := interop.GethTestnetGenesis(genesisTime, config)
254258
// HACK: fix this in prysm?

playground/components.go

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
mevboostrelay "github.com/flashbots/builder-playground/mev-boost-relay"
1414
"github.com/flashbots/go-boost-utils/bls"
1515
"github.com/flashbots/go-boost-utils/utils"
16+
"github.com/goccy/go-yaml"
1617
)
1718

1819
var (
@@ -547,7 +548,9 @@ func (l *LighthouseBeaconNode) Apply(ctx *ExContext) *Component {
547548
"--http-address", "0.0.0.0",
548549
"--http-allow-origin", "*",
549550
"--disable-packet-filter",
550-
"--target-peers", "0",
551+
"--target-peers", "1",
552+
//"--target-peers", "0",
553+
"--subscribe-all-subnets",
551554
"--execution-endpoint", Connect(l.ExecutionNode, "authrpc"),
552555
"--execution-jwt", "/data/jwtsecret",
553556
"--always-prepare-payload",
@@ -558,7 +561,8 @@ func (l *LighthouseBeaconNode) Apply(ctx *ExContext) *Component {
558561
WithArtifact("/data/jwtsecret", "jwtsecret").
559562
WithVolume("data", "/data_beacon")
560563

561-
UseHealthmon(component, svc, healthmonBeacon)
564+
// TODO: Enable later - doesn't work with --target-peers=1 which is required for builder VM
565+
//UseHealthmon(component, svc, healthmonBeacon)
562566

563567
if l.MevBoostNode != "" {
564568
svc.WithArgs(
@@ -635,7 +639,8 @@ func (m *MevBoostRelay) Apply(ctx *ExContext) *Component {
635639
WithTag(latestPlaygroundUtilsTag).
636640
WithEnv("ALLOW_SYNCING_BEACON_NODE", "1").
637641
WithEntrypoint("mev-boost-relay").
638-
DependsOnHealthy(m.BeaconClient).
642+
// TODO: Enable later - doesn't work when beacon healthmon is disabled.
643+
//DependsOnHealthy(m.BeaconClient).
639644
WithArgs(
640645
"--api-listen-addr", "0.0.0.0",
641646
"--api-listen-port", `{{Port "http" 5555}}`,
@@ -942,8 +947,8 @@ func (b *BuilderHub) Apply(ctx *ExContext) *Component {
942947
StartPeriod: 2 * time.Second,
943948
})
944949

945-
// API service
946-
apiSrv := component.NewService("builder-hub-api").
950+
// API service
951+
component.NewService("builder-hub-api").
947952
WithImage("docker.io/flashbots/builder-hub").
948953
WithTag("0.3.1-alpha1").
949954
DependsOnHealthy("builder-hub-db").
@@ -965,15 +970,14 @@ func (b *BuilderHub) Apply(ctx *ExContext) *Component {
965970
Timeout: 30 * time.Second,
966971
Retries: 3,
967972
StartPeriod: 1 * time.Second,
973+
}).
974+
WithPostHook(&postHook{
975+
Name: "register-builder",
976+
Action: func(m *Manifest, s *Service) error {
977+
return registerBuilderHook(ctx, m, s, b)
978+
},
968979
})
969980

970-
apiSrv.WithPostHook(&postHook{
971-
Name: "register-builder",
972-
Action: func(s *Service) error {
973-
return registerBuilderHook(ctx, s, b)
974-
},
975-
})
976-
977981
// Proxy service
978982
component.NewService("builder-hub-proxy").
979983
WithImage("docker.io/flashbots/builder-hub-mock-proxy").
@@ -992,14 +996,33 @@ func (b *BuilderHub) Apply(ctx *ExContext) *Component {
992996
return component
993997
}
994998

995-
func registerBuilderHook(ctx *ExContext, s *Service, b *BuilderHub) error {
999+
type builderHubConfig struct {
1000+
Playground struct {
1001+
BuilderHubConfig struct {
1002+
BuilderID string `yaml:"builder_id"`
1003+
BuilderIP string `yaml:"builder_ip"`
1004+
MeasurementID string `yaml:"measurement_id"`
1005+
Network string `yaml:"network"`
1006+
} `yaml:"builder_hub_config"`
1007+
} `yaml:"playground"`
1008+
}
1009+
1010+
func registerBuilderHook(ctx *ExContext, manifest *Manifest, s *Service, b *BuilderHub) error {
9961011
genesis, err := ctx.Output.Read("genesis.json")
9971012
if err != nil {
9981013
return err
9991014
}
10001015

1001-
configYaml, err := os.ReadFile(b.BuilderConfig)
1002-
if err != nil {
1016+
configYaml := defaultBuilderHubConfig
1017+
if len(b.BuilderConfig) > 0 {
1018+
configYaml, err = os.ReadFile(b.BuilderConfig)
1019+
if err != nil {
1020+
return err
1021+
}
1022+
}
1023+
1024+
var config builderHubConfig
1025+
if err := yaml.Unmarshal([]byte(configYaml), &config); err != nil {
10031026
return err
10041027
}
10051028

@@ -1016,15 +1039,17 @@ func registerBuilderHook(ctx *ExContext, s *Service, b *BuilderHub) error {
10161039
return err
10171040
}
10181041

1019-
endpoint := fmt.Sprintf("http://localhost:%d", s.MustGetPort("admin").HostPort)
10201042
input := &builderHubRegisterBuilderInput{
1021-
BuilderID: "builder",
1022-
BuilderIP: b.BuilderIP,
1023-
MeasurementID: "test",
1024-
Network: "playground",
1043+
BuilderID: config.Playground.BuilderHubConfig.BuilderID,
1044+
BuilderIP: config.Playground.BuilderHubConfig.BuilderIP,
1045+
MeasurementID: config.Playground.BuilderHubConfig.MeasurementID,
1046+
Network: config.Playground.BuilderHubConfig.Network,
10251047
Config: string(configJSON),
10261048
}
1027-
if err := registerBuilder(endpoint, input); err != nil {
1049+
adminApi := fmt.Sprintf("http://localhost:%d", manifest.MustGetService("builder-hub-api").MustGetPort("admin").HostPort)
1050+
beaconApi := fmt.Sprintf("http://localhost:%d", manifest.MustGetService("beacon").MustGetPort("http").HostPort)
1051+
rethApi := fmt.Sprintf("http://localhost:%d", manifest.MustGetService("el").MustGetPort("http").HostPort)
1052+
if err := registerBuilder(adminApi, beaconApi, rethApi, input); err != nil {
10281053
return err
10291054
}
10301055
return nil
@@ -1052,3 +1077,25 @@ func UseHealthmon(component *Component, s *Service, chain string) {
10521077
StartPeriod: 1 * time.Second,
10531078
})
10541079
}
1080+
1081+
// Fileserver serves genesis and testnet files over HTTP using Caddy.
1082+
// This allows VMs or external clients to fetch configuration files.
1083+
type Fileserver struct{}
1084+
1085+
func (f *Fileserver) Apply(ctx *ExContext) *Component {
1086+
component := NewComponent("fileserver")
1087+
1088+
component.NewService("server").
1089+
WithImage("caddy").
1090+
WithTag("2-alpine").
1091+
WithArgs(
1092+
"caddy", "file-server",
1093+
"--root", "/data",
1094+
"--listen", `:{{Port "http" 8100}}`,
1095+
"--browse",
1096+
).
1097+
WithArtifact("/data/genesis.json", "genesis.json").
1098+
WithArtifact("/data/testnet", "testnet")
1099+
1100+
return component
1101+
}

playground/components_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestRecipeBuilderHub_RegisterBuilder(t *testing.T) {
192192
apiPort := manifest.MustGetService("builder-hub-api").MustGetPort("admin")
193193
endpoint := fmt.Sprintf("http://localhost:%d", apiPort.HostPort)
194194

195-
err := registerBuilder(endpoint, &builderHubRegisterBuilderInput{
195+
err := registerBuilder(endpoint, "", "", &builderHubRegisterBuilderInput{
196196
BuilderID: "test_builder",
197197
BuilderIP: "1.2.3.4",
198198
MeasurementID: "test",

playground/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func (s *Service) WithReady(check ReadyCheck) *Service {
539539

540540
type postHook struct {
541541
Name string
542-
Action func(s *Service) error
542+
Action func(m *Manifest, s *Service) error
543543
}
544544

545545
func (s *Service) WithPostHook(hook *postHook) *Service {
@@ -551,7 +551,7 @@ func (m *Manifest) ExecutePostHookActions() error {
551551
for _, svc := range m.Services {
552552
if svc.postHook != nil {
553553
slog.Info("Executing post-hook operation", "name", svc.postHook.Name)
554-
if err := svc.postHook.Action(svc); err != nil {
554+
if err := svc.postHook.Action(m, svc); err != nil {
555555
return err
556556
}
557557
}

0 commit comments

Comments
 (0)