Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement command to get execution traces of any message #4200

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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