From c377442e24089f193b0df1e495f9a7ed1609989d Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sat, 6 Mar 2021 00:24:26 +0000 Subject: [PATCH] Do not overwrite validator list with null. If Vouch contains a list of validators, and on refresh obtains an empty list, assume the empty response is a result of an error and do not remove the existing list in favor of it. It is possible for network issues to result in an empty response when requesting an update on the list of validators for which Vouch should operate. In this situation, where Vouch already has a list of validators, it retains that list rather than replace it with the empty results of the request. (cherry picked from commit 52c58216cb7a4060c6c46672c3428025adb15f68) --- services/accountmanager/dirk/service.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/accountmanager/dirk/service.go b/services/accountmanager/dirk/service.go index 560f691..cf62ccf 100644 --- a/services/accountmanager/dirk/service.go +++ b/services/accountmanager/dirk/service.go @@ -117,10 +117,10 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { } if err := s.refreshAccounts(ctx); err != nil { - return nil, errors.Wrap(err, "failed to fetch accounts") + return nil, errors.Wrap(err, "failed to fetch initial accounts") } if err := s.refreshValidators(ctx); err != nil { - return nil, errors.Wrap(err, "failed to fetch validator states") + return nil, errors.Wrap(err, "failed to fetch initial validator states") } return s, nil @@ -175,6 +175,11 @@ func (s *Service) refreshAccounts(ctx context.Context) error { } log.Trace().Int("accounts", len(accounts)).Msg("Obtained accounts") + if len(accounts) == 0 && len(s.accounts) != 0 { + log.Warn().Msg("No accounts obtained; retaining old list") + return nil + } + s.mutex.Lock() s.accounts = accounts s.mutex.Unlock()