Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get-ask, set-ask retrieval commands #3886

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions cmd/lotus-storage-miner/retrieval-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -17,6 +20,8 @@ var retrievalDealsCmd = &cli.Command{
Subcommands: []*cli.Command{
retrievalDealSelectionCmd,
retrievalDealsListCmd,
retrievalSetAskCmd,
retrievalGetAskCmd,
},
}

Expand Down Expand Up @@ -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 (FIL/GiB)",
},
&cli.StringFlag{
Name: "payment-interval",
Usage: "Set the payment interval (in bytes) for retrieval",
DefaultText: "1MiB",
},
&cli.StringFlag{
Name: "payment-interval-increase",
Usage: "Set the payment interval increase (in bytes) for retrieval",
DefaultText: "1MiB",
},
},
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's per byte, but above we the comment says per GiB.

We could change the comment, but i think it's better ux to actually have it be per GiB, so we just need to divide here by 1 << 30

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

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, "<miner does not have an retrieval ask set>\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()

},
}