From b734e5a2328ee1ba6a3bfc76a3dd5a907188ef08 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 28 Mar 2021 01:21:09 -0400 Subject: [PATCH] Miner CLI: If performing read-only operations on a foreign miner, miner API isn't needed --- cmd/lotus-storage-miner/info.go | 2 +- cmd/lotus-storage-miner/main.go | 12 ++++++++--- cmd/lotus-storage-miner/proving.go | 32 ++++-------------------------- cmd/lotus-storage-miner/sectors.go | 23 ++++++--------------- 4 files changed, 20 insertions(+), 49 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index cf39e5516..7650de035 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -90,7 +90,7 @@ func infoCmdAct(cctx *cli.Context) error { fmt.Println() - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index 84654d789..f5ff25177 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -106,15 +106,21 @@ func main() { lcli.RunApp(app) } -func getActorAddress(ctx context.Context, nodeAPI api.StorageMiner, overrideMaddr string) (maddr address.Address, err error) { - if overrideMaddr != "" { - maddr, err = address.NewFromString(overrideMaddr) +func getActorAddress(ctx context.Context, cctx *cli.Context) (maddr address.Address, err error) { + if cctx.IsSet("actor") { + maddr, err = address.NewFromString(cctx.String("actor")) if err != nil { return maddr, err } return } + nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return address.Undef, err + } + defer closer() + maddr, err = nodeAPI.ActorAddress(ctx) if err != nil { return maddr, xerrors.Errorf("getting actor address: %w", err) diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index f6bc74318..66007b63d 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -38,12 +38,6 @@ var provingFaultsCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -54,7 +48,7 @@ var provingFaultsCmd = &cli.Command{ stor := store.ActorStore(ctx, blockstore.NewAPIBlockstore(api)) - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err } @@ -98,12 +92,6 @@ var provingInfoCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -112,7 +100,7 @@ var provingInfoCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err } @@ -211,12 +199,6 @@ var provingDeadlinesCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -225,7 +207,7 @@ var provingDeadlinesCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err } @@ -301,12 +283,6 @@ var provingDeadlineInfoCmd = &cli.Command{ return xerrors.Errorf("could not parse deadline index: %w", err) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -315,7 +291,7 @@ var provingDeadlineInfoCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 010e3cdeb..8922a24fa 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -434,11 +434,6 @@ var sectorsExtendCmd = &cli.Command{ &cli.StringFlag{}, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() api, nCloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { @@ -447,9 +442,10 @@ var sectorsExtendCmd = &cli.Command{ defer nCloser() ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + + maddr, err := getActorAddress(ctx, cctx) if err != nil { - return xerrors.Errorf("getting miner actor address: %w", err) + return err } var params []miner0.ExtendSectorExpirationParams @@ -512,7 +508,6 @@ var sectorsExtendCmd = &cli.Command{ } } - // TODO: Count added sectors, if it exceeds 10k, split messages p := &miner0.ExtendSectorExpirationParams{} scount := 0 for l, exts := range sectors { @@ -578,8 +573,8 @@ var sectorsExtendCmd = &cli.Command{ return xerrors.Errorf("getting miner info: %w", err) } - for _, p := range params { - sp, aerr := actors.SerializeParams(&p) + for i := range params { + sp, aerr := actors.SerializeParams(¶ms[i]) if aerr != nil { return xerrors.Errorf("serializing params: %w", err) } @@ -836,12 +831,6 @@ var sectorsCapacityCollateralCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { - mApi, mCloser, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer mCloser() - nApi, nCloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -850,7 +839,7 @@ var sectorsCapacityCollateralCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := mApi.ActorAddress(ctx) + maddr, err := getActorAddress(ctx, cctx) if err != nil { return err }