@@ -25,7 +25,6 @@ import (
25
25
"github.com/filecoin-project/lotus/chain/vm"
26
26
"github.com/filecoin-project/specs-actors/actors/util/adt"
27
27
28
- builtininit "github.com/filecoin-project/lily/chain/actors/builtin/init"
29
28
"github.com/filecoin-project/lily/lens"
30
29
)
31
30
@@ -170,68 +169,38 @@ func ActorNameAndFamilyFromCode(c cid.Cid) (name string, family string, err erro
170
169
return
171
170
}
172
171
173
- func MakeGetActorCodeFunc (ctx context.Context , store adt.Store , next , current * types.TipSet ) (func (a address.Address ) (cid.Cid , bool ), error ) {
174
- ctx , span := otel .Tracer ("" ).Start (ctx , "MakeGetActorCodeFunc" )
172
+ func MakeGetActorCodeFunc (ctx context.Context , store adt.Store , child , parent * types.TipSet ) (func (ctx context. Context , a address.Address ) (cid.Cid , bool ), error ) {
173
+ _ , span := otel .Tracer ("" ).Start (ctx , "MakeGetActorCodeFunc" )
175
174
defer span .End ()
176
- nextStateTree , err := state .LoadStateTree (store , next .ParentState ())
177
- if err != nil {
178
- return nil , fmt .Errorf ("load state tree: %w" , err )
179
- }
180
-
181
- // Build a lookup of actor codes that exist after all messages in the current epoch have been executed
182
- actorCodes := map [address.Address ]cid.Cid {}
183
- if err := nextStateTree .ForEach (func (a address.Address , act * types.Actor ) error {
184
- actorCodes [a ] = act .Code
185
- return nil
186
- }); err != nil {
187
- return nil , fmt .Errorf ("iterate actors: %w" , err )
188
- }
189
175
190
- nextInitActor , err := nextStateTree . GetActor ( builtininit . Address )
176
+ childStateTree , err := state . LoadStateTree ( store , child . ParentState () )
191
177
if err != nil {
192
- return nil , fmt .Errorf ("getting init actor : %w" , err )
178
+ return nil , fmt .Errorf ("loading child state : %w" , err )
193
179
}
194
180
195
- nextInitActorState , err := builtininit . Load (store , nextInitActor )
181
+ parentStateTree , err := state . LoadStateTree (store , parent . ParentState () )
196
182
if err != nil {
197
- return nil , fmt .Errorf ("loading init actor state: %w" , err )
183
+ return nil , fmt .Errorf ("loading parent state: %w" , err )
198
184
}
199
185
200
- return func (a address.Address ) (cid.Cid , bool ) {
201
- // TODO accept a context, don't take the function context.
186
+ return func (ctx context.Context , a address.Address ) (cid.Cid , bool ) {
202
187
_ , innerSpan := otel .Tracer ("" ).Start (ctx , "GetActorCode" )
203
188
defer innerSpan .End ()
204
- // Shortcut lookup before resolving
205
- c , ok := actorCodes [a ]
206
- if ok {
207
- return c , true
208
- }
209
189
210
- ra , found , err := nextInitActorState .ResolveAddress (a )
211
- if err != nil || ! found {
212
- log .Warnw ("failed to resolve actor address" , "address" , a .String ())
213
- return cid .Undef , false
190
+ act , err := childStateTree .GetActor (a )
191
+ if err == nil {
192
+ return act .Code , true
214
193
}
215
194
216
- c , ok = actorCodes [ra ]
217
- if ok {
218
- return c , true
219
- }
220
-
221
- // Fall back to looking in current state tree. This actor may have been deleted.
222
- currentStateTree , err := state .LoadStateTree (store , current .ParentState ())
223
- if err != nil {
224
- log .Warnf ("failed to load state tree: %v" , err )
225
- return cid .Undef , false
226
- }
227
-
228
- act , err := currentStateTree .GetActor (a )
229
- if err != nil {
230
- log .Warnw ("failed to find actor in state tree" , "address" , a .String (), "error" , err .Error ())
231
- return cid .Undef , false
195
+ // look in parent state, the address may have been deleted in the transition from parent -> child state.
196
+ log .Infof ("failed to find actor %s in child init actor state (err: %s), falling back to parent" , a , err )
197
+ act , err = parentStateTree .GetActor (a )
198
+ if err == nil {
199
+ return act .Code , true
232
200
}
233
201
234
- return act .Code , true
202
+ log .Errorf ("failed to find actor %s in parent state: %s" , a , err )
203
+ return cid .Undef , false
235
204
}, nil
236
205
}
237
206
0 commit comments