From 925498f938352b4e204f520b89638c7616b0ebf1 Mon Sep 17 00:00:00 2001 From: Phi Date: Sun, 20 Aug 2023 10:06:00 +0200 Subject: [PATCH 1/5] Add exec-trace and receipt Add exec-trace and receipt to the lotus-shed msg command --- cmd/lotus-shed/msg.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 062e077df..5e28d0254 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -36,6 +36,38 @@ var msgCmd = &cli.Command{ 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 { + return fmt.Errorf("failed to find message: %s", mcid) + } + + // 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) + } + + // Print the execution trace and receipt + fmt.Println("Execution trace:") + fmt.Println(res.ExecutionTrace) + fmt.Println("Receipt:") + fmt.Println(res.MsgRct) + switch msg := msg.(type) { case *types.SignedMessage: return printSignedMessage(cctx, msg) From c1231125e9f1912bbcff446a0c2acbf37367e634 Mon Sep 17 00:00:00 2001 From: Phi Date: Sun, 20 Aug 2023 19:54:17 +0200 Subject: [PATCH 2/5] Print receipt Print receipt --- cmd/lotus-shed/msg.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 5e28d0254..6562e156a 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -63,10 +63,13 @@ var msgCmd = &cli.Command{ } // Print the execution trace and receipt - fmt.Println("Execution trace:") + color.Green("Execution trace:") fmt.Println(res.ExecutionTrace) - fmt.Println("Receipt:") - fmt.Println(res.MsgRct) + 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) { case *types.SignedMessage: From 539a5242711220dc328398881ea4a421259f1210 Mon Sep 17 00:00:00 2001 From: Phi Date: Sun, 20 Aug 2023 20:11:27 +0200 Subject: [PATCH 3/5] Make exec-trace human readable Make exec-trace human readable --- cmd/lotus-shed/msg.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 6562e156a..c9cab631e 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -64,7 +64,11 @@ var msgCmd = &cli.Command{ // Print the execution trace and receipt color.Green("Execution trace:") - fmt.Println(res.ExecutionTrace) + 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) From e1ed24ddd0dbafe713ada0562dcc9df8c8dfa301 Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 21 Aug 2023 13:55:49 +0200 Subject: [PATCH 4/5] Put exec-trace behind flag Put exec-trace behind flag --- cmd/lotus-shed/msg.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index c9cab631e..1b8be8a03 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -26,6 +26,12 @@ var msgCmd = &cli.Command{ Aliases: []string{"msg"}, Usage: "Translate message between various formats", ArgsUsage: "Message in any form", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "exec-trace", + Usage: "Print the execution trace", + }, + }, Action: func(cctx *cli.Context) error { if cctx.NArg() != 1 { return lcli.IncorrectNumArgs(cctx) @@ -62,14 +68,16 @@ var msgCmd = &cli.Command{ return xerrors.Errorf("replay call failed: %w", err) } - // Print the execution trace and receipt - color.Green("Execution trace:") - trace, err := json.MarshalIndent(res.ExecutionTrace, "", " ") - if err != nil { - return xerrors.Errorf("marshaling execution trace: %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() } - 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) From 825064669ddce943b9610c8d1c88eb5a67ed724d Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 22 Aug 2023 10:56:50 +0200 Subject: [PATCH 5/5] Continue if msg not found on-chain Continue if msg not found on-chain --- cmd/lotus-shed/msg.go | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 1b8be8a03..35f8eed35 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -59,29 +59,30 @@ var msgCmd = &cli.Command{ return err } if lookup == nil { - return fmt.Errorf("failed to find message: %s", mcid) - } - - // 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, "", " ") + 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("marshaling execution trace: %w", err) + 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) } - 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) { case *types.SignedMessage: