Skip to content

Commit

Permalink
Merge pull request #4200 from filecoin-project/feat/state-exec-trace
Browse files Browse the repository at this point in the history
implement command to get execution traces of any message
  • Loading branch information
magik6k authored Oct 7, 2020
2 parents c6e0cb4 + bd47461 commit 25bc00e
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var stateCmd = &cli.Command{
stateMsgCostCmd,
stateMinerInfo,
stateMarketCmd,
stateExecTraceCmd,
},
}

Expand Down Expand Up @@ -315,6 +316,74 @@ var stateActiveSectorsCmd = &cli.Command{
},
}

var stateExecTraceCmd = &cli.Command{
Name: "exec-trace",
Usage: "Get the execution trace of a given message",
ArgsUsage: "<messageCid>",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return ShowHelp(cctx, fmt.Errorf("must pass message cid"))
}

mcid, err := cid.Decode(cctx.Args().First())
if err != nil {
return fmt.Errorf("message cid was invalid: %s", err)
}

capi, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := ReqContext(cctx)

msg, err := capi.ChainGetMessage(ctx, mcid)
if err != nil {
return err
}

lookup, err := capi.StateSearchMsg(ctx, mcid)
if err != nil {
return err
}

ts, err := capi.ChainGetTipSet(ctx, lookup.TipSet)
if err != nil {
return err
}

pts, err := capi.ChainGetTipSet(ctx, ts.Parents())
if err != nil {
return err
}

cso, err := capi.StateCompute(ctx, pts.Height(), nil, pts.Key())
if err != nil {
return err
}

var trace *api.InvocResult
for _, t := range cso.Trace {
if t.Msg.From == msg.From && t.Msg.Nonce == msg.Nonce {
trace = t
break
}
}
if trace == nil {
return fmt.Errorf("failed to find message in tipset trace output")
}

out, err := json.MarshalIndent(trace, "", " ")
if err != nil {
return err
}

fmt.Println(string(out))
return nil
},
}

var stateReplaySetCmd = &cli.Command{
Name: "replay",
Usage: "Replay a particular message within a tipset",
Expand Down

0 comments on commit 25bc00e

Please sign in to comment.