From 665d23cb8e72f661d55beb1f390216e4bcf3c7f4 Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Tue, 15 Sep 2020 12:10:22 -0700 Subject: [PATCH 1/3] Add set-ask, get-ask retrieval CLI --- cmd/lotus-storage-miner/retrieval-deals.go | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/cmd/lotus-storage-miner/retrieval-deals.go b/cmd/lotus-storage-miner/retrieval-deals.go index df194978d02..0f15f19f2e2 100644 --- a/cmd/lotus-storage-miner/retrieval-deals.go +++ b/cmd/lotus-storage-miner/retrieval-deals.go @@ -5,9 +5,12 @@ import ( "os" "text/tabwriter" + "github.com/docker/go-units" "github.com/filecoin-project/go-fil-markets/retrievalmarket" + "github.com/filecoin-project/go-state-types/abi" "github.com/urfave/cli/v2" + "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) @@ -17,6 +20,8 @@ var retrievalDealsCmd = &cli.Command{ Subcommands: []*cli.Command{ retrievalDealSelectionCmd, retrievalDealsListCmd, + retrievalSetAskCmd, + retrievalGetAskCmd, }, } @@ -154,3 +159,112 @@ var retrievalDealsListCmd = &cli.Command{ return w.Flush() }, } + +var retrievalSetAskCmd = &cli.Command{ + Name: "set-ask", + Usage: "Configure the provider's retrieval ask", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "price", + Usage: "Set the price of the ask for retrievals (per byte)", + }, + &cli.StringFlag{ + Name: "unseal-price", + Usage: "Set the price to unseal", + }, + &cli.StringFlag{ + Name: "payment-interval", + Usage: "Set the payment interval (in bytes) for retrieval", + DefaultText: "1Mb", + }, + &cli.StringFlag{ + Name: "payment-interval-increase", + Usage: "Set the payment interval increase (in bytes) for retrieval", + DefaultText: "1Mb", + }, + }, + Action: func(cctx *cli.Context) error { + ctx := lcli.DaemonContext(cctx) + + api, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return err + } + defer closer() + + ask, err := api.MarketGetRetrievalAsk(ctx) + if err != nil { + return err + } + + if cctx.IsSet("price") { + v, err := types.ParseFIL(cctx.String("price")) + if err != nil { + return err + } + ask.PricePerByte = abi.TokenAmount(v) + } + + if cctx.IsSet("unseal-price") { + v, err := types.ParseFIL(cctx.String("unseal-price")) + if err != nil { + return err + } + ask.UnsealPrice = abi.TokenAmount(v) + } + + if cctx.IsSet("payment-interval") { + v, err := units.RAMInBytes(cctx.String("payment-interval")) + if err != nil { + return err + } + ask.PaymentInterval = uint64(v) + } + + if cctx.IsSet("payment-interval-increase") { + v, err := units.RAMInBytes(cctx.String("payment-interval-increase")) + if err != nil { + return err + } + ask.PaymentIntervalIncrease = uint64(v) + } + + return api.MarketSetRetrievalAsk(ctx, ask) + }, +} + +var retrievalGetAskCmd = &cli.Command{ + Name: "get-ask", + Usage: "Get the provider's current retrieval ask", + Flags: []cli.Flag{}, + Action: func(cctx *cli.Context) error { + ctx := lcli.DaemonContext(cctx) + + api, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return err + } + defer closer() + + ask, err := api.MarketGetRetrievalAsk(ctx) + if err != nil { + return err + } + + w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) + fmt.Fprintf(w, "Price per Byte\tUnseal Price\tPayment Interval\tPayment Interval Increase\n") + if ask == nil { + fmt.Fprintf(w, "\n") + return w.Flush() + } + + fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", + types.FIL(ask.PricePerByte), + types.FIL(ask.UnsealPrice), + units.BytesSize(float64(ask.PaymentInterval)), + units.BytesSize(float64(ask.PaymentIntervalIncrease)), + ) + return w.Flush() + + }, +} From 2aef7f7c07445d64b0b4c7b9bf7b7b10898531f7 Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Wed, 16 Sep 2020 13:56:34 -0700 Subject: [PATCH 2/3] Clarify help text units --- cmd/lotus-storage-miner/retrieval-deals.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-storage-miner/retrieval-deals.go b/cmd/lotus-storage-miner/retrieval-deals.go index 0f15f19f2e2..08a0fea51b1 100644 --- a/cmd/lotus-storage-miner/retrieval-deals.go +++ b/cmd/lotus-storage-miner/retrieval-deals.go @@ -170,17 +170,17 @@ var retrievalSetAskCmd = &cli.Command{ }, &cli.StringFlag{ Name: "unseal-price", - Usage: "Set the price to unseal", + Usage: "Set the price to unseal (FIL/GiB)", }, &cli.StringFlag{ Name: "payment-interval", Usage: "Set the payment interval (in bytes) for retrieval", - DefaultText: "1Mb", + DefaultText: "1MiB", }, &cli.StringFlag{ Name: "payment-interval-increase", Usage: "Set the payment interval increase (in bytes) for retrieval", - DefaultText: "1Mb", + DefaultText: "1MiB", }, }, Action: func(cctx *cli.Context) error { From f56602c5887864d88328df4374cb4a894e1c53f9 Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Wed, 16 Sep 2020 14:30:04 -0700 Subject: [PATCH 3/3] Specify retrieval price in FIL/GiB --- cmd/lotus-storage-miner/retrieval-deals.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-storage-miner/retrieval-deals.go b/cmd/lotus-storage-miner/retrieval-deals.go index 08a0fea51b1..03d397852d8 100644 --- a/cmd/lotus-storage-miner/retrieval-deals.go +++ b/cmd/lotus-storage-miner/retrieval-deals.go @@ -166,11 +166,11 @@ var retrievalSetAskCmd = &cli.Command{ Flags: []cli.Flag{ &cli.StringFlag{ Name: "price", - Usage: "Set the price of the ask for retrievals (per byte)", + Usage: "Set the price of the ask for retrievals (FIL/GiB)", }, &cli.StringFlag{ Name: "unseal-price", - Usage: "Set the price to unseal (FIL/GiB)", + Usage: "Set the price to unseal", }, &cli.StringFlag{ Name: "payment-interval", @@ -202,7 +202,7 @@ var retrievalSetAskCmd = &cli.Command{ if err != nil { return err } - ask.PricePerByte = abi.TokenAmount(v) + ask.PricePerByte = types.BigDiv(types.BigInt(v), types.NewInt(1<<30)) } if cctx.IsSet("unseal-price") {