Skip to content

Commit 0f78e8d

Browse files
committed
config hot reloading
1 parent c66acfd commit 0f78e8d

File tree

8 files changed

+192
-41
lines changed

8 files changed

+192
-41
lines changed

cli/config.go

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package cli
22

33
import (
44
"os"
5+
"path/filepath"
56
"strings"
67

78
"github.com/flashbots/mev-boost/server/types"
9+
"github.com/fsnotify/fsnotify"
10+
"github.com/sirupsen/logrus"
11+
"github.com/spf13/viper"
812
"gopkg.in/yaml.v3"
913
)
1014

@@ -29,6 +33,15 @@ type ConfigResult struct {
2933
LateInSlotTimeMs uint64
3034
}
3135

36+
// ConfigWatcher provides hot reloading of config files
37+
type ConfigWatcher struct {
38+
v *viper.Viper
39+
configPath string
40+
cliRelays []types.RelayEntry
41+
onConfigChange func(*ConfigResult)
42+
log *logrus.Entry
43+
}
44+
3245
// LoadConfigFile loads configurations from a YAML file
3346
func LoadConfigFile(configPath string) (*ConfigResult, error) {
3447
data, err := os.ReadFile(configPath)
@@ -40,7 +53,85 @@ func LoadConfigFile(configPath string) (*ConfigResult, error) {
4053
if err := yaml.Unmarshal(data, &config); err != nil {
4154
return nil, err
4255
}
56+
return parseConfig(config)
57+
}
58+
59+
// NewConfigWatcher creates a new config file watcher
60+
func NewConfigWatcher(configPath string, cliRelays []types.RelayEntry, log *logrus.Entry) (*ConfigWatcher, error) {
61+
v := viper.New()
62+
absPath, err := filepath.Abs(configPath)
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
v.SetConfigFile(absPath)
68+
v.SetConfigType("yaml")
69+
70+
if err := v.ReadInConfig(); err != nil {
71+
return nil, err
72+
}
73+
74+
return &ConfigWatcher{
75+
v: v,
76+
configPath: absPath,
77+
cliRelays: cliRelays,
78+
log: log,
79+
}, nil
80+
}
81+
82+
// Watch starts watching the config file for changes
83+
func (cw *ConfigWatcher) Watch(onConfigChange func(*ConfigResult)) {
84+
cw.onConfigChange = onConfigChange
85+
86+
cw.v.OnConfigChange(func(in fsnotify.Event) {
87+
cw.log.Info("config file changed, reloading...")
88+
var config Config
89+
if err := cw.v.Unmarshal(&config); err != nil {
90+
cw.log.WithError(err).Error("failed to unmarshal new config, keeping old config")
91+
return
92+
}
93+
newConfig, err := parseConfig(config)
94+
if err != nil {
95+
cw.log.WithError(err).Error("failed to parse new config, keeping old config")
96+
return
97+
}
98+
99+
cw.log.Infof("successfully loaded new config")
100+
101+
if cw.onConfigChange != nil {
102+
cw.onConfigChange(newConfig)
103+
}
104+
})
105+
106+
cw.v.WatchConfig()
107+
}
108+
109+
// MergeRelayConfigs merges relays passed via --relays with config file settings.
110+
// this allows the users to still use --relays if they dont want to provide a config file
111+
func MergeRelayConfigs(relays []types.RelayEntry, configMap map[string]types.RelayConfig) []types.RelayConfig {
112+
configs := make([]types.RelayConfig, 0)
113+
processedURLs := make(map[string]bool)
114+
115+
for _, entry := range relays {
116+
urlStr := entry.String()
117+
if config, exists := configMap[urlStr]; exists {
118+
config.RelayEntry = entry
119+
configs = append(configs, config)
120+
} else {
121+
configs = append(configs, types.NewRelayConfig(entry))
122+
}
123+
processedURLs[urlStr] = true
124+
}
43125

126+
for urlStr, config := range configMap {
127+
if !processedURLs[urlStr] {
128+
configs = append(configs, config)
129+
}
130+
}
131+
return configs
132+
}
133+
134+
func parseConfig(config Config) (*ConfigResult, error) {
44135
timeoutGetHeaderMs := config.TimeoutGetHeaderMs
45136
if timeoutGetHeaderMs == 0 {
46137
timeoutGetHeaderMs = 900
@@ -77,28 +168,3 @@ func LoadConfigFile(configPath string) (*ConfigResult, error) {
77168
LateInSlotTimeMs: lateInSlotTimeMs,
78169
}, nil
79170
}
80-
81-
// MergeRelayConfigs merges relays passed via --relays with config file settings.
82-
// this allows the users to still use --relays if they dont want to provide a config file
83-
func MergeRelayConfigs(relays []types.RelayEntry, configMap map[string]types.RelayConfig) []types.RelayConfig {
84-
configs := make([]types.RelayConfig, 0)
85-
processedURLs := make(map[string]bool)
86-
87-
for _, entry := range relays {
88-
urlStr := entry.String()
89-
if config, exists := configMap[urlStr]; exists {
90-
config.RelayEntry = entry
91-
configs = append(configs, config)
92-
} else {
93-
configs = append(configs, types.NewRelayConfig(entry))
94-
}
95-
processedURLs[urlStr] = true
96-
}
97-
98-
for urlStr, config := range configMap {
99-
if !processedURLs[urlStr] {
100-
configs = append(configs, config)
101-
}
102-
}
103-
return configs
104-
}

cli/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type RelaySetupResult struct {
3636
RelayCheck bool
3737
TimeoutGetHeaderMs uint64
3838
LateInSlotTimeMs uint64
39+
CLIRelays []serverTypes.RelayEntry // CLI-provided relays for hot-reload merging
3940
}
4041

4142
var (
@@ -106,6 +107,21 @@ func start(_ context.Context, cmd *cli.Command) error {
106107
log.Error("no relay passed the health-check!")
107108
}
108109

110+
// set up config file watcher if a config file is provided
111+
if cmd.IsSet(relayConfigFlag.Name) {
112+
configPath := cmd.String(relayConfigFlag.Name)
113+
watcher, err := NewConfigWatcher(configPath, relaySetup.CLIRelays, log)
114+
if err != nil {
115+
log.WithError(err).Warn("failed to set up config watcher")
116+
} else {
117+
// register a callback which gets invoked when config file changes
118+
watcher.Watch(func(newConfig *ConfigResult) {
119+
mergedConfigs := MergeRelayConfigs(relaySetup.CLIRelays, newConfig.RelayConfigs)
120+
service.UpdateConfig(mergedConfigs, newConfig.TimeoutGetHeaderMs, newConfig.LateInSlotTimeMs)
121+
})
122+
}
123+
}
124+
109125
if metricsEnabled {
110126
go func() {
111127
log.Infof("metrics server listening on %v", opts.MetricsAddr)
@@ -177,6 +193,7 @@ func setupRelays(cmd *cli.Command) RelaySetupResult {
177193
RelayCheck: cmd.Bool(relayCheckFlag.Name),
178194
TimeoutGetHeaderMs: timeoutGetHeaderMs,
179195
LateInSlotTimeMs: lateInSlotTimeMs,
196+
CLIRelays: []serverTypes.RelayEntry(relays),
180197
}
181198
}
182199

go.mod

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ require (
77
github.com/ethereum/go-ethereum v1.15.9
88
github.com/flashbots/go-boost-utils v1.10.0
99
github.com/flashbots/go-utils v0.10.0
10+
github.com/fsnotify/fsnotify v1.9.0
1011
github.com/google/uuid v1.6.0
1112
github.com/gorilla/mux v1.8.1
1213
github.com/holiman/uint256 v1.3.2
1314
github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15
1415
github.com/sirupsen/logrus v1.9.3
15-
github.com/stretchr/testify v1.10.0
16+
github.com/spf13/viper v1.21.0
17+
github.com/stretchr/testify v1.11.1
1618
github.com/timewasted/go-accept-headers v0.0.0-20130320203746-c78f304b1b09
1719
github.com/urfave/cli/v3 v3.2.0
1820
)
@@ -26,15 +28,25 @@ require (
2628
github.com/emicklei/dot v1.8.0 // indirect
2729
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
2830
github.com/ethereum/go-verkle v0.2.2 // indirect
31+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
2932
github.com/goccy/go-yaml v1.17.1 // indirect
3033
github.com/gofrs/flock v0.12.1 // indirect
3134
github.com/mmcloughlin/addchain v0.4.0 // indirect
35+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
3236
github.com/rivo/uniseg v0.4.7 // indirect
37+
github.com/sagikazarmark/locafero v0.11.0 // indirect
38+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
39+
github.com/spf13/afero v1.15.0 // indirect
40+
github.com/spf13/cast v1.10.0 // indirect
41+
github.com/spf13/pflag v1.0.10 // indirect
42+
github.com/subosito/gotenv v1.6.0 // indirect
3343
github.com/supranational/blst v0.3.14 // indirect
3444
github.com/valyala/fastrand v1.1.0 // indirect
3545
github.com/valyala/histogram v1.2.0 // indirect
3646
github.com/yusufpapurcu/wmi v1.2.4 // indirect
37-
golang.org/x/sync v0.13.0 // indirect
47+
go.yaml.in/yaml/v3 v3.0.4 // indirect
48+
golang.org/x/sync v0.16.0 // indirect
49+
golang.org/x/text v0.28.0 // indirect
3850
rsc.io/tmplfunc v0.0.3 // indirect
3951
)
4052

go.sum

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ github.com/flashbots/go-boost-utils v1.10.0 h1:AGihhYtOjGF/efaBoQefYfmqzKsba6Y7S
3939
github.com/flashbots/go-boost-utils v1.10.0/go.mod h1:vCtklzlENAGLqDrf6JteivgANjzXFqVSQQ3LtoQxyV8=
4040
github.com/flashbots/go-utils v0.10.0 h1:75XWewRO5GIhdLn8+vqdzzuoqJh+j8wN54A++Id7W0Y=
4141
github.com/flashbots/go-utils v0.10.0/go.mod h1:i4xxEB6sHDFfNWEIfh+rP6nx3LxynEn8AOZa05EYgwA=
42+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
43+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
44+
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
45+
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
4246
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
4347
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
4448
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
49+
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
50+
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
4551
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
4652
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
4753
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
@@ -83,6 +89,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
8389
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
8490
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
8591
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
92+
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
93+
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
8694
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8795
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8896
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -96,14 +104,28 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
96104
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
97105
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
98106
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
107+
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
108+
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
99109
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
100110
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
101111
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
102112
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
113+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
114+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
115+
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
116+
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
117+
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
118+
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
119+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
120+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
121+
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
122+
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
103123
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
104124
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
105-
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
106-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
125+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
126+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
127+
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
128+
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
107129
github.com/supranational/blst v0.3.14 h1:xNMoHRJOTwMn63ip6qoWJ2Ymgvj7E2b9jY2FAwY+qRo=
108130
github.com/supranational/blst v0.3.14/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
109131
github.com/timewasted/go-accept-headers v0.0.0-20130320203746-c78f304b1b09 h1:QVxbx5l/0pzciWYOynixQMtUhPYC3YKD6EcUlOsgGqw=
@@ -128,15 +150,19 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
128150
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
129151
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
130152
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
153+
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
154+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
131155
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
132156
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
133-
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
134-
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
157+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
158+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
135159
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
136160
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
137161
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
138162
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
139163
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
164+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
165+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
140166
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
141167
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
142168
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

server/get_header.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ func (m *BoostService) getHeader(log *logrus.Entry, slot phase0.Slot, pubkey, pa
7676
maxTimeoutMs uint64
7777
)
7878

79-
if m.timeoutGetHeaderMs < m.lateInSlotTimeMs-msIntoSlot {
80-
maxTimeoutMs = m.timeoutGetHeaderMs
79+
m.relayConfigsLock.RLock()
80+
relayConfigs := m.relayConfigs
81+
timeoutGetHeaderMs := m.timeoutGetHeaderMs
82+
lateInSlotTimeMs := m.lateInSlotTimeMs
83+
m.relayConfigsLock.RUnlock()
84+
85+
if timeoutGetHeaderMs < lateInSlotTimeMs-msIntoSlot {
86+
maxTimeoutMs = timeoutGetHeaderMs
8187
} else {
82-
maxTimeoutMs = m.lateInSlotTimeMs - msIntoSlot
88+
maxTimeoutMs = lateInSlotTimeMs - msIntoSlot
8389
}
8490

8591
if maxTimeoutMs == 0 {
@@ -93,7 +99,7 @@ func (m *BoostService) getHeader(log *logrus.Entry, slot phase0.Slot, pubkey, pa
9399
}
94100

95101
// Request a bid from each relay
96-
for _, relayConfig := range m.relayConfigs {
102+
for _, relayConfig := range relayConfigs {
97103
wg.Add(1)
98104
go func(relayConfig types.RelayConfig) {
99105
relay := relayConfig.RelayEntry

server/get_payload.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
143143
}
144144

145145
// Prepare for requests
146-
resultCh := make(chan payloadResult, len(m.relayConfigs))
146+
m.relayConfigsLock.RLock()
147+
relayConfigs := m.relayConfigs
148+
m.relayConfigsLock.RUnlock()
149+
150+
resultCh := make(chan payloadResult, len(relayConfigs))
147151
var received atomic.Bool
148152
go func() {
149153
// Make sure we receive a response within the timeout

server/register_validator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ import (
1414
)
1515

1616
func (m *BoostService) registerValidator(log *logrus.Entry, regBytes []byte, header http.Header) error {
17-
respErrCh := make(chan error, len(m.relayConfigs))
17+
m.relayConfigsLock.RLock()
18+
relayConfigs := m.relayConfigs
19+
m.relayConfigsLock.RUnlock()
20+
21+
respErrCh := make(chan error, len(relayConfigs))
1822

1923
log.WithFields(logrus.Fields{
2024
"timeout": m.httpClientRegVal.Timeout,
21-
"numRelays": len(m.relayConfigs),
25+
"numRelays": len(relayConfigs),
2226
"regBytes": len(regBytes),
2327
}).Info("calling registerValidator on relays")
2428

2529
// Forward request to each relay
26-
for _, relayConfig := range m.relayConfigs {
30+
for _, relayConfig := range relayConfigs {
2731
go func(relay types.RelayEntry) {
2832
// Get the URL for this relay
2933
requestURL := relay.GetURI(params.PathRegisterValidator)
@@ -72,7 +76,7 @@ func (m *BoostService) registerValidator(log *logrus.Entry, regBytes []byte, hea
7276
}
7377

7478
// Return OK if any relay responds OK
75-
for range m.relayConfigs {
79+
for range relayConfigs {
7680
respErr := <-respErrCh
7781
if respErr == nil {
7882
// Goroutines are independent, so if there are a lot of configured

0 commit comments

Comments
 (0)