Skip to content

Commit d4007b3

Browse files
committed
feat(validator): validate other applications after error
1 parent 235cf8f commit d4007b3

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

internal/validator/validator.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,25 @@ func Create(ctx context.Context, c *CreateInfo) (*Service, error) {
7171
func (s *Service) Alive() bool { return true }
7272
func (s *Service) Ready() bool { return true }
7373
func (s *Service) Reload() []error { return nil }
74+
75+
// Tick executes the Validator main logic of producing claims and/or proofs
76+
// for processed epochs of all running applications. It is meant to be executed
77+
// inside a loop. If an error occurs while processing any epoch, it halts and
78+
// returns the error.
7479
func (s *Service) Tick() []error {
75-
if err := s.Run(s.Context); err != nil {
76-
return []error{err}
80+
apps, err := getAllRunningApplications(s.Context, s.repository)
81+
if err != nil {
82+
return []error{fmt.Errorf("failed to get running applications. %w", err)}
7783
}
78-
return []error{}
84+
85+
// validate each application
86+
errs := []error{}
87+
for idx := range apps {
88+
if err := s.validateApplication(s.Context, apps[idx]); err != nil {
89+
errs = append(errs, err)
90+
}
91+
}
92+
return errs
7993
}
8094
func (s *Service) Stop(b bool) []error {
8195
return nil
@@ -105,24 +119,6 @@ func getAllRunningApplications(ctx context.Context, er ValidatorRepository) ([]*
105119
return er.ListApplications(ctx, f, repository.Pagination{})
106120
}
107121

108-
// Run executes the Validator main logic of producing claims and/or proofs
109-
// for processed epochs of all running applications. It is meant to be executed
110-
// inside a loop. If an error occurs while processing any epoch, it halts and
111-
// returns the error.
112-
func (v *Service) Run(ctx context.Context) error {
113-
apps, err := getAllRunningApplications(ctx, v.repository)
114-
if err != nil {
115-
return fmt.Errorf("failed to get running applications. %w", err)
116-
}
117-
118-
for idx := range apps {
119-
if err := v.validateApplication(ctx, apps[idx]); err != nil {
120-
return err
121-
}
122-
}
123-
return nil
124-
}
125-
126122
func getProcessedEpochs(ctx context.Context, er ValidatorRepository, address string) ([]*Epoch, error) {
127123
f := repository.EpochFilter{Status: Pointer(EpochStatus_InputsProcessed)}
128124
return er.ListEpochs(ctx, address, f, repository.Pagination{})

0 commit comments

Comments
 (0)