2020-06-23 17:17:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-26 17:33:06 +00:00
|
|
|
"fmt"
|
2020-08-04 23:40:29 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2020-06-26 17:33:06 +00:00
|
|
|
|
2020-09-15 19:10:22 +00:00
|
|
|
"github.com/docker/go-units"
|
2020-08-04 23:40:29 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
2020-09-15 19:10:22 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-06-23 17:17:31 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-08-04 23:40:29 +00:00
|
|
|
|
2020-09-15 19:10:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-08-04 23:40:29 +00:00
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-06-23 17:17:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var retrievalDealsCmd = &cli.Command{
|
|
|
|
Name: "retrieval-deals",
|
|
|
|
Usage: "Manage retrieval deals and related configuration",
|
|
|
|
Subcommands: []*cli.Command{
|
2020-06-26 17:33:06 +00:00
|
|
|
retrievalDealSelectionCmd,
|
2020-08-04 23:40:29 +00:00
|
|
|
retrievalDealsListCmd,
|
2020-09-15 19:10:22 +00:00
|
|
|
retrievalSetAskCmd,
|
|
|
|
retrievalGetAskCmd,
|
2020-06-23 17:17:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:33:06 +00:00
|
|
|
var retrievalDealSelectionCmd = &cli.Command{
|
|
|
|
Name: "selection",
|
|
|
|
Usage: "Configure acceptance criteria for retrieval deal proposals",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
retrievalDealSelectionShowCmd,
|
|
|
|
retrievalDealSelectionResetCmd,
|
|
|
|
retrievalDealSelectionRejectCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var retrievalDealSelectionShowCmd = &cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List retrieval deal proposal selection criteria",
|
2020-06-23 17:17:31 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-26 17:33:06 +00:00
|
|
|
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-06-23 17:17:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-26 19:27:41 +00:00
|
|
|
onlineOk, err := smapi.DealsConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx))
|
2020-06-26 17:33:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-26 19:27:41 +00:00
|
|
|
offlineOk, err := smapi.DealsConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("considering online retrieval deals: %t\n", onlineOk)
|
|
|
|
fmt.Printf("considering offline retrieval deals: %t\n", offlineOk)
|
2020-06-26 17:33:06 +00:00
|
|
|
|
|
|
|
return nil
|
2020-06-23 17:17:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:33:06 +00:00
|
|
|
var retrievalDealSelectionResetCmd = &cli.Command{
|
|
|
|
Name: "reset",
|
|
|
|
Usage: "Reset retrieval deal proposal selection criteria to default values",
|
2020-06-23 17:17:31 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-06-26 17:33:06 +00:00
|
|
|
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-06-23 17:17:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-26 17:50:54 +00:00
|
|
|
err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), true)
|
2020-06-26 17:33:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-26 19:27:41 +00:00
|
|
|
err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:33:06 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var retrievalDealSelectionRejectCmd = &cli.Command{
|
|
|
|
Name: "reject",
|
|
|
|
Usage: "Configure criteria which necessitate automatic rejection",
|
2020-06-26 19:27:41 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "online",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "offline",
|
|
|
|
},
|
|
|
|
},
|
2020-06-26 17:33:06 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2020-06-26 19:27:41 +00:00
|
|
|
if cctx.Bool("online") {
|
|
|
|
err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if cctx.Bool("offline") {
|
|
|
|
err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-26 17:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-06-23 17:17:31 +00:00
|
|
|
},
|
|
|
|
}
|
2020-08-04 23:40:29 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
deals, err := api.MarketListRetrievalDeals(lcli.DaemonContext(cctx))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
|
|
|
|
2020-08-05 00:09:32 +00:00
|
|
|
_, _ = fmt.Fprintf(w, "Receiver\tDealID\tPayload\tState\tPricePerByte\tBytesSent\tMessage\n")
|
2020-08-04 23:40:29 +00:00
|
|
|
|
|
|
|
for _, deal := range deals {
|
2020-08-05 00:09:32 +00:00
|
|
|
payloadCid := deal.PayloadCID.String()
|
|
|
|
|
|
|
|
_, _ = fmt.Fprintf(w,
|
|
|
|
"%s\t%d\t%s\t%s\t%s\t%d\t%s\n",
|
|
|
|
deal.Receiver.String(),
|
|
|
|
deal.ID,
|
|
|
|
"..."+payloadCid[len(payloadCid)-8:],
|
|
|
|
retrievalmarket.DealStatuses[deal.Status],
|
|
|
|
deal.PricePerByte.String(),
|
|
|
|
deal.TotalSent,
|
|
|
|
deal.Message,
|
|
|
|
)
|
2020-08-04 23:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return w.Flush()
|
|
|
|
},
|
|
|
|
}
|
2020-09-15 19:10:22 +00:00
|
|
|
|
|
|
|
var retrievalSetAskCmd = &cli.Command{
|
|
|
|
Name: "set-ask",
|
|
|
|
Usage: "Configure the provider's retrieval ask",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "price",
|
2020-09-16 21:30:04 +00:00
|
|
|
Usage: "Set the price of the ask for retrievals (FIL/GiB)",
|
2020-09-15 19:10:22 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "unseal-price",
|
2020-09-16 21:30:04 +00:00
|
|
|
Usage: "Set the price to unseal",
|
2020-09-15 19:10:22 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "payment-interval",
|
|
|
|
Usage: "Set the payment interval (in bytes) for retrieval",
|
2020-09-16 20:56:34 +00:00
|
|
|
DefaultText: "1MiB",
|
2020-09-15 19:10:22 +00:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "payment-interval-increase",
|
|
|
|
Usage: "Set the payment interval increase (in bytes) for retrieval",
|
2020-09-16 20:56:34 +00:00
|
|
|
DefaultText: "1MiB",
|
2020-09-15 19:10:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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
|
|
|
|
}
|
2020-09-16 21:30:04 +00:00
|
|
|
ask.PricePerByte = types.BigDiv(types.BigInt(v), types.NewInt(1<<30))
|
2020-09-15 19:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
2021-05-22 17:10:21 +00:00
|
|
|
Usage: "Get the provider's current retrieval ask configured by the provider in the ask-store using the set-ask CLI command",
|
2020-09-15 19:10:22 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|