From a373fc4c4c8a82f60561dfe9b31b1dd8194822fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 12 Mar 2021 12:23:43 +0100 Subject: [PATCH 1/3] make lotus-miner info all more robust --- cmd/lotus-storage-miner/info_all.go | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/lotus-storage-miner/info_all.go b/cmd/lotus-storage-miner/info_all.go index 408f9b5c7..e5e08a569 100644 --- a/cmd/lotus-storage-miner/info_all.go +++ b/cmd/lotus-storage-miner/info_all.go @@ -35,80 +35,80 @@ var infoAllCmd = &cli.Command{ fmt.Println("#: Version") if err := lcli.VersionCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Miner Info") if err := infoCmdAct(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } // Verbose info fmt.Println("\n#: Storage List") if err := storageListCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Worker List") if err := sealingWorkersCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: PeerID") if err := lcli.NetId.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Listen Addresses") if err := lcli.NetListen.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Reachability") if err := lcli.NetReachability.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } // Very Verbose info fmt.Println("\n#: Peers") if err := lcli.NetPeers.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Sealing Jobs") if err := sealingJobsCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Sched Diag") if err := sealingSchedDiagCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Storage Ask") if err := getAskCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Storage Deals") if err := dealsListCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Retrieval Deals") if err := retrievalDealsListCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Sector List") if err := sectorsListCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } fmt.Println("\n#: Sector Refs") if err := sectorsRefsCmd.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } // Very Very Verbose info @@ -116,7 +116,7 @@ var infoAllCmd = &cli.Command{ list, err := nodeApi.SectorsList(ctx) if err != nil { - return err + fmt.Println("ERROR: ", err) } sort.Slice(list, func(i, j int) bool { @@ -129,11 +129,11 @@ var infoAllCmd = &cli.Command{ fs := &flag.FlagSet{} for _, f := range sectorsStatusCmd.Flags { if err := f.Apply(fs); err != nil { - return err + fmt.Println("ERROR: ", err) } } if err := fs.Parse([]string{"--log", "--on-chain-info", fmt.Sprint(s)}); err != nil { - return err + fmt.Println("ERROR: ", err) } if err := sectorsStatusCmd.Action(cli.NewContext(cctx.App, fs, cctx)); err != nil { @@ -144,7 +144,7 @@ var infoAllCmd = &cli.Command{ fs = &flag.FlagSet{} if err := fs.Parse([]string{fmt.Sprint(s)}); err != nil { - return err + fmt.Println("ERROR: ", err) } if err := storageFindCmd.Action(cli.NewContext(cctx.App, fs, cctx)); err != nil { @@ -155,7 +155,7 @@ var infoAllCmd = &cli.Command{ if !_test { fmt.Println("\n#: Goroutines") if err := lcli.PprofGoroutines.Action(cctx); err != nil { - return err + fmt.Println("ERROR: ", err) } } From 88b0d551b9aa0e578ad1cb6818d5fef558c816f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 12 Mar 2021 12:24:09 +0100 Subject: [PATCH 2/3] shed command to unpack miner info dumps --- cmd/lotus-shed/main.go | 1 + cmd/lotus-shed/miner.go | 112 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 cmd/lotus-shed/miner.go diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index b2a676a8d..b4031359b 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -37,6 +37,7 @@ func main() { mpoolCmd, genesisVerifyCmd, mathCmd, + minerCmd, mpoolStatsCmd, exportChainCmd, consensusCmd, diff --git a/cmd/lotus-shed/miner.go b/cmd/lotus-shed/miner.go new file mode 100644 index 000000000..5cf4c06de --- /dev/null +++ b/cmd/lotus-shed/miner.go @@ -0,0 +1,112 @@ +package main + +import ( + "bufio" + "github.com/mitchellh/go-homedir" + "github.com/urfave/cli/v2" + "golang.org/x/xerrors" + "io" + "os" + "path/filepath" + "strings" +) + +var minerCmd = &cli.Command{ + Name: "miner", + Usage: "miner-related utilities", + Subcommands: []*cli.Command{ + minerUnpackInfoCmd, + }, +} + +var minerUnpackInfoCmd = &cli.Command{ + Name: "unpack-info", + Usage: "unpack miner info all dump", + ArgsUsage: "[allinfo.txt] [dir]", + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 2 { + return xerrors.Errorf("expected 2 args") + } + + src, err := homedir.Expand(cctx.Args().Get(0)) + if err != nil { + return xerrors.Errorf("expand src: %w", err) + } + + f, err := os.Open(src) + if err != nil { + return xerrors.Errorf("open file: %w", err) + } + defer f.Close() // nolint + + dest, err := homedir.Expand(cctx.Args().Get(1)) + if err != nil { + return xerrors.Errorf("expand dest: %w", err) + } + + var outf *os.File + + r := bufio.NewReader(f) + for { + l, _ ,err := r.ReadLine() + if err == io.EOF { + if outf != nil { + return outf.Close() + } + } + if err != nil { + return xerrors.Errorf("read line: %w", err) + } + sl := string(l) + + if strings.HasPrefix(sl, "#") { + if strings.Contains(sl, "..") { + return xerrors.Errorf("bad name %s", sl) + } + + if strings.HasPrefix(sl, "#: ") { + if outf != nil { + if err := outf.Close(); err != nil { + return xerrors.Errorf("close out file: %w", err) + } + } + p := filepath.Join(dest, sl[len("#: "):]) + if err := os.MkdirAll(filepath.Dir(p), 0775); err != nil { + return xerrors.Errorf("mkdir: %w", err) + } + outf, err = os.Create(p) + if err != nil { + return xerrors.Errorf("create out file: %w", err) + } + continue + } + + if strings.HasPrefix(sl, "##: ") { + if outf != nil { + if err := outf.Close(); err != nil { + return xerrors.Errorf("close out file: %w", err) + } + } + p := filepath.Join(dest, "Per Sector Infos", sl[len("##: "):]) + if err := os.MkdirAll(filepath.Dir(p), 0775); err != nil { + return xerrors.Errorf("mkdir: %w", err) + } + outf, err = os.Create(p) + if err != nil { + return xerrors.Errorf("create out file: %w", err) + } + continue + } + } + + if outf != nil { + if _, err := outf.Write(l); err != nil { + return xerrors.Errorf("write line: %w", err) + } + if _, err := outf.Write([]byte("\n")); err != nil { + return xerrors.Errorf("write line end: %w", err) + } + } + } + }, +} \ No newline at end of file From 58213760b7190cdfb2918630b38e4bb9724e3c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 12 Mar 2021 12:24:18 +0100 Subject: [PATCH 3/3] gofmt --- cmd/lotus-shed/miner.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/lotus-shed/miner.go b/cmd/lotus-shed/miner.go index 5cf4c06de..ec5a445f9 100644 --- a/cmd/lotus-shed/miner.go +++ b/cmd/lotus-shed/miner.go @@ -2,13 +2,14 @@ package main import ( "bufio" - "github.com/mitchellh/go-homedir" - "github.com/urfave/cli/v2" - "golang.org/x/xerrors" "io" "os" "path/filepath" "strings" + + "github.com/mitchellh/go-homedir" + "github.com/urfave/cli/v2" + "golang.org/x/xerrors" ) var minerCmd = &cli.Command{ @@ -20,8 +21,8 @@ var minerCmd = &cli.Command{ } var minerUnpackInfoCmd = &cli.Command{ - Name: "unpack-info", - Usage: "unpack miner info all dump", + Name: "unpack-info", + Usage: "unpack miner info all dump", ArgsUsage: "[allinfo.txt] [dir]", Action: func(cctx *cli.Context) error { if cctx.Args().Len() != 2 { @@ -48,7 +49,7 @@ var minerUnpackInfoCmd = &cli.Command{ r := bufio.NewReader(f) for { - l, _ ,err := r.ReadLine() + l, _, err := r.ReadLine() if err == io.EOF { if outf != nil { return outf.Close() @@ -109,4 +110,4 @@ var minerUnpackInfoCmd = &cli.Command{ } } }, -} \ No newline at end of file +}