diff --git a/cmd/lotus-storage-miner/init_service.go b/cmd/lotus-storage-miner/init_service.go index 33bffafd48c..c5f922a3920 100644 --- a/cmd/lotus-storage-miner/init_service.go +++ b/cmd/lotus-storage-miner/init_service.go @@ -17,33 +17,9 @@ import ( "golang.org/x/xerrors" ) -func checkApiInfo(ctx context.Context, ai string) (string, error) { - ai = strings.TrimPrefix(strings.TrimSpace(ai), "MINER_API_INFO=") - info := cliutil.ParseApiInfo(ai) - addr, err := info.DialArgs("v0") - if err != nil { - return "", xerrors.Errorf("could not get DialArgs: %w", err) - } - - log.Infof("Checking api version of %s", addr) - - api, closer, err := client.NewStorageMinerRPCV0(ctx, addr, info.AuthHeader()) - if err != nil { - return "", err - } - defer closer() - - v, err := api.Version(ctx) - if err != nil { - return "", xerrors.Errorf("checking version: %w", err) - } - - if !v.APIVersion.EqMajorMinor(lapi.MinerAPIVersion0) { - return "", xerrors.Errorf("remote service API version didn't match (expected %s, remote %s)", lapi.MinerAPIVersion0, v.APIVersion) - } - - return ai, nil -} +const ( + MarketsService = "markets" +) var serviceCmd = &cli.Command{ Name: "service", @@ -63,12 +39,10 @@ var serviceCmd = &cli.Command{ Name: "nosync", Usage: "don't check full-node sync status", }, - - &cli.BoolFlag{ - Name: "enable-market", - Usage: "enable market module", + &cli.StringSliceFlag{ + Name: "name", + Usage: "services to be enabled", }, - &cli.StringFlag{ Name: "api-sealer", Usage: "sealer API info (lotus-miner auth api-info --perm=admin)", @@ -83,10 +57,17 @@ var serviceCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) log.Info("Initializing lotus miner service") - if !cctx.Bool("enable-market") { + es := EnabledServices(cctx.StringSlice("name")) + + if len(es) == 0 { return xerrors.Errorf("at least one module must be enabled") } + // we should remove this as soon as we have more service types and not just `markets` + if !es.Contains(MarketsService) { + return xerrors.Errorf("markets module must be enabled") + } + if !cctx.IsSet("api-sealer") { return xerrors.Errorf("--api-sealer is required without the sealer module enabled") } @@ -95,7 +76,7 @@ var serviceCmd = &cli.Command{ } if err := restore(ctx, cctx, func(cfg *config.StorageMiner) error { - cfg.Subsystems.EnableMarkets = cctx.Bool("enable-market") + cfg.Subsystems.EnableMarkets = es.Contains(MarketsService) cfg.Subsystems.EnableMining = false cfg.Subsystems.EnableSealing = false cfg.Subsystems.EnableSectorStorage = false @@ -118,7 +99,7 @@ var serviceCmd = &cli.Command{ return nil }, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi miner.MinerInfo) error { - if cctx.Bool("enable-market") { + if es.Contains(MarketsService) { log.Info("Configuring miner actor") if err := configureStorageMiner(ctx, api, maddr, peerid, big.Zero()); err != nil { @@ -134,3 +115,42 @@ var serviceCmd = &cli.Command{ return nil }, } + +type EnabledServices []string + +func (es EnabledServices) Contains(name string) bool { + for _, s := range es { + if s == name { + return true + } + } + return false +} + +func checkApiInfo(ctx context.Context, ai string) (string, error) { + ai = strings.TrimPrefix(strings.TrimSpace(ai), "MINER_API_INFO=") + info := cliutil.ParseApiInfo(ai) + addr, err := info.DialArgs("v0") + if err != nil { + return "", xerrors.Errorf("could not get DialArgs: %w", err) + } + + log.Infof("Checking api version of %s", addr) + + api, closer, err := client.NewStorageMinerRPCV0(ctx, addr, info.AuthHeader()) + if err != nil { + return "", err + } + defer closer() + + v, err := api.Version(ctx) + if err != nil { + return "", xerrors.Errorf("checking version: %w", err) + } + + if !v.APIVersion.EqMajorMinor(lapi.MinerAPIVersion0) { + return "", xerrors.Errorf("remote service API version didn't match (expected %s, remote %s)", lapi.MinerAPIVersion0, v.APIVersion) + } + + return ai, nil +}