Skip to content

Commit

Permalink
Try to use the state tree to get Actor
Browse files Browse the repository at this point in the history
  • Loading branch information
Terryhung committed Aug 28, 2023
1 parent 8bb80bf commit 7ba35b4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
28 changes: 25 additions & 3 deletions chain/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ func (t *DataSource) Store() adt.Store {
return t.node.Store()
}

func (t *DataSource) getState(ctx context.Context, ts *types.TipSet) (*state.StateTree, error) {
cid := ts.ParentState()
key, keyErr := asKey(KeyPrefix{"stateTree"}, cid)
if keyErr == nil {
value, found := t.actorCache.Get(key)
if found {
return value.(*state.StateTree), nil
}
}

stateTree, err := state.LoadStateTree(t.Store(), cid)
if err != nil {
return nil, err
}
t.actorCache.Add(key, stateTree)
return stateTree, err
}

func (t *DataSource) Actor(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) {
metrics.RecordInc(ctx, metrics.DataSourceActorCacheRead)
ctx, span := otel.Tracer("").Start(ctx, "DataSource.Actor")
Expand Down Expand Up @@ -230,8 +248,9 @@ func (t *DataSource) Actor(ctx context.Context, addr address.Address, tsk types.
// it includes the actor's state and relevant metadata such as family and name.
// If the actor is not found or an error occurs during retrieval, the function
// returns an error.
func (t *DataSource) ActorInfo(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*tasks.ActorInfo, error) {
func (t *DataSource) ActorInfo(ctx context.Context, addr address.Address, ts *types.TipSet) (*tasks.ActorInfo, error) {
metrics.RecordInc(ctx, metrics.DataSourceActorCacheRead)
tsk := ts.Key()
ctx, span := otel.Tracer("").Start(ctx, "DataSource.ActorInfo")
if span.IsRecording() {
span.SetAttributes(attribute.String("tipset", tsk.String()))
Expand All @@ -248,8 +267,11 @@ func (t *DataSource) ActorInfo(ctx context.Context, addr address.Address, tsk ty
return value.(*tasks.ActorInfo), nil
}
}

act, err := t.Actor(ctx, addr, tsk)
stateTree, err := t.getState(ctx, ts)
if err != nil {
return nil, err
}
act, err := stateTree.GetActor(addr)
actorInfo := tasks.ActorInfo{}
if err == nil {
if act.Address == nil {
Expand Down
2 changes: 1 addition & 1 deletion tasks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type DataSource interface {
TipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)
Actor(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error)
ActorState(ctx context.Context, addr address.Address, ts *types.TipSet) (*api.ActorState, error)
ActorInfo(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*ActorInfo, error)
ActorInfo(ctx context.Context, addr address.Address, ts *types.TipSet) (*ActorInfo, error)
CirculatingSupply(ctx context.Context, ts *types.TipSet) (api.CirculatingSupply, error)
MinerPower(ctx context.Context, addr address.Address, ts *types.TipSet) (*api.MinerPower, error)
ActorStateChanges(ctx context.Context, ts, pts *types.TipSet) (ActorStateChangeDiff, error)
Expand Down
9 changes: 5 additions & 4 deletions tasks/fevm/transaction/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ func (p *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
if message.Message == nil {
continue
}
fromActorInfo, err := p.node.ActorInfo(ctx, message.Message.From, current.Key())
if err != nil {

if !util.IsEVMMessage(ctx, p.node, message.Message, current.Key()) {
continue
}

if !util.IsEVMMessage(ctx, p.node, message.Message, current.Key()) {
fromActorInfo, err := p.node.ActorInfo(ctx, message.Message.From, current)
if err != nil {
continue
}

Expand Down Expand Up @@ -124,7 +125,7 @@ func (p *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
txnObj.To = txn.To.String()

// Get the Actor from ActorInfo
toActorInfo, err := p.node.ActorInfo(ctx, message.Message.To, current.Key())
toActorInfo, err := p.node.ActorInfo(ctx, message.Message.To, current)
if err == nil && toActorInfo.Actor != nil && toActorInfo.Actor.Address != nil {
txnObj.ToActorName = toActorInfo.ActorName
txnObj.ToFilecoinAddress = toActorInfo.Actor.Address.String()
Expand Down

0 comments on commit 7ba35b4

Please sign in to comment.