@@ -20,11 +20,12 @@ type VerifiedRegistryExtractionContext struct {
2020 PrevState , CurrState verifreg.State
2121 PrevTs , CurrTs * types.TipSet
2222
23- Store adt.Store
23+ Store adt.Store
24+ PreviousStatePresent bool
2425}
2526
2627func (v * VerifiedRegistryExtractionContext ) HasPreviousState () bool {
27- return ! ( v . CurrTs . Height () == 1 || v . PrevState == v . CurrState )
28+ return v . PreviousStatePresent
2829}
2930
3031func NewVerifiedRegistryExtractorContext (ctx context.Context , a actorstate.ActorInfo , node actorstate.ActorStateAPI ) (* VerifiedRegistryExtractionContext , error ) {
@@ -33,35 +34,34 @@ func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.Actor
3334 return nil , fmt .Errorf ("loading current verified registry state: %w" , err )
3435 }
3536
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
5249 }
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+ }
5352
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 )
5857 }
5958 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 ,
6565 }, nil
6666}
6767
0 commit comments