Skip to content

Commit 97778b8

Browse files
authored
app: improved feerecipient behavior (#4491)
* app: improved feerecipient behavior
1 parent 733e549 commit 97778b8

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

app/builderregistration.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,19 @@ func (s *builderRegistrationService) Run(ctx context.Context) {
226226
if s.path != "" {
227227
watcher, err := fsnotify.NewWatcher()
228228
if err != nil {
229-
log.Error(ctx, "Failed to create file watcher for builder registration overrides", err)
230-
return
231-
}
232-
defer watcher.Close()
229+
log.Warn(ctx, "Failed to create file watcher for builder registration overrides; file watching disabled", err)
230+
} else {
231+
dir := filepath.Dir(s.path)
232+
if err := watcher.Add(dir); err != nil {
233+
log.Warn(ctx, "Failed to watch directory for builder registration overrides; file watching disabled", err, z.Str("dir", dir))
234+
watcher.Close()
235+
} else {
236+
defer watcher.Close()
233237

234-
dir := filepath.Dir(s.path)
235-
if err := watcher.Add(dir); err != nil {
236-
log.Error(ctx, "Failed to watch directory for builder registration overrides", err, z.Str("dir", dir))
237-
return
238+
fileEvents = watcher.Events
239+
fileErrors = watcher.Errors
240+
}
238241
}
239-
240-
fileEvents = watcher.Events
241-
fileErrors = watcher.Errors
242242
}
243243

244244
// Optional API fetch timer (nil channel if obolClient == nil).
@@ -254,6 +254,10 @@ func (s *builderRegistrationService) Run(ctx context.Context) {
254254
fetchCh = fetchTimer.C
255255
}
256256

257+
if fileEvents == nil && fetchCh == nil {
258+
return
259+
}
260+
257261
baseName := filepath.Base(s.path)
258262

259263
for {

app/builderregistration_internal_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,28 @@ func TestBuilderRegistrationService(t *testing.T) {
218218
}
219219
})
220220

221+
t.Run("missing directory returns without error", func(t *testing.T) {
222+
// Path under a directory that does not exist. Watcher setup will fail,
223+
// but with no API client configured, Run should return cleanly.
224+
path := filepath.Join(t.TempDir(), "missing", "overrides.json")
225+
226+
svc, err := NewBuilderRegistrationService(ctx, path, eth2p0.Version{}, baseRegs, baseFeeRecipients, nil, nil)
227+
require.NoError(t, err)
228+
229+
done := make(chan struct{})
230+
231+
go func() {
232+
svc.Run(ctx)
233+
close(done)
234+
}()
235+
236+
select {
237+
case <-done:
238+
case <-time.After(time.Second):
239+
t.Fatal("Run did not return when file watcher setup failed and no API client is configured")
240+
}
241+
})
242+
221243
t.Run("file watcher reloads on change", func(t *testing.T) {
222244
dir := t.TempDir()
223245
path := filepath.Join(dir, "overrides.json")

0 commit comments

Comments
 (0)