Merge pull request #11188 from filecoin-project/shed-msg-add-exec-trace
feat: shed: Add exec traces to `lotus-shed msg`
This commit is contained in:
commit
5281a6d307
@ -26,6 +26,12 @@ var msgCmd = &cli.Command{
|
|||||||
Aliases: []string{"msg"},
|
Aliases: []string{"msg"},
|
||||||
Usage: "Translate message between various formats",
|
Usage: "Translate message between various formats",
|
||||||
ArgsUsage: "Message in any form",
|
ArgsUsage: "Message in any form",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "exec-trace",
|
||||||
|
Usage: "Print the execution trace",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
if cctx.NArg() != 1 {
|
if cctx.NArg() != 1 {
|
||||||
return lcli.IncorrectNumArgs(cctx)
|
return lcli.IncorrectNumArgs(cctx)
|
||||||
@ -36,6 +42,48 @@ var msgCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, closer, err := lcli.GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
// Get the CID of the message
|
||||||
|
mcid := msg.Cid()
|
||||||
|
|
||||||
|
// Search for the message on-chain
|
||||||
|
lookup, err := api.StateSearchMsg(ctx, mcid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if lookup == nil {
|
||||||
|
fmt.Println("Message not found on-chain. Continuing...")
|
||||||
|
} else {
|
||||||
|
// Replay the message to get the execution trace
|
||||||
|
res, err := api.StateReplay(ctx, types.EmptyTSK, mcid)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("replay call failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cctx.Bool("exec-trace") {
|
||||||
|
// Print the execution trace
|
||||||
|
color.Green("Execution trace:")
|
||||||
|
trace, err := json.MarshalIndent(res.ExecutionTrace, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("marshaling execution trace: %w", err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(trace))
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
color.Green("Receipt:")
|
||||||
|
fmt.Printf("Exit code: %d\n", res.MsgRct.ExitCode)
|
||||||
|
fmt.Printf("Return: %x\n", res.MsgRct.Return)
|
||||||
|
fmt.Printf("Gas Used: %d\n", res.MsgRct.GasUsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *types.SignedMessage:
|
case *types.SignedMessage:
|
||||||
return printSignedMessage(cctx, msg)
|
return printSignedMessage(cctx, msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user