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 all 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
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.
62 changes: 62 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,67 @@ var clientFindCmd = &cli.Command{
},
}

var clientQueryRetrievalAskCmd = &cli.Command{
Name: "retrieval-ask",
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: 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.Uint64("size")
if size == 0 {
if ask.Size == 0 {
return nil
}
size = ask.Size
afmt.Printf("Size: %s\n", types.SizeStr(types.NewInt(ask.Size)))
}
transferPrice := types.BigMul(ask.PricePerByte, types.NewInt(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
18 changes: 18 additions & 0 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ COMMANDS:
stat Print information about a locally stored file (piece size, etc)
RETRIEVAL:
find Find data in the network
retrieval-ask Get a miner's retrieval ask
retrieve Retrieve data from network
cat Show data from network
ls List object links
Expand Down Expand Up @@ -535,6 +536,23 @@ OPTIONS:

```

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

USAGE:
lotus client 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 retrieval-ask --size=1 <miner addr> <data CID>
out = clientCLI.RunCmd("client", "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