Skip to content

Commit

Permalink
target markets API for markets commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Jul 29, 2021
1 parent 4e19d8d commit 22c0884
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 37 deletions.
3 changes: 2 additions & 1 deletion cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var AuthApiInfoToken = &cli.Command{

ti, ok := cctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetAPI?")
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNode
}
t, ok := ti.(repo.RepoType)
Expand All @@ -128,6 +128,7 @@ var AuthApiInfoToken = &cli.Command{

// TODO: Log in audit log when it is implemented

// WARN: this is unable to tell
currentEnv, _ := cliutil.EnvsForRepo(t)
fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr)
return nil
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) {

var GetAPIInfo = cliutil.GetAPIInfo
var GetRawAPI = cliutil.GetRawAPI
var GetAPI = cliutil.GetAPI
var GetAPI = cliutil.GetCommonAPI

var DaemonContext = cliutil.DaemonContext
var ReqContext = cliutil.ReqContext
Expand All @@ -54,6 +54,7 @@ var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
var GetGatewayAPI = cliutil.GetGatewayAPI

var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetMarketsAPI = cliutil.GetMarketsAPI
var GetWorkerAPI = cliutil.GetWorkerAPI

var CommonCommands = []*cli.Command{
Expand Down
20 changes: 18 additions & 2 deletions cli/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ func GetRawAPI(ctx *cli.Context, t repo.RepoType, version string) (string, http.
return addr, ainfo.AuthHeader(), nil
}

func GetAPI(ctx *cli.Context) (api.CommonNet, jsonrpc.ClientCloser, error) {
func GetCommonAPI(ctx *cli.Context) (api.CommonNet, jsonrpc.ClientCloser, error) {
ti, ok := ctx.App.Metadata["repoType"]
if !ok {
log.Errorf("unknown repo type, are you sure you want to use GetAPI?")
log.Errorf("unknown repo type, are you sure you want to use GetCommonAPI?")
ti = repo.FullNode
}
t, ok := ti.(repo.RepoType)
Expand Down Expand Up @@ -296,6 +296,22 @@ func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) {
return client.NewWorkerRPCV0(ctx.Context, addr, headers)
}

func GetMarketsAPI(ctx *cli.Context) (api.StorageMiner, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.Markets, "v0")
if err != nil {
return nil, nil, err
}

if IsVeryVerbose {
_, _ = fmt.Fprintln(ctx.App.Writer, "using markets API v0 endpoint:", addr)
}

// the markets node is a specialised miner's node, supporting only the
// markets API, which is a subset of the miner API. All non-markets
// operations will error out with "unsupported".
return client.NewStorageMinerRPCV0(ctx.Context, addr, headers)
}

func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions cmd/lotus-miner/dagstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"github.com/urfave/cli/v2"
)

var dagstoreCmd = &cli.Command{
Name: "dagstore",
Usage: "Manage the DAG store",
Subcommands: []*cli.Command{
dagstoreListShardsCmd,
dagstoreGarbageCollectCmd,
},
}

var dagstoreListShardsCmd = &cli.Command{
Name: "list-shards",
Usage: "List shards known to the DAG store",
Action: func(cctx *cli.Context) error {
return nil
},
}

var dagstoreGarbageCollectCmd = &cli.Command{
Name: "gc",
Usage: "Garbage collect the DAG store",
Action: func(cctx *cli.Context) error {
return nil
},
}
24 changes: 17 additions & 7 deletions cmd/lotus-miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func main() {
}

app := &cli.App{
Name: "lotus-miner",
Usage: "Filecoin decentralized storage network miner",
Version: build.UserVersion(),
EnableBashCompletion: true,
Name: "lotus-miner",
Usage: "Filecoin decentralized storage network miner",
Version: build.UserVersion(),
Commands: append(local, lcli.CommonCommands...),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "actor",
Expand All @@ -106,14 +106,24 @@ func main() {
Value: "~/.lotusminer", // TODO: Consider XDG_DATA_HOME
Usage: fmt.Sprintf("Specify miner repo path. flag(%s) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON", FlagMinerRepoDeprecation),
},
&cli.BoolFlag{
Name: "call-on-markets",
Usage: "(experimental; may be removed) call this command against a markets node; use only with common commands like net, auth, pprof, etc. whose target may be ambiguous",
},
cliutil.FlagVeryVerbose,
},

Commands: append(local, lcli.CommonCommands...),
EnableBashCompletion: true,
Before: func(c *cli.Context) error {
// this command is explicitly called on markets, inform
// common commands by overriding the repoType.
if c.Bool("call-on-markets") {
c.App.Metadata["repoType"] = repo.Markets
}
return nil
},
}
app.Setup()
app.Metadata["repoType"] = repo.StorageMiner

