From bd474617ed6f51726f645119f1da4bf2ece092bb Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 6 Oct 2020 16:06:24 -0700 Subject: [PATCH] implement command to get execution traces of any message --- cli/state.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/cli/state.go b/cli/state.go index 7baf57df2..371ef4af0 100644 --- a/cli/state.go +++ b/cli/state.go @@ -72,6 +72,7 @@ var stateCmd = &cli.Command{ stateMsgCostCmd, stateMinerInfo, stateMarketCmd, + stateExecTraceCmd, }, } @@ -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: "", + 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",