@@ -17,28 +17,30 @@ import (
17
17
18
18
var log = logging .Logger ("lily/chain/walk" )
19
19
20
- func NewWalker (obs indexer.Indexer , node lens.API , name string , tasks []string , minHeight , maxHeight int64 , r * schedule.Reporter ) * Walker {
20
+ func NewWalker (obs indexer.Indexer , node lens.API , name string , tasks []string , minHeight , maxHeight int64 , r * schedule.Reporter , stopOnError bool ) * Walker {
21
21
return & Walker {
22
- node : node ,
23
- obs : obs ,
24
- name : name ,
25
- tasks : tasks ,
26
- minHeight : minHeight ,
27
- maxHeight : maxHeight ,
28
- report : r ,
22
+ node : node ,
23
+ obs : obs ,
24
+ name : name ,
25
+ tasks : tasks ,
26
+ minHeight : minHeight ,
27
+ maxHeight : maxHeight ,
28
+ report : r ,
29
+ stopOnError : stopOnError ,
29
30
}
30
31
}
31
32
32
33
// Walker is a job that indexes blocks by walking the chain history.
33
34
type Walker struct {
34
- node lens.API
35
- obs indexer.Indexer
36
- name string
37
- tasks []string
38
- minHeight int64 // limit persisting to tipsets equal to or above this height
39
- maxHeight int64 // limit persisting to tipsets equal to or below this height}
40
- done chan struct {}
41
- report * schedule.Reporter
35
+ node lens.API
36
+ obs indexer.Indexer
37
+ name string
38
+ tasks []string
39
+ minHeight int64 // limit persisting to tipsets equal to or above this height
40
+ maxHeight int64 // limit persisting to tipsets equal to or below this height}
41
+ done chan struct {}
42
+ report * schedule.Reporter
43
+ stopOnError bool
42
44
}
43
45
44
46
// Run starts walking the chain history and continues until the context is done or
@@ -92,6 +94,7 @@ func (c *Walker) WalkChain(ctx context.Context, node lens.API, ts *types.TipSet)
92
94
defer span .End ()
93
95
94
96
var err error
97
+ errs := []error {}
95
98
for int64 (ts .Height ()) >= c .minHeight && ts .Height () != 0 {
96
99
select {
97
100
case <- ctx .Done ():
@@ -102,7 +105,15 @@ func (c *Walker) WalkChain(ctx context.Context, node lens.API, ts *types.TipSet)
102
105
c .report .UpdateCurrentHeight (int64 (ts .Height ()))
103
106
if success , err := c .obs .TipSet (ctx , ts , indexer .WithIndexerType (indexer .Walk ), indexer .WithTasks (c .tasks )); err != nil {
104
107
span .RecordError (err )
105
- return fmt .Errorf ("notify tipset: %w" , err )
108
+ err := fmt .Errorf ("index tipset, height: %v, error: %v" , ts .Height ().String (), err )
109
+ log .Errorf ("%v" , err )
110
+ // collect error
111
+ errs = append (errs , err )
112
+
113
+ // return an error only if the "stopOnError" flag is set to true.
114
+ if c .stopOnError {
115
+ return err
116
+ }
106
117
} else if ! success {
107
118
log .Errorw ("walk incomplete" , "height" , ts .Height (), "tipset" , ts .Key ().String (), "reporter" , c .name )
108
119
}
@@ -115,5 +126,9 @@ func (c *Walker) WalkChain(ctx context.Context, node lens.API, ts *types.TipSet)
115
126
}
116
127
}
117
128
129
+ if len (errs ) > 0 {
130
+ return fmt .Errorf ("errors: %v" , errs )
131
+ }
132
+
118
133
return nil
119
134
}
0 commit comments