@@ -20,11 +20,12 @@ type VerifiedRegistryExtractionContext struct {
20
20
PrevState , CurrState verifreg.State
21
21
PrevTs , CurrTs * types.TipSet
22
22
23
- Store adt.Store
23
+ Store adt.Store
24
+ PreviousStatePresent bool
24
25
}
25
26
26
27
func (v * VerifiedRegistryExtractionContext ) HasPreviousState () bool {
27
- return ! ( v . CurrTs . Height () == 1 || v . PrevState == v . CurrState )
28
+ return v . PreviousStatePresent
28
29
}
29
30
30
31
func NewVerifiedRegistryExtractorContext (ctx context.Context , a actorstate.ActorInfo , node actorstate.ActorStateAPI ) (* VerifiedRegistryExtractionContext , error ) {
@@ -33,35 +34,34 @@ func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.Actor
33
34
return nil , fmt .Errorf ("loading current verified registry state: %w" , err )
34
35
}
35
36
36
- prevState := curState
37
- if a .Current .Height () != 0 {
38
- prevActor , err := node .Actor (ctx , a .Address , a .Executed .Key ())
39
- if err != nil {
40
- // if the actor exists in the current state and not in the parent state then the
41
- // actor was created in the current state.
42
- if err == types .ErrActorNotFound {
43
- return & VerifiedRegistryExtractionContext {
44
- PrevState : prevState ,
45
- CurrState : curState ,
46
- PrevTs : a .Executed ,
47
- CurrTs : a .Current ,
48
- Store : node .Store (),
49
- }, nil
50
- }
51
- return nil , fmt .Errorf ("loading previous verified registry actor at tipset %s epoch %d: %w" , a .Executed .Key (), a .Current .Height (), err )
37
+ prevActor , err := node .Actor (ctx , a .Address , a .Executed .Key ())
38
+ if err != nil {
39
+ // actor doesn't exist yet, may have just been created.
40
+ if err == types .ErrActorNotFound {
41
+ return & VerifiedRegistryExtractionContext {
42
+ CurrState : curState ,
43
+ PrevTs : a .Executed ,
44
+ CurrTs : a .Current ,
45
+ Store : node .Store (),
46
+ PrevState : nil ,
47
+ PreviousStatePresent : false ,
48
+ }, nil
52
49
}
50
+ return nil , fmt .Errorf ("loading previous verified registry actor from parent tipset %s current height epoch %d: %w" , a .Executed .Key (), a .Current .Height (), err )
51
+ }
53
52
54
- prevState , err = verifreg . Load ( node . Store (), prevActor )
55
- if err != nil {
56
- return nil , fmt . Errorf ( "loading previous verified registry state: %w" , err )
57
- }
53
+ // actor exists in previous state, load it.
54
+ prevState , err := verifreg . Load ( node . Store (), prevActor )
55
+ if err != nil {
56
+ return nil , fmt . Errorf ( "loading previous verified registry state: %w" , err )
58
57
}
59
58
return & VerifiedRegistryExtractionContext {
60
- PrevState : prevState ,
61
- CurrState : curState ,
62
- PrevTs : a .Executed ,
63
- CurrTs : a .Current ,
64
- Store : node .Store (),
59
+ PrevState : prevState ,
60
+ CurrState : curState ,
61
+ PrevTs : a .Executed ,
62
+ CurrTs : a .Current ,
63
+ Store : node .Store (),
64
+ PreviousStatePresent : true ,
65
65
}, nil
66
66
}
67
67
0 commit comments