Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
494b75f
feat(dynamic-relays): add relay configuration manager
screwyprof Nov 16, 2022
298a5ce
feat(dynamic-relays): add default relay config provider
screwyprof Nov 16, 2022
8104fad
feat(dynamic-relays): use default config provider to registerValidator
screwyprof Nov 16, 2022
7c2454a
feat(dynamic-relays): use config manager for getHeader and getPayload
screwyprof Nov 16, 2022
d500cff
feat(dynamic-relays): remove relays in favour of relay config manager
screwyprof Nov 16, 2022
f1510fd
feat(dynamic-relays): renamed helpers for consistency
screwyprof Nov 16, 2022
0b4d7d7
feat(dynamic-relays): add json-api relay config provider
screwyprof Nov 17, 2022
779bade
feat(dynamic-relays): move relay entry to a separate package
screwyprof Nov 17, 2022
442876e
feat(dynamic-relays): more relay list to relay package
screwyprof Nov 17, 2022
f4cff30
feat(dynamic-relays) add relay registry
screwyprof Nov 21, 2022
0483e64
feat(dynamic-relays): add tests for file rcp
screwyprof Nov 22, 2022
7b46752
feat(dynamic-relays): add more tests for json-api rcp
screwyprof Nov 22, 2022
7ccdbc5
feat(dynamic-relays): add more rcp tests
screwyprof Nov 22, 2022
19f0efc
feat(dynamic-relays): refactor rcm
screwyprof Nov 22, 2022
f721a03
feat(dynamic-relays): fix concurren access
screwyprof Nov 22, 2022
f022bf1
feat(dynamic-relays): move registry creator to rcm
screwyprof Nov 23, 2022
423be9d
feat(dynamic-relays): create rcm based on the passed cli options
screwyprof Nov 23, 2022
a04ab35
feat(dynamic-relays): refactor RCM to remove RCP with Registry Creator
screwyprof Nov 23, 2022
8c1d49a
feat(dynamic-relays): add syncer to update config in background
screwyprof Nov 23, 2022
9ac998c
feat(dynamic-relays): add tests for registry creator
screwyprof Nov 24, 2022
defb11e
feat(dynamic-relays): refactor test helpers
screwyprof Nov 24, 2022
4599b18
feat(dynamic-relays): change github action to publish docker images
screwyprof Nov 25, 2022
19c0124
feat(dynamic-relays): fix double printing sync time
screwyprof Nov 25, 2022
950faa9
feat(dynamic-relays): fix mev boost version for docker pipeline
screwyprof Nov 25, 2022
02a0b55
feat(dynamic-relays): add tests for relay.Set
screwyprof Nov 28, 2022
7bec904
feat(dynamic-relays): make error messages more descriptive
screwyprof Nov 28, 2022
915ca64
feat(dynamic-relays): refactor rcm.Syncer
screwyprof Nov 29, 2022
eb2d4da
feat(dynamic-relays): fix -relay option
screwyprof Nov 29, 2022
5854ff9
feat(dynamic-relays): fix registry and refactor tests
screwyprof Nov 30, 2022
3a1ad75
feat(dynamic-relays): add tests to check if the correct relays are hit
screwyprof Nov 30, 2022
75b5bc8
feat(dynamic-relays): refactor test for better reporting
screwyprof Nov 30, 2022
8fd14fa
feat(dynamic-relays): refactor rcm package
screwyprof Dec 1, 2022
f6ce1e2
feat(dynamic-relays): extract proposer config related tests into a se…
screwyprof Dec 1, 2022
b1a2440
feat(dynamic-relays): rename rcm.NewDefault to rcm.New
screwyprof Dec 1, 2022
0a1db11
feat(dynamic-relays): refactor rcp file provider tests
screwyprof Dec 1, 2022
26e5e67
feat(dynamic-relays): refactor rcp tests
screwyprof Dec 1, 2022
976f8cb
feat(dynamic-relays): refactor rcp package
screwyprof Dec 1, 2022
a4c0046
feat(dynamic-relays): move test helpers to reltest package
screwyprof Dec 2, 2022
538121e
feat(dynamic-relays): update valid proposer config
screwyprof Jan 10, 2023
942b8a8
feat(dynamic-relays): handle default relays properly
screwyprof Jan 12, 2023
0ccc2c9
feat(dynamic-relays): add more valid json examples
screwyprof Jan 17, 2023
ca0e3c7
feat(dynamic-relays): add test cases for missing proposer builder
screwyprof Jan 17, 2023
43166c0
feat(dynamic-relays): fix linters
screwyprof Jan 20, 2023
2c7573e
feat(dynamic-relays): make sync timeout configurable
screwyprof Jan 24, 2023
056fd24
feat(dynamic-relays): add more test cases for get payload endpoint
screwyprof Jan 24, 2023
659328d
feat(dynamic-relays): rename validator relays to proposer relays
screwyprof Jan 25, 2023
e0dd687
feat(dynamic-relays): add docs
screwyprof Jan 25, 2023
dde6357
feat(dynamic-relays): update readme
screwyprof Jan 25, 2023
1e8057b
feat(dynamic-relays): log synced relays
screwyprof Jan 26, 2023
560bfdf
feat(dynamic-relays): add benchmarks
screwyprof Jan 30, 2023
7d3e0b0
feat(dynamic-relays): revert relays check in service
screwyprof Jan 31, 2023
e289ee2
feat(dynamic-relays): dump register validator body for debug
screwyprof Jan 31, 2023
5031d89
feat(dynamic-relays): fix public key for validator registration
screwyprof Jan 31, 2023
4526c33
feat(dynamic-relays): empty the registry before populating after sync
screwyprof Feb 1, 2023
5b685e9
feat(dynamic-relays): group tests
screwyprof Feb 1, 2023
e72cee7
feat(dynamic-relays): fix rebase artifacts
screwyprof Feb 3, 2023
f395804
feat(dynamic-relays): bring back an accidently removed test
screwyprof Feb 3, 2023
87136de
feat(dynamic-relays): refactor register creator to get rid of walker
screwyprof Feb 3, 2023
57f1a5b
feat(dynamic-relays): fix review comments
screwyprof Feb 6, 2023
a79d042
Merge remote-tracking branch 'upstream/main' into feat/dynamic-relay-…
screwyprof Feb 14, 2023
16c7656
feat(dynamic-relays): fix cyclo linter warning for main
screwyprof Feb 15, 2023
94e1d64
feat(dynamic-relays): fix test to expect at least one relay response
screwyprof Feb 15, 2023
1fee12b
feat(dynamic-relays): post-review fixes
screwyprof Feb 16, 2023
7a2ab68
feat(dynamic-relays): add goleaks
screwyprof Feb 16, 2023
ef76417
feat(dynamic-relays): batch register validators
screwyprof Feb 16, 2023
acf8f36
feat(dynamic-relays): rename relay config manager to configurator
screwyprof Feb 17, 2023
8aaa35d
feat(dynamic-relays): refactor to simplify validator registration
screwyprof Feb 17, 2023
3ef3984
feat(dynamic-relays): enable pprof and dumb body
screwyprof Feb 17, 2023
6d3b943
feat(dynamic-relays): don't dump the body
screwyprof Feb 17, 2023
b86ccf9
fix(mev-boost): remove excessive logging
screwyprof Feb 17, 2023
4136ba7
Bump github.com/attestantio/go-eth2-client from 0.15.1 to 0.15.6 (#450)
dependabot[bot] Feb 21, 2023
2475a83
feat(dynamic-relays): revert unintented changes
screwyprof Feb 21, 2023
309191e
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Feb 21, 2023
132d6f9
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Mar 7, 2023
310aeb1
feat(dynamic-relays): fix linters for go1.20
screwyprof Mar 7, 2023
9728cb9
feat(dynamic-relays): move test helper into a separate file
screwyprof Mar 7, 2023
0331f77
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Mar 14, 2023
338d386
feat(dynamic-relay-configuration): fix linters
screwyprof Mar 14, 2023
ed3a378
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Mar 16, 2023
65b6e07
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Mar 20, 2023
a8b4f51
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Mar 30, 2023
a2bcc1e
feat(dynamic-relay-configuration): fix review comments
screwyprof Mar 30, 2023
2bd2282
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Apr 17, 2023
2e0ab48
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Apr 19, 2023
2f68420
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Apr 19, 2023
f8fb22d
Merge branch 'main' into feat/dynamic-relay-configuration-final
screwyprof Apr 24, 2023
9808d48
feat(dynamic-relay-configuration): move types to the top
screwyprof Apr 24, 2023
033b985
feat(dynamic-relay-configuration): continue when there are no relays
screwyprof Apr 24, 2023
41f4113
feat(dynamic-relay-configuration): don't pre-allocate
screwyprof Apr 24, 2023
5bc1c6e
feat(dynamic-relay-configuration): use scatter-gather
screwyprof Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ test:
test-race:
CGO_ENABLED=1 go test -race ./...

.PHONY: fmt
fmt:
gofmt -s -w .
gofumpt -extra -w .
gci write . -s standard,default
go mod tidy

.PHONY: lint
lint:
gofmt -d -s .
Expand Down
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,47 +229,55 @@ These are the CLI arguments for the main branch. For arguments available in a sp

```
$ ./mev-boost -help
Usage of mev-boost:
Usage of ./mev-boost:
-addr string
listen-address for mev-boost server (default "localhost:18550")
listen-address for mev-boost server (default "localhost:18550")
-debug
shorthand for '-loglevel debug'
shorthand for '-loglevel debug'
-genesis-fork-version string
use a custom genesis fork version
use a custom genesis fork version
-goerli
use Goerli
use Goerli
-json
log in JSON format instead of text
log in JSON format instead of text
-log-no-version
disables adding the version to every log entry
disables adding the version to every log entry
-log-service string
add a 'service=...' tag to all log messages
add a 'service=...' tag to all log messages
-loglevel string
minimum loglevel: trace, debug, info, warn/warning, error, fatal, panic (default "info")
minimum loglevel: trace, debug, info, warn/warning, error, fatal, panic (default "info")
-mainnet
use Mainnet (default true)
use Mainnet (default true)
-min-bid float
minimum bid to accept from a relay [eth]
minimum bid to accept from a relay [eth]
-proposer-config-file string
proposer config file path
-proposer-config-refresh-enabled
periodically reload proposer config
-proposer-config-sync-timeout int
proposer config sync timeout [ms] (default 3000)
-proposer-config-url string
proposer config endpoint url
-relay value
a single relay, can be specified multiple times
a single relay, can be specified multiple times
-relay-check
check relay status on startup and on the status API call
check relay status on startup and on the status API call
-relay-monitor value
a single relay monitor, can be specified multiple times
a single relay monitor, can be specified multiple times
-relay-monitors string
relay monitor urls - single entry or comma-separated list (scheme://host)
relay monitor urls - single entry or comma-separated list (scheme://host)
-relays string
relay urls - single entry or comma-separated list (scheme://pubkey@host)
relay urls - single entry or comma-separated list (scheme://pubkey@host)
-request-timeout-getheader int
timeout for getHeader requests to the relay [ms] (default 950)
timeout for getHeader requests to the relay [ms] (default 950)
-request-timeout-getpayload int
timeout for getPayload requests to the relay [ms] (default 4000)
timeout for getPayload requests to the relay [ms] (default 4000)
-request-timeout-regval int
timeout for registerValidator requests [ms] (default 3000)
timeout for registerValidator requests [ms] (default 3000)
-sepolia
use Sepolia
use Sepolia
-version
only print version
only print version
```

### `-relays` vs `-relay`
Expand Down
162 changes: 150 additions & 12 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package cli

import (
"context"
"errors"
"flag"
"fmt"
"math/big"
"net/http"
"os"
"sort"
"strconv"
"strings"
"time"

"github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/mev-boost/config"
"github.com/flashbots/mev-boost/config/rcm"
"github.com/flashbots/mev-boost/config/rcp"
"github.com/flashbots/mev-boost/config/relay"
"github.com/flashbots/mev-boost/server"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -46,8 +53,11 @@ var (
defaultTimeoutMsGetPayload = getEnvInt("RELAY_TIMEOUT_MS_GETPAYLOAD", 4000) // timeout for getPayload requests
defaultTimeoutMsRegisterValidator = getEnvInt("RELAY_TIMEOUT_MS_REGVAL", 3000) // timeout for registerValidator requests

relays relayList
relayMonitors relayMonitorList
// is used when json rcp fetches configuration.
defaultTimeoutMsSyncConfig = getEnvInt("CONFIG_SYNC_TIMEOUT_MS", 3000)

relays = relay.NewRelaySet()
relayMonitors relay.MonitorList

// cli flags
printVersion = flag.Bool("version", false, "only print version")
Expand All @@ -57,7 +67,13 @@ var (
logService = flag.String("log-service", defaultLogServiceTag, "add a 'service=...' tag to all log messages")
logNoVersion = flag.Bool("log-no-version", defaultDisableLogVersion, "disables adding the version to every log entry")

listenAddr = flag.String("addr", defaultListenAddr, "listen-address for mev-boost server")
listenAddr = flag.String("addr", defaultListenAddr, "listen-address for mev-boost server")

proposerConfigURL = flag.String("proposer-config-url", "", "proposer config endpoint url")
proposerConfigFile = flag.String("proposer-config-file", "", "proposer config file path")
proposerConfigRefresh = flag.Bool("proposer-config-refresh-enabled", false, "periodically reload proposer config")
proposerConfigSyncTimeout = flag.Int("proposer-config-sync-timeout", defaultTimeoutMsSyncConfig, "proposer config sync timeout [ms]")

relayURLs = flag.String("relays", defaultRelays, "relay urls - single entry or comma-separated list (scheme://pubkey@host)")
relayCheck = flag.Bool("relay-check", defaultRelayCheck, "check relay status on startup and on the status API call")
relayMinBidEth = flag.Float64("min-bid", defaultRelayMinBidEth, "minimum bid to accept from a relay [eth]")
Expand All @@ -79,6 +95,12 @@ var (

var log = logrus.NewEntry(logrus.New())

var (
ErrRequiredOptionsAreNotProvided = errors.New("required options are not provided")
ErrMutuallyExclusiveOptions = errors.New("mutually exclusive options provided")
ErrNoRelaysProvided = errors.New("no relays provided")
)

// Main starts the mev-boost cli
func Main() {
// process repeatable flags
Expand Down Expand Up @@ -146,25 +168,29 @@ func Main() {
}
log.Infof("using genesis fork version: %s", genesisForkVersionHex)

if err := checkProposerConfigOptions(); err != nil {
flag.Usage()
log.WithError(err).Fatal("invalid proposer options")
}

// For backwards compatibility with the -relays flag.
if *relayURLs != "" {
for _, relayURL := range strings.Split(*relayURLs, ",") {
err := relays.Set(strings.TrimSpace(relayURL))
err := relays.Set(relayURL)
if err != nil {
log.WithError(err).WithField("relay", relayURL).Fatal("Invalid relay URL")
}
}
}

if len(relays) == 0 {
flag.Usage()
log.Fatal("no relays specified")
}
log.Infof("using %d relays", len(relays))
for index, relay := range relays {
log.Infof("relay #%d: %s", index+1, relay.String())
relayConfigurator, err := createConfigurator()
if err != nil {
log.WithError(err).Fatal("cannot init relay configurator")
}

printRelaysList(relayConfigurator)
runConfigSyncerIfEnabled(relayConfigurator)

// For backwards compatibility with the -relay-monitors flag.
if *relayMonitorURLs != "" {
for _, relayMonitorURL := range strings.Split(*relayMonitorURLs, ",") {
Expand Down Expand Up @@ -202,8 +228,8 @@ func Main() {
opts := server.BoostServiceOpts{
Log: log,
ListenAddr: *listenAddr,
Relays: relays,
RelayMonitors: relayMonitors,
RelayConfigurator: relayConfigurator,
GenesisForkVersionHex: genesisForkVersionHex,
RelayCheck: *relayCheck,
RelayMinBid: *relayMinBidWei,
Expand All @@ -225,6 +251,118 @@ func Main() {
log.Fatal(service.StartHTTPServer())
}

func checkProposerConfigOptions() error {
const (
flagRelay = "relay"
flagRelayURLs = "relays"
flagProposerConfigURL = "proposer-config-url"
flagProposerConfigFile = "proposer-config-file"
)

allowedOptions := map[string]string{
flagRelay: relays.String(),
flagRelayURLs: *relayURLs,
flagProposerConfigURL: *proposerConfigURL,
flagProposerConfigFile: *proposerConfigFile,
}

providedOptions := make(map[string]string, len(allowedOptions))

addOptionIfNotEmpty := func(opt, val string) {
if _, ok := allowedOptions[opt]; ok && val != "" {
providedOptions[opt] = val
}
}

for opt, value := range allowedOptions {
addOptionIfNotEmpty(opt, value)
}

if len(providedOptions) < 1 {
return fmt.Errorf("%w: please specify %s",
ErrRequiredOptionsAreNotProvided, mapKeysToString(allowedOptions))
}

if len(providedOptions) > 1 {
return fmt.Errorf("%w: please specify %s",
ErrMutuallyExclusiveOptions, mapKeysToString(providedOptions))
}

return nil
}

func mapKeysToString(m map[string]string) string {
res := make([]string, 0, len(m))
for opt := range m {
res = append(res, opt)
}
sort.Strings(res)
return "-" + strings.Join(res, " or -")
}

func createConfigurator() (*rcm.Configurator, error) {
var registryCreator *rcm.RegistryCreator

switch {
case len(relays) > 0:
registryCreator = rcm.NewRegistryCreator(rcp.NewDefault(relays).FetchConfig)
case *proposerConfigFile != "":
registryCreator = rcm.NewRegistryCreator(rcp.NewFile(*proposerConfigFile).FetchConfig)
case *proposerConfigURL != "":
syncTimeout := time.Duration(*proposerConfigSyncTimeout) * time.Millisecond
c := &http.Client{Timeout: syncTimeout}
registryCreator = rcm.NewRegistryCreator(rcp.NewJSONAPI(c, *proposerConfigURL).FetchConfig)
}

relayConfigurator, err := rcm.New(registryCreator)
if err != nil {
return nil, fmt.Errorf("cannot create relay configurator: %w", err)
}

if len(relayConfigurator.AllRelays()) == 0 {
return nil, ErrNoRelaysProvided
}

return relayConfigurator, nil
}

func printRelaysList(relayConfigurator *rcm.Configurator) {
relaysList := relayConfigurator.AllRelays().ToStringSlice()

log.Infof("using %d relays", len(relaysList))

for index, entry := range relaysList {
log.Infof("relay #%d: %s", index+1, entry)
}
}

func runConfigSyncerIfEnabled(relayConfigurator *rcm.Configurator) {
if *proposerConfigRefresh {
log.Infof("default proposer config sync interval is %.2f min", rcm.DefaultSyncInterval.Minutes())

// At the moment the sync job will run perpetually until the program is killed.
// Even thought the Syncer supports graceful shutdown via context cancellation,
// we cannot utilise it here as we don't have a cancellable context at the moment.
// If we use a cancellable context here instead of context.Background(),
// it will just stop the synchronisation, yet won't stop the other running go-routines.
syncer := rcm.NewSyncer(relayConfigurator, rcm.SyncerWithOnSyncHandler(onSyncHandler))
go syncer.SyncConfig(context.Background())
}
}

// onSyncHandler runs every time when configuration is synced.
//
// We ignore the first time parameter, as the logger already has the time field.
func onSyncHandler(_ time.Time, err error, relays relay.List) {
if err != nil {
log.WithError(err).Error("cannot sync configuration")

return
}

log.Infof("successfully synced relay configuration: %s", relays)
}

func getEnv(key, defaultValue string) string {
if value, ok := os.LookupEnv(key); ok {
return value
Expand Down
69 changes: 0 additions & 69 deletions cli/types.go

This file was deleted.

Loading