Skip to content

Commit e966a48

Browse files
feat: add --use-reth-for-validation (#21)
1 parent 33ea095 commit e966a48

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/spf13/cobra v1.8.0
1616
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3
17+
golang.org/x/mod v0.21.0
1718
gopkg.in/yaml.v2 v2.4.0
1819
)
1920

@@ -131,7 +132,6 @@ require (
131132
go.uber.org/zap v1.27.0 // indirect
132133
golang.org/x/crypto v0.26.0 // indirect
133134
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
134-
golang.org/x/mod v0.20.0 // indirect
135135
golang.org/x/net v0.28.0 // indirect
136136
golang.org/x/oauth2 v0.21.0 // indirect
137137
golang.org/x/sync v0.8.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDT
433433
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
434434
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
435435
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
436-
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
437-
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
436+
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
437+
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
438438
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
439439
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
440440
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

main.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/flashbots/mev-boost-relay/beaconclient"
2626
mevRCommon "github.com/flashbots/mev-boost-relay/common"
27+
"golang.org/x/mod/semver"
2728

2829
"github.com/ethereum/go-ethereum/core/types"
2930
ecrypto "github.com/ethereum/go-ethereum/crypto"
@@ -58,6 +59,7 @@ var validateFlag bool
5859
var genesisDelayFlag uint64
5960
var watchPayloadsFlag bool
6061
var latestForkFlag bool
62+
var useRethForValidation bool
6163

6264
var rootCmd = &cobra.Command{
6365
Use: "playground",
@@ -164,6 +166,7 @@ func main() {
164166
rootCmd.Flags().Uint64Var(&genesisDelayFlag, "genesis-delay", 5, "")
165167
rootCmd.Flags().BoolVar(&watchPayloadsFlag, "watch-payloads", false, "")
166168
rootCmd.Flags().BoolVar(&latestForkFlag, "electra", false, "")
169+
rootCmd.Flags().BoolVar(&useRethForValidation, "use-reth-for-validation", false, "enable flashbots_validateBuilderSubmissionV* on reth and use them for validation")
167170

168171
downloadArtifactsCmd.Flags().BoolVar(&validateFlag, "validate", false, "")
169172
validateCmd.Flags().Uint64Var(&numBlocksValidate, "num-blocks", 5, "")
@@ -361,12 +364,32 @@ func setupServices(svcManager *serviceManager, out *output) error {
361364
fmt.Printf("(%d) %s (%s)\n", indx, acc, ecrypto.PubkeyToAddress(priv.PublicKey).Hex())
362365
}
363366
fmt.Println("")
364-
365367
if err := os.WriteFile(defaultRethDiscoveryPrivKeyLoc, []byte(defaultRethDiscoveryPrivKey), 0644); err != nil {
366368
return err
367369
}
368370

371+
rethVersion := func() string {
372+
cmd := exec.Command(rethBin, "--version")
373+
out, err := cmd.Output()
374+
if err != nil {
375+
return "unknown"
376+
}
377+
// find the line of the form:
378+
// reth Version: x.y.z
379+
for _, line := range strings.Split(string(out), "\n") {
380+
if strings.HasPrefix(line, "reth Version: ") {
381+
v := strings.TrimSpace(strings.TrimPrefix(line, "reth Version: "))
382+
if !strings.HasPrefix(v, "v") {
383+
v = "v" + v
384+
}
385+
return semver.Canonical(v)
386+
}
387+
}
388+
return "unknown"
389+
}()
390+
369391
// start the reth el client
392+
fmt.Println("Starting reth version " + rethVersion)
370393
svcManager.
371394
NewService("reth").
372395
WithArgs(
@@ -387,6 +410,16 @@ func setupServices(svcManager *serviceManager, out *output) error {
387410
"--authrpc.port", "8551",
388411
"--authrpc.jwtsecret", "{{.Dir}}/jwtsecret",
389412
).
413+
If(useRethForValidation, func(s *service) *service {
414+
return s.WithArgs("--http.api", "eth,web3,net,rpc,flashbots")
415+
}).
416+
If(
417+
semver.Compare(rethVersion, "v1.1.0") >= 0,
418+
func(s *service) *service {
419+
// For versions >= v1.1.0, we need to run with --engine.legacy, at least for now
420+
return s.WithArgs("--engine.legacy")
421+
},
422+
).
390423
WithPort("rpc", 30303).
391424
WithPort("http", 8545).
392425
WithPort("authrpc", 8551).
@@ -444,6 +477,7 @@ func setupServices(svcManager *serviceManager, out *output) error {
444477
if cfg.LogOutput, err = out.LogOutput("mev-boost-relay"); err != nil {
445478
return err
446479
}
480+
cfg.UseRethForValidation = useRethForValidation
447481
relay, err := mevboostrelay.New(cfg)
448482
if err != nil {
449483
return fmt.Errorf("failed to create relay: %w", err)
@@ -731,6 +765,13 @@ func (s *service) WithArgs(args ...string) *service {
731765
return s
732766
}
733767

768+
func (s *service) If(cond bool, fn func(*service) *service) *service {
769+
if cond {
770+
return fn(s)
771+
}
772+
return s
773+
}
774+
734775
func (s *service) Run() {
735776
s.srvMng.Run(s)
736777
}

mev-boost-relay/mev-boost-relay.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ type Config struct {
3333
ApiSecretKey string
3434
BeaconClientAddr string
3535
LogOutput io.Writer
36+
37+
UseRethForValidation bool
3638
}
3739

3840
func DefaultConfig() *Config {
3941
return &Config{
40-
ApiListenAddr: "127.0.0.1",
41-
ApiListenPort: 5555,
42-
ApiSecretKey: defaultSecretKey,
43-
BeaconClientAddr: "http://localhost:3500",
44-
LogOutput: os.Stdout,
42+
ApiListenAddr: "127.0.0.1",
43+
ApiListenPort: 5555,
44+
ApiSecretKey: defaultSecretKey,
45+
BeaconClientAddr: "http://localhost:3500",
46+
LogOutput: os.Stdout,
47+
UseRethForValidation: false,
4548
}
4649
}
4750

@@ -119,13 +122,20 @@ func New(config *Config) (*MevBoostRelay, error) {
119122

120123
housekeeperSrv := housekeeper.NewHousekeeper(housekeeperOpts)
121124

122-
// start a mock block validation service that always
123-
// returns the blocks as valids.
124-
apiBlockSimURL, err := startMockBlockValidationServiceServer()
125-
if err != nil {
126-
return nil, fmt.Errorf("failed to start mock block validation service: %w", err)
125+
var blockSimURL string
126+
if config.UseRethForValidation {
127+
log.Info("Using reth for block validation")
128+
blockSimURL = "http://localhost:8545"
129+
} else {
130+
// start a mock block validation service that always
131+
// returns the blocks as valids.
132+
apiBlockSimURL, err := startMockBlockValidationServiceServer()
133+
if err != nil {
134+
return nil, fmt.Errorf("failed to start mock block validation service: %w", err)
135+
}
136+
log.Info("Started mock block validation service, addr: ", apiBlockSimURL)
137+
blockSimURL = apiBlockSimURL
127138
}
128-
log.Info("Started mock block validation service, addr: ", apiBlockSimURL)
129139

130140
// decode the secret key
131141
envSkBytes, err := hex.DecodeString(strings.TrimPrefix(config.ApiSecretKey, "0x"))
@@ -146,7 +156,7 @@ func New(config *Config) (*MevBoostRelay, error) {
146156
DB: pqDB,
147157
SecretKey: secretKey,
148158
EthNetDetails: *ethNetworkDetails,
149-
BlockSimURL: apiBlockSimURL,
159+
BlockSimURL: blockSimURL,
150160
ProposerAPI: true,
151161
BlockBuilderAPI: true,
152162
DataAPI: true,

0 commit comments

Comments
 (0)