lcli.RunApp(app)
}

Expand Down
40 changes: 23 additions & 17 deletions cmd/lotus-miner/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var storageDealSelectionShowCmd = &cli.Command{
Name: "list",
Usage: "List storage deal proposal selection criteria",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand All @@ -100,7 +100,7 @@ var storageDealSelectionResetCmd = &cli.Command{
Name: "reset",
Usage: "Reset storage deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -148,7 +148,7 @@ var storageDealSelectionRejectCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -215,7 +215,13 @@ var setAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx)

api, closer, err := lcli.GetStorageMinerAPI(cctx)
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()

marketsApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -252,12 +258,12 @@ var setAskCmd = &cli.Command{
return xerrors.Errorf("cannot parse max-piece-size to quantity of bytes: %w", err)
}

maddr, err := api.ActorAddress(ctx)
maddr, err := minerApi.ActorAddress(ctx)
if err != nil {
return err
}

ssize, err := api.ActorSectorSize(ctx, maddr)
ssize, err := minerApi.ActorSectorSize(ctx, maddr)
if err != nil {
return err
}
Expand All @@ -272,7 +278,7 @@ var setAskCmd = &cli.Command{
return xerrors.Errorf("max piece size (w/bit-padding) %s cannot exceed miner sector size %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax))))
}

return api.MarketSetAsk(ctx, types.BigInt(pri), types.BigInt(vpri), abi.ChainEpoch(qty), abi.PaddedPieceSize(min), abi.PaddedPieceSize(max))
return marketsApi.MarketSetAsk(ctx, types.BigInt(pri), types.BigInt(vpri), abi.ChainEpoch(qty), abi.PaddedPieceSize(min), abi.PaddedPieceSize(max))
},
}

Expand All @@ -289,7 +295,7 @@ var getAskCmd = &cli.Command{
}
defer closer()

smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -352,7 +358,7 @@ var dealsImportDataCmd = &cli.Command{
Usage: "Manually import data for a deal",
ArgsUsage: "<proposal CID> <file>",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -390,7 +396,7 @@ var dealsListCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -494,7 +500,7 @@ var getBlocklistCmd = &cli.Command{
&CidBaseFlag,
},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -524,7 +530,7 @@ var setBlocklistCmd = &cli.Command{
ArgsUsage: "[<path-of-file-containing-newline-delimited-piece-CIDs> (optional, will read from stdin if omitted)]",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -570,7 +576,7 @@ var resetBlocklistCmd = &cli.Command{
Usage: "Remove all entries from the miner's piece CID blocklist",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -634,7 +640,7 @@ var marketRestartTransfer = &cli.Command{
if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
nodeApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -699,7 +705,7 @@ var marketCancelTransfer = &cli.Command{
if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
nodeApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -775,7 +781,7 @@ var transfersListCmd = &cli.Command{
color.NoColor = !cctx.Bool("color")
}

api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -842,7 +848,7 @@ var dealsPendingPublish = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/lotus-miner/retrieval-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var retrievalDealSelectionShowCmd = &cli.Command{
Name: "list",
Usage: "List retrieval deal proposal selection criteria",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand All @@ -66,7 +66,7 @@ var retrievalDealSelectionResetCmd = &cli.Command{
Name: "reset",
Usage: "Reset retrieval deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -98,7 +98,7 @@ var retrievalDealSelectionRejectCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ var retrievalDealsListCmd = &cli.Command{
Name: "list",
Usage: "List all active retrieval deals for this miner",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -186,7 +186,7 @@ var retrievalSetAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx)

api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -240,7 +240,7 @@ var retrievalGetAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx)

api, closer, err := lcli.GetStorageMinerAPI(cctx)
api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
Expand All @@ -252,13 +252,13 @@ var retrievalGetAskCmd = &cli.Command{
}

w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
fmt.Fprintf(w, "Price per Byte\tUnseal Price\tPayment Interval\tPayment Interval Increase\n")
_, _ = fmt.Fprintf(w, "Price per Byte\tUnseal Price\tPayment Interval\tPayment Interval Increase\n")
if ask == nil {
fmt.Fprintf(w, "<miner does not have an retrieval ask set>\n")
_, _ = fmt.Fprintf(w, "<miner does not have an retrieval ask set>\n")
return w.Flush()
}

fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
types.FIL(ask.PricePerByte),
types.FIL(ask.UnsealPrice),
units.BytesSize(float64(ask.PaymentInterval)),
Expand Down

0 comments on commit 22c0884

Please sign in to comment.