target markets API for markets commands.

This commit is contained in:
Raúl Kripalani 2021-07-29 12:37:29 +01:00
parent 4e19d8d562
commit 22c0884f5f
7 changed files with 101 additions and 37 deletions

View File

@ -113,7 +113,7 @@ var AuthApiInfoToken = &cli.Command{
ti, ok := cctx.App.Metadata["repoType"] ti, ok := cctx.App.Metadata["repoType"]
if !ok { 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 ti = repo.FullNode
} }
t, ok := ti.(repo.RepoType) t, ok := ti.(repo.RepoType)
@ -128,6 +128,7 @@ var AuthApiInfoToken = &cli.Command{
// TODO: Log in audit log when it is implemented // TODO: Log in audit log when it is implemented
// WARN: this is unable to tell
currentEnv, _ := cliutil.EnvsForRepo(t) currentEnv, _ := cliutil.EnvsForRepo(t)
fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr) fmt.Printf("%s=%s:%s\n", currentEnv, string(token), ainfo.Addr)
return nil return nil

View File

@ -44,7 +44,7 @@ func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) {
var GetAPIInfo = cliutil.GetAPIInfo var GetAPIInfo = cliutil.GetAPIInfo
var GetRawAPI = cliutil.GetRawAPI var GetRawAPI = cliutil.GetRawAPI
var GetAPI = cliutil.GetAPI var GetAPI = cliutil.GetCommonAPI
var DaemonContext = cliutil.DaemonContext var DaemonContext = cliutil.DaemonContext
var ReqContext = cliutil.ReqContext var ReqContext = cliutil.ReqContext
@ -54,6 +54,7 @@ var GetFullNodeAPIV1 = cliutil.GetFullNodeAPIV1
var GetGatewayAPI = cliutil.GetGatewayAPI var GetGatewayAPI = cliutil.GetGatewayAPI
var GetStorageMinerAPI = cliutil.GetStorageMinerAPI var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetMarketsAPI = cliutil.GetMarketsAPI
var GetWorkerAPI = cliutil.GetWorkerAPI var GetWorkerAPI = cliutil.GetWorkerAPI
var CommonCommands = []*cli.Command{ var CommonCommands = []*cli.Command{

View File

@ -175,10 +175,10 @@ func GetRawAPI(ctx *cli.Context, t repo.RepoType, version string) (string, http.
return addr, ainfo.AuthHeader(), nil 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"] ti, ok := ctx.App.Metadata["repoType"]
if !ok { 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 ti = repo.FullNode
} }
t, ok := ti.(repo.RepoType) t, ok := ti.(repo.RepoType)
@ -296,6 +296,22 @@ func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) {
return client.NewWorkerRPCV0(ctx.Context, addr, headers) 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) { func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) {
addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1") addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
if err != nil { if err != nil {

View File

@ -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
},
}

View File

@ -76,10 +76,10 @@ func main() {
} }
app := &cli.App{ app := &cli.App{
Name: "lotus-miner", Name: "lotus-miner",
Usage: "Filecoin decentralized storage network miner", Usage: "Filecoin decentralized storage network miner",
Version: build.UserVersion(), Version: build.UserVersion(),
EnableBashCompletion: true, Commands: append(local, lcli.CommonCommands...),
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "actor", Name: "actor",
@ -106,14 +106,24 @@ func main() {
Value: "~/.lotusminer", // TODO: Consider XDG_DATA_HOME 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), 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, cliutil.FlagVeryVerbose,
}, },
EnableBashCompletion: true,
Commands: append(local, lcli.CommonCommands...), 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.Setup()
app.Metadata["repoType"] = repo.StorageMiner app.Metadata["repoType"] = repo.StorageMiner
lcli.RunApp(app) lcli.RunApp(app)
} }

View File

@ -73,7 +73,7 @@ var storageDealSelectionShowCmd = &cli.Command{
Name: "list", Name: "list",
Usage: "List storage deal proposal selection criteria", Usage: "List storage deal proposal selection criteria",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -100,7 +100,7 @@ var storageDealSelectionResetCmd = &cli.Command{
Name: "reset", Name: "reset",
Usage: "Reset storage deal proposal selection criteria to default values", Usage: "Reset storage deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -148,7 +148,7 @@ var storageDealSelectionRejectCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -215,7 +215,13 @@ var setAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx) 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 { if err != nil {
return err return err
} }
@ -252,12 +258,12 @@ var setAskCmd = &cli.Command{
return xerrors.Errorf("cannot parse max-piece-size to quantity of bytes: %w", err) 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 { if err != nil {
return err return err
} }
ssize, err := api.ActorSectorSize(ctx, maddr) ssize, err := minerApi.ActorSectorSize(ctx, maddr)
if err != nil { if err != nil {
return err return err
} }
@ -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 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))
}, },
} }
@ -289,7 +295,7 @@ var getAskCmd = &cli.Command{
} }
defer closer() defer closer()
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -352,7 +358,7 @@ var dealsImportDataCmd = &cli.Command{
Usage: "Manually import data for a deal", Usage: "Manually import data for a deal",
ArgsUsage: "<proposal CID> <file>", ArgsUsage: "<proposal CID> <file>",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -390,7 +396,7 @@ var dealsListCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -494,7 +500,7 @@ var getBlocklistCmd = &cli.Command{
&CidBaseFlag, &CidBaseFlag,
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -524,7 +530,7 @@ var setBlocklistCmd = &cli.Command{
ArgsUsage: "[<path-of-file-containing-newline-delimited-piece-CIDs> (optional, will read from stdin if omitted)]", ArgsUsage: "[<path-of-file-containing-newline-delimited-piece-CIDs> (optional, will read from stdin if omitted)]",
Flags: []cli.Flag{}, Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -570,7 +576,7 @@ var resetBlocklistCmd = &cli.Command{
Usage: "Remove all entries from the miner's piece CID blocklist", Usage: "Remove all entries from the miner's piece CID blocklist",
Flags: []cli.Flag{}, Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -634,7 +640,7 @@ var marketRestartTransfer = &cli.Command{
if !cctx.Args().Present() { if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name) return cli.ShowCommandHelp(cctx, cctx.Command.Name)
} }
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -699,7 +705,7 @@ var marketCancelTransfer = &cli.Command{
if !cctx.Args().Present() { if !cctx.Args().Present() {
return cli.ShowCommandHelp(cctx, cctx.Command.Name) return cli.ShowCommandHelp(cctx, cctx.Command.Name)
} }
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) nodeApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -775,7 +781,7 @@ var transfersListCmd = &cli.Command{
color.NoColor = !cctx.Bool("color") color.NoColor = !cctx.Bool("color")
} }
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -842,7 +848,7 @@ var dealsPendingPublish = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }

View File

@ -39,7 +39,7 @@ var retrievalDealSelectionShowCmd = &cli.Command{
Name: "list", Name: "list",
Usage: "List retrieval deal proposal selection criteria", Usage: "List retrieval deal proposal selection criteria",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -66,7 +66,7 @@ var retrievalDealSelectionResetCmd = &cli.Command{
Name: "reset", Name: "reset",
Usage: "Reset retrieval deal proposal selection criteria to default values", Usage: "Reset retrieval deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -98,7 +98,7 @@ var retrievalDealSelectionRejectCmd = &cli.Command{
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx) smapi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -126,7 +126,7 @@ var retrievalDealsListCmd = &cli.Command{
Name: "list", Name: "list",
Usage: "List all active retrieval deals for this miner", Usage: "List all active retrieval deals for this miner",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -186,7 +186,7 @@ var retrievalSetAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx) ctx := lcli.DaemonContext(cctx)
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -240,7 +240,7 @@ var retrievalGetAskCmd = &cli.Command{
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
ctx := lcli.DaemonContext(cctx) ctx := lcli.DaemonContext(cctx)
api, closer, err := lcli.GetStorageMinerAPI(cctx) api, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
@ -252,13 +252,13 @@ var retrievalGetAskCmd = &cli.Command{
} }
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) 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 { 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() 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.PricePerByte),
types.FIL(ask.UnsealPrice), types.FIL(ask.UnsealPrice),
units.BytesSize(float64(ask.PaymentInterval)), units.BytesSize(float64(ask.PaymentInterval)),