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

feat: #6017 market: retrieval ask CLI command #7814

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ type QueryOffer struct {
Size uint64
MinPrice types.BigInt
UnsealPrice types.BigInt
PricePerByte abi.TokenAmount
PaymentInterval uint64
PaymentIntervalIncrease uint64
Miner address.Address
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
58 changes: 58 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var clientCmd = &cli.Command{
WithCategory("data", clientLocalCmd),
WithCategory("data", clientStat),
WithCategory("retrieval", clientFindCmd),
WithCategory("retrieval", clientQueryRetrievalAskCmd),
WithCategory("retrieval", clientRetrieveCmd),
WithCategory("retrieval", clientRetrieveCatCmd),
WithCategory("retrieval", clientRetrieveLsCmd),
Expand Down Expand Up @@ -1030,6 +1031,63 @@ var clientFindCmd = &cli.Command{
},
}

var clientQueryRetrievalAskCmd = &cli.Command{
Name: "query-retrieval-ask",
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
Usage: "Get a miner's retrieval ask",
ArgsUsage: "[minerAddress] [data CID]",
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "size",
Usage: "data size in bytes",
},
},
Action: func(cctx *cli.Context) error {
afmt := NewAppFmt(cctx.App)
if cctx.NArg() != 2 {
afmt.Println("Usage: query-retrieval-ask [minerAddress] [data CID]")
return nil
}

maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}

dataCid, err := cid.Parse(cctx.Args().Get(1))
if err != nil {
return fmt.Errorf("parsing data cid: %w", err)
}

api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)

ask, err := api.ClientMinerQueryOffer(ctx, maddr, dataCid, nil)
if err != nil {
return err
}

afmt.Printf("Ask: %s\n", maddr)
afmt.Printf("Unseal price: %s\n", types.FIL(ask.UnsealPrice))
afmt.Printf("Price per byte: %s\n", types.FIL(ask.PricePerByte))
afmt.Printf("Payment interval: %s\n", types.SizeStr(types.NewInt(ask.PaymentInterval)))
afmt.Printf("Payment interval increase: %s\n", types.SizeStr(types.NewInt(ask.PaymentIntervalIncrease)))

size := cctx.Int64("size")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure that QueryOffer has a Size field (for the whole piece, so doesn't exactly apply to selective retrievals, but imo still useful to print that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The size is actually passed in as a parameter - if the user passes it, then the "Total Cost" calculation is output - see the Example Output in the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, my point is that the default could be to use the size from QueryOffer if it wasn't specified by the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I made that change 👍

if size == 0 {
return nil
}
transferPrice := types.BigMul(ask.PricePerByte, types.NewInt(uint64(size)))
totalPrice := types.BigAdd(ask.UnsealPrice, transferPrice)
afmt.Printf("Total price for %d bytes: %s\n", size, types.FIL(totalPrice))

return nil
},
}

var clientListRetrievalsCmd = &cli.Command{
Name: "list-retrievals",
Usage: "List retrieval market deals",
Expand Down
1 change: 1 addition & 0 deletions documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ Response:
"Size": 42,
"MinPrice": "0",
"UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42,
"PaymentIntervalIncrease": 42,
"Miner": "f01234",
Expand Down
1 change: 1 addition & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ Response:
"Size": 42,
"MinPrice": "0",
"UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42,
"PaymentIntervalIncrease": 42,
"Miner": "f01234",
Expand Down
30 changes: 24 additions & 6 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,13 @@ COMMANDS:
local List locally imported data
stat Print information about a locally stored file (piece size, etc)
RETRIEVAL:
find Find data in the network
retrieve Retrieve data from network
cat Show data from network
ls List object links
cancel-retrieval Cancel a retrieval deal by deal ID; this also cancels the associated transfer
list-retrievals List retrieval market deals
find Find data in the network
query-retrieval-ask Get a miner's retrieval ask
retrieve Retrieve data from network
cat Show data from network
ls List object links
cancel-retrieval Cancel a retrieval deal by deal ID; this also cancels the associated transfer
list-retrievals List retrieval market deals
STORAGE:
deal Initialize storage deal with a miner
query-ask Find a miners ask
Expand Down Expand Up @@ -535,6 +536,23 @@ OPTIONS:

```

### lotus client query-retrieval-ask
```
NAME:
lotus client query-retrieval-ask - Get a miner's retrieval ask

USAGE:
lotus client query-retrieval-ask [command options] [minerAddress] [data CID]

CATEGORY:
RETRIEVAL

OPTIONS:
--size value data size in bytes (default: 0)
--help, -h show help (default: false)

```

### lotus client retrieve
```
NAME:
Expand Down
7 changes: 6 additions & 1 deletion itests/kit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode)
time.Sleep(time.Second)
}

// client query-retrieval-ask --size=1 <miner addr> <data CID>
out = clientCLI.RunCmd("client", "query-retrieval-ask", "--size=1", minerAddr.String(), dataCid.String())
require.Regexp(t, regexp.MustCompile("Ask:"), out)
fmt.Println("retrieval ask:\n", out)

// Retrieve the first file from the Miner
// client retrieve <cid> <file path>
tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-Client")
tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-client")
require.NoError(t, err)
path := filepath.Join(tmpdir, "outfile.dat")
out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path)
Expand Down
1 change: 1 addition & 0 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func (a *API) makeRetrievalQuery(ctx context.Context, rp rm.RetrievalPeer, paylo
Size: queryResponse.Size,
MinPrice: queryResponse.PieceRetrievalPrice(),
UnsealPrice: queryResponse.UnsealPrice,
PricePerByte: queryResponse.MinPricePerByte,
PaymentInterval: queryResponse.MaxPaymentInterval,
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
Miner: queryResponse.PaymentAddress, // TODO: check
Expand Down