1- package chain
1+ package actorstate
22
33import (
44 "context"
@@ -15,33 +15,32 @@ import (
1515 "github.com/filecoin-project/sentinel-visor/metrics"
1616 "github.com/filecoin-project/sentinel-visor/model"
1717 visormodel "github.com/filecoin-project/sentinel-visor/model/visor"
18- "github.com/filecoin-project/sentinel-visor/tasks/actorstate"
1918)
2019
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 {
2322 node lens.API
2423 opener lens.APIOpener
2524 closer lens.APICloser
2625 extracterMap ActorExtractorMap
2726}
2827
29- func NewActorStateProcessor (opener lens.APIOpener , extracterMap ActorExtractorMap ) * ActorStateProcessor {
30- p := & ActorStateProcessor {
28+ func NewTask (opener lens.APIOpener , extracterMap ActorExtractorMap ) * Task {
29+ p := & Task {
3130 opener : opener ,
3231 extracterMap : extracterMap ,
3332 }
3433 return p
3534}
3635
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 )
4039 if err != nil {
4140 return nil , nil , xerrors .Errorf ("unable to open lens: %w" , err )
4241 }
43- p .node = node
44- p .closer = closer
42+ t .node = node
43+ t .closer = closer
4544 }
4645
4746 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
5756 // Filter to just allowed actors
5857 actors := map [string ]types.Actor {}
5958 for addr , act := range candidates {
60- if p .extracterMap .Allow (act .Code ) {
59+ if t .extracterMap .Allow (act .Code ) {
6160 actors [addr ] = act
6261 }
6362 }
@@ -77,7 +76,7 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
7776 // Run each task concurrently
7877 results := make (chan * ActorStateResult , len (actors ))
7978 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 )
8180 }
8281
8382 // Gather results
@@ -86,13 +85,13 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
8685 res := <- results
8786 inFlight --
8887 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 )
9089
9190 if res .Error != nil {
9291 lla .Errorw ("actor returned with error" , "error" , res .Error .Error ())
9392 report .ErrorsDetected = append (errorsDetected , & ActorStateError {
9493 Code : res .Code .String (),
95- Name : actorstate . ActorNameByCode (res .Code ),
94+ Name : ActorNameByCode (res .Code ),
9695 Head : res .Head .String (),
9796 Address : res .Address ,
9897 Error : res .Error .Error (),
@@ -120,8 +119,8 @@ func (p *ActorStateProcessor) ProcessActors(ctx context.Context, ts *types.TipSe
120119 return data , report , nil
121120}
122121
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 )))
125124
126125 res := & ActorStateResult {
127126 Code : act .Code ,
@@ -138,7 +137,7 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
138137 return
139138 }
140139
141- info := actorstate. ActorInfo {
140+ info := ActorInfo {
142141 Actor : act ,
143142 Address : addr ,
144143 ParentStateRoot : pts .ParentState (),
@@ -147,12 +146,12 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
147146 ParentTipSet : pts .Parents (),
148147 }
149148
150- extracter , ok := p .extracterMap .GetExtractor (act .Code )
149+ extracter , ok := t .extracterMap .GetExtractor (act .Code )
151150 if ! ok {
152151 res .SkippedParse = true
153152 } else {
154153 // Parse state
155- data , err := extracter .Extract (ctx , info , p .node )
154+ data , err := extracter .Extract (ctx , info , t .node )
156155 if err != nil {
157156 res .Error = xerrors .Errorf ("failed to extract parsed actor state: %w" , err )
158157 return
@@ -161,12 +160,12 @@ func (p *ActorStateProcessor) runActorStateExtraction(ctx context.Context, ts *t
161160 }
162161}
163162
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
168167 }
169- p .node = nil
168+ t .node = nil
170169 return nil
171170}
172171
@@ -190,7 +189,7 @@ type ActorStateError struct {
190189// An ActorExtractorMap controls which actor types may be extracted.
191190type ActorExtractorMap interface {
192191 Allow (code cid.Cid ) bool
193- GetExtractor (code cid.Cid ) (actorstate. ActorStateExtractor , bool )
192+ GetExtractor (code cid.Cid ) (ActorStateExtractor , bool )
194193}
195194
196195type ActorExtractorFilter interface {
@@ -204,8 +203,8 @@ func (RawActorExtractorMap) Allow(code cid.Cid) bool {
204203 return true
205204}
206205
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
209208}
210209
211210// 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 {
220219 return code == t .CodeV1 || code == t .CodeV2 || code == t .CodeV3
221220}
222221
223- func (t * TypedActorExtractorMap ) GetExtractor (code cid.Cid ) (actorstate. ActorStateExtractor , bool ) {
222+ func (t * TypedActorExtractorMap ) GetExtractor (code cid.Cid ) (ActorStateExtractor , bool ) {
224223 if ! t .Allow (code ) {
225224 return nil , false
226225 }
227- return actorstate . GetActorStateExtractor (code )
226+ return GetActorStateExtractor (code )
228227}
0 commit comments