1
- package chain
1
+ package actorstate
2
2
3
3
import (
4
4
"context"
@@ -15,33 +15,32 @@ import (
15
15
"github.com/filecoin-project/sentinel-visor/metrics"
16
16
"github.com/filecoin-project/sentinel-visor/model"
17
17
visormodel "github.com/filecoin-project/sentinel-visor/model/visor"
18
- "github.com/filecoin-project/sentinel-visor/tasks/actorstate"
19
18
)
20
19
21
- // An ActorStateProcessor processes the extraction of actor state according the allowed types in its extracter map.
22
- type ActorStateProcessor struct {
20
+ // A Task processes the extraction of actor state according the allowed types in its extracter map.
21
+ type Task struct {
23
22
node lens.API
24
23
opener lens.APIOpener
25
24
closer lens.APICloser
26
25
extracterMap ActorExtractorMap
27
26
}
28
27
29
- func NewActorStateProcessor (opener lens.APIOpener , extracterMap ActorExtractorMap ) * ActorStateProcessor {
30
- p := & ActorStateProcessor {
28
+ func NewTask (opener lens.APIOpener , extracterMap ActorExtractorMap ) * Task {
29
+ p := & Task {
31
30
opener : opener ,
32
31
extracterMap : extracterMap ,
33
32
}
34
33
return p
35
34
}
36
35
37
- func (p * ActorStateProcessor ) ProcessActors (ctx context.Context , ts * types.TipSet , pts * types.TipSet , candidates map [string ]types.Actor ) (model.Persistable , * visormodel.ProcessingReport , error ) {
38
- if p .node == nil {
39
- node , closer , err := p .opener .Open (ctx )
36
+ func (t * Task ) ProcessActors (ctx context.Context , ts * types.TipSet , pts * types.TipSet , candidates map [string ]types.Actor ) (model.Persistable , * visormodel.ProcessingReport , error ) {
37
+ if t .node == nil {
38
+ node , closer , err := t .opener .Open (ctx )
40
39
if err != nil {
41
40
return nil , nil , xerrors .Errorf ("unable to open lens: %w" , err )
42
41
}
43
- p .node = node
44
- p .closer = closer
42
+ t .node = node
43
+ t .closer = closer
45
44
}
46
45
47
46
log .Debugw ("processing actor state changes" , "height" , ts .Height (), "parent_height" , pts .Height ())
@@ -57,7 +56,7 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
57
56
// Filter to just allowed actors
58
57
actors := map [string ]types.Actor {}
59
58
for addr , act := range candidates {
60
- if p .extracterMap .Allow (act .Code ) {
59
+ if t .extracterMap .Allow (act .Code ) {
61
60
actors [addr ] = act
62
61
}
63
62
}
@@ -77,7 +76,7 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
77
76
// Run each task concurrently
78
77
results := make (chan * ActorStateResult , len (actors ))
79
78
for addr , act := range actors {
80
- go p .runActorStateExtraction (ctx , ts , pts , addr , act , results )
79
+ go t .runActorStateExtraction (ctx , ts , pts , addr , act , results )
81
80
}
82
81
83
82
// Gather results
@@ -86,13 +85,13 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
86
85
res := <- results
87
86
inFlight --
88
87
elapsed := time .Since (start )
89
- lla := log .With ("height" , int64 (ts .Height ()), "actor" , actorstate . ActorNameByCode (res .Code ), "address" , res .Address )
88
+ lla := log .With ("height" , int64 (ts .Height ()), "actor" , ActorNameByCode (res .Code ), "address" , res .Address )
90
89
91
90
if res .Error != nil {
92
91
lla .Errorw ("actor returned with error" , "error" , res .Error .Error ())
93
92
report .ErrorsDetected = append (errorsDetected , & ActorStateError {
94
93
Code : res .Code .String (),
95
- Name : actorstate . ActorNameByCode (res .Code ),
94
+ Name : ActorNameByCode (res .Code ),
96
95
Head : res .Head .String (),
97
96
Address : res .Address ,
98
97
Error : res .Error .Error (),
@@ -120,8 +119,8 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
120
119
return data , report , nil
121
120
}
122
121
123
- func (p * ActorStateProcessor ) runActorStateExtraction (ctx context.Context , ts * types.TipSet , pts * types.TipSet , addrStr string , act types.Actor , results chan * ActorStateResult ) {
124
- ctx , _ = tag .New (ctx , tag .Upsert (metrics .ActorCode , actorstate . ActorNameByCode (act .Code )))
122
+ func (t * Task ) runActorStateExtraction (ctx context.Context , ts * types.TipSet , pts * types.TipSet , addrStr string , act types.Actor , results chan * ActorStateResult ) {
123
+ ctx , _ = tag .New (ctx , tag .Upsert (metrics .ActorCode , ActorNameByCode (act .Code )))
125
124
126
125
res := & ActorStateResult {
127
126
Code : act .Code ,
@@ -138,7 +137,7 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
138
137
return
139
138
}
140
139
141
- info := actorstate. ActorInfo {
140
+ info := ActorInfo {
142
141
Actor : act ,
143
142
Address : addr ,
144
143
ParentStateRoot : pts .ParentState (),
@@ -147,12 +146,12 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
147
146
ParentTipSet : pts .Parents (),
148
147
}
149
148
150
- extracter , ok := p .extracterMap .GetExtractor (act .Code )
149
+ extracter , ok := t .extracterMap .GetExtractor (act .Code )
151
150
if ! ok {
152
151
res .SkippedParse = true
153
152
} else {
154
153
// Parse state
155
- data , err := extracter .Extract (ctx , info , p .node )
154
+ data , err := extracter .Extract (ctx , info , t .node )
156
155
if err != nil {
157
156
res .Error = xerrors .Errorf ("failed to extract parsed actor state: %w" , err )
158
157
return
@@ -161,12 +160,12 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
161
160
}
162
161
}
163
162
164
- func (p * ActorStateProcessor ) Close () error {
165
- if p .closer != nil {
166
- p .closer ()
167
- p .closer = nil
163
+ func (t * Task ) Close () error {
164
+ if t .closer != nil {
165
+ t .closer ()
166
+ t .closer = nil
168
167
}
169
- p .node = nil
168
+ t .node = nil
170
169
return nil
171
170
}
172
171
@@ -190,7 +189,7 @@ type ActorStateError struct {
190
189
// An ActorExtractorMap controls which actor types may be extracted.
191
190
type ActorExtractorMap interface {
192
191
Allow (code cid.Cid ) bool
193
- GetExtractor (code cid.Cid ) (actorstate. ActorStateExtractor , bool )
192
+ GetExtractor (code cid.Cid ) (ActorStateExtractor , bool )
194
193
}
195
194
196
195
type ActorExtractorFilter interface {
@@ -204,8 +203,8 @@ func (RawActorExtractorMap) Allow(code cid.Cid) bool {
204
203
return true
205
204
}
206
205
207
- func (RawActorExtractorMap ) GetExtractor (code cid.Cid ) (actorstate. ActorStateExtractor , bool ) {
208
- return actorstate. ActorExtractor {}, true
206
+ func (RawActorExtractorMap ) GetExtractor (code cid.Cid ) (ActorStateExtractor , bool ) {
207
+ return ActorExtractor {}, true
209
208
}
210
209
211
210
// A TypedActorExtractorMap extracts a single type of actor using full parsing of actor state
@@ -220,9 +219,9 @@ func (t *TypedActorExtractorMap) Allow(code cid.Cid) bool {
220
219
return code == t .CodeV1 || code == t .CodeV2 || code == t .CodeV3
221
220
}
222
221
223
- func (t * TypedActorExtractorMap ) GetExtractor (code cid.Cid ) (actorstate. ActorStateExtractor , bool ) {
222
+ func (t * TypedActorExtractorMap ) GetExtractor (code cid.Cid ) (ActorStateExtractor , bool ) {
224
223
if ! t .Allow (code ) {
225
224
return nil , false
226
225
}
227
- return actorstate . GetActorStateExtractor (code )
226
+ return GetActorStateExtractor (code )
228
227
}
0 commit comments