From c4462ab63e6b56b5b928c20ba0870cd7445bb05d Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Wed, 22 Jul 2020 10:14:45 -0700 Subject: [PATCH] add some useful tools --- cmd/lotus-shed/main.go | 2 ++ cmd/lotus-shed/misc.go | 39 ++++++++++++++++++++++++++++++++ cmd/lotus-shed/mpool.go | 50 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 cmd/lotus-shed/misc.go create mode 100644 cmd/lotus-shed/mpool.go diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index c37b93a42..15cd3cfb3 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -27,6 +27,8 @@ func main() { fetchParamCmd, proofsCmd, verifRegCmd, + miscCmd, + mpoolCmd, } app := &cli.App{ diff --git a/cmd/lotus-shed/misc.go b/cmd/lotus-shed/misc.go new file mode 100644 index 000000000..b342fab0a --- /dev/null +++ b/cmd/lotus-shed/misc.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "strconv" + + "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/urfave/cli/v2" +) + +var miscCmd = &cli.Command{ + Name: "misc", + Usage: "Assorted unsorted commands for various purposes", + Flags: []cli.Flag{}, + Subcommands: []*cli.Command{ + dealStateMappingCmd, + }, +} + +var dealStateMappingCmd = &cli.Command{ + Name: "deal-state", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return cli.ShowCommandHelp(cctx, cctx.Command.Name) + } + + num, err := strconv.Atoi(cctx.Args().First()) + if err != nil { + return err + } + + ststr, ok := storagemarket.DealStates[uint64(num)] + if !ok { + return fmt.Errorf("no such deal state %d", num) + } + fmt.Println(ststr) + return nil + }, +} diff --git a/cmd/lotus-shed/mpool.go b/cmd/lotus-shed/mpool.go new file mode 100644 index 000000000..eddf5b7f8 --- /dev/null +++ b/cmd/lotus-shed/mpool.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + + lcli "github.com/filecoin-project/lotus/cli" + "github.com/filecoin-project/lotus/miner" + "github.com/urfave/cli/v2" +) + +var mpoolCmd = &cli.Command{ + Name: "mpool", + Usage: "Tools for diagnosing mempool issues", + Flags: []cli.Flag{}, + Subcommands: []*cli.Command{ + minerSelectMsgsCmd, + }, +} + +var minerSelectMsgsCmd = &cli.Command{ + Name: "miner-select-msgs", + Action: func(cctx *cli.Context) error { + api, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + + defer closer() + ctx := lcli.ReqContext(cctx) + + head, err := api.ChainHead(ctx) + if err != nil { + return err + } + + msgs, err := api.MpoolPending(ctx, head.Key()) + if err != nil { + return err + } + + filtered, err := miner.SelectMessages(ctx, api.StateGetActor, head, msgs) + if err != nil { + return err + } + + fmt.Println("mempool input messages: ", len(msgs)) + fmt.Println("filtered messages: ", len(filtered)) + return nil + }, +}