Skip to content

Commit

Permalink
remove --enable-markets flag; add --name string slice flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Jul 12, 2021
1 parent 4bc9fa0 commit c884d81
Showing 1 changed file with 55 additions and 35 deletions.
90 changes: 55 additions & 35 deletions cmd/lotus-storage-miner/init_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)",
Expand All @@ -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")
}
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit c884d81

Please sign in to comment.