implement command to get execution traces of any message
This commit is contained in:
parent
2bf42d5318
commit
bd474617ed
69
cli/state.go
69
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: "<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",
|
||||
|
Loading…
Reference in New Issue
Block a user