Merge pull request #7814 from filecoin-project/feat/retrieval-ask-cli

feat: #6017 market: retrieval ask CLI command
This commit is contained in:
Łukasz Magiera 2021-12-20 18:04:21 +01:00 committed by GitHub
commit ef65ddf351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 1 deletions

View File

@ -900,6 +900,7 @@ type QueryOffer struct {
Size uint64 Size uint64
MinPrice types.BigInt MinPrice types.BigInt
UnsealPrice types.BigInt UnsealPrice types.BigInt
PricePerByte abi.TokenAmount
PaymentInterval uint64 PaymentInterval uint64
PaymentIntervalIncrease uint64 PaymentIntervalIncrease uint64
Miner address.Address Miner address.Address

Binary file not shown.

View File

@ -92,6 +92,7 @@ var clientCmd = &cli.Command{
WithCategory("data", clientLocalCmd), WithCategory("data", clientLocalCmd),
WithCategory("data", clientStat), WithCategory("data", clientStat),
WithCategory("retrieval", clientFindCmd), WithCategory("retrieval", clientFindCmd),
WithCategory("retrieval", clientQueryRetrievalAskCmd),
WithCategory("retrieval", clientRetrieveCmd), WithCategory("retrieval", clientRetrieveCmd),
WithCategory("retrieval", clientRetrieveCatCmd), WithCategory("retrieval", clientRetrieveCatCmd),
WithCategory("retrieval", clientRetrieveLsCmd), WithCategory("retrieval", clientRetrieveLsCmd),
@ -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{ var clientListRetrievalsCmd = &cli.Command{
Name: "list-retrievals", Name: "list-retrievals",
Usage: "List retrieval market deals", Usage: "List retrieval market deals",

View File

@ -1386,6 +1386,7 @@ Response:
"Size": 42, "Size": 42,
"MinPrice": "0", "MinPrice": "0",
"UnsealPrice": "0", "UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42, "PaymentInterval": 42,
"PaymentIntervalIncrease": 42, "PaymentIntervalIncrease": 42,
"Miner": "f01234", "Miner": "f01234",

View File

@ -1425,6 +1425,7 @@ Response:
"Size": 42, "Size": 42,
"MinPrice": "0", "MinPrice": "0",
"UnsealPrice": "0", "UnsealPrice": "0",
"PricePerByte": "0",
"PaymentInterval": 42, "PaymentInterval": 42,
"PaymentIntervalIncrease": 42, "PaymentIntervalIncrease": 42,
"Miner": "f01234", "Miner": "f01234",

View File

@ -425,6 +425,7 @@ COMMANDS:
stat Print information about a locally stored file (piece size, etc) stat Print information about a locally stored file (piece size, etc)
RETRIEVAL: RETRIEVAL:
find Find data in the network find Find data in the network
retrieval-ask Get a miner's retrieval ask
retrieve Retrieve data from network retrieve Retrieve data from network
cat Show data from network cat Show data from network
ls List object links ls List object links
@ -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 ### lotus client retrieve
``` ```
NAME: NAME:

View File

@ -101,9 +101,14 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode)
time.Sleep(time.Second) 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 // Retrieve the first file from the Miner
// client retrieve <cid> <file path> // 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) require.NoError(t, err)
path := filepath.Join(tmpdir, "outfile.dat") path := filepath.Join(tmpdir, "outfile.dat")
out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path) out = clientCLI.RunCmd("client", "retrieve", dataCid.String(), path)

View File

@ -490,6 +490,7 @@ func (a *API) makeRetrievalQuery(ctx context.Context, rp rm.RetrievalPeer, paylo
Size: queryResponse.Size, Size: queryResponse.Size,
MinPrice: queryResponse.PieceRetrievalPrice(), MinPrice: queryResponse.PieceRetrievalPrice(),
UnsealPrice: queryResponse.UnsealPrice, UnsealPrice: queryResponse.UnsealPrice,
PricePerByte: queryResponse.MinPricePerByte,
PaymentInterval: queryResponse.MaxPaymentInterval, PaymentInterval: queryResponse.MaxPaymentInterval,
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease, PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
Miner: queryResponse.PaymentAddress, // TODO: check Miner: queryResponse.PaymentAddress, // TODO: check