diff --git a/changelog/maradini77_patch-2.md b/changelog/maradini77_patch-2.md new file mode 100644 index 000000000000..8a2c597b7285 --- /dev/null +++ b/changelog/maradini77_patch-2.md @@ -0,0 +1,3 @@ +### Fixed + +- Prevent validator service from starting with empty Beacon API host lists by filtering and validating endpoints. diff --git a/validator/client/service.go b/validator/client/service.go index f4e27254f51d..c3bbf39e28f3 100644 --- a/validator/client/service.go +++ b/validator/client/service.go @@ -181,8 +181,7 @@ func (v *ValidatorService) Start() { return } - u := strings.ReplaceAll(v.conn.GetBeaconApiUrl(), " ", "") - hosts := strings.Split(u, ",") + hosts := sanitizeBeaconAPIHosts(v.conn.GetBeaconApiUrl()) if len(hosts) == 0 { log.WithError(err).Error("No API hosts provided") return @@ -376,6 +375,19 @@ func ConstructDialOptions( return dialOpts } +func sanitizeBeaconAPIHosts(raw string) []string { + u := strings.ReplaceAll(raw, " ", "") + rawHosts := strings.Split(u, ",") + hosts := make([]string, 0, len(rawHosts)) + for _, host := range rawHosts { + if host == "" { + continue + } + hosts = append(hosts, host) + } + return hosts +} + func (v *ValidatorService) Graffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]byte, error) { if v.validator == nil { return nil, errors.New("validator is unavailable")