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 lotus client cancel-retrieval cmd to lotus CLI #5871

Merged
merged 7 commits into from
Mar 31, 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
3 changes: 3 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ type FullNode interface {
// which are stuck due to insufficient funds
ClientRetrieveTryRestartInsufficientFunds(ctx context.Context, paymentChannel address.Address) error //perm:write

// ClientCancelRetrievalDeal cancels an ongoing retrieval deal based on DealID
ClientCancelRetrievalDeal(ctx context.Context, dealid retrievalmarket.DealID) error //perm:write

// ClientUnimport removes references to the specified file from filestore
//ClientUnimport(path string)

Expand Down
6 changes: 6 additions & 0 deletions api/apistruct/struct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var clientCmd = &cli.Command{
WithCategory("util", clientListTransfers),
WithCategory("util", clientRestartTransfer),
WithCategory("util", clientCancelTransfer),
WithCategory("util", clientCancelRetrievalDeal),
},
}

Expand Down Expand Up @@ -1975,6 +1976,32 @@ var clientCancelTransfer = &cli.Command{
},
}

var clientCancelRetrievalDeal = &cli.Command{
Name: "cancel-retrieval-deal",
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
Usage: "Cancel a retrieval deal by DealID",
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "dealid",
Usage: "specify retrieval deal by DealID",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)

if cctx.Int64("dealid") == 0 {
return errors.New("deal id cannot be 0")
dirkmc marked this conversation as resolved.
Show resolved Hide resolved
}

return api.ClientCancelRetrievalDeal(ctx, retrievalmarket.DealID(cctx.Int64("dealid")))
},
}

var clientListTransfers = &cli.Command{
Name: "list-transfers",
Usage: "List ongoing data transfers for deals",
Expand Down
16 changes: 16 additions & 0 deletions documentation/en/api-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [Client](#Client)
* [ClientCalcCommP](#ClientCalcCommP)
* [ClientCancelDataTransfer](#ClientCancelDataTransfer)
* [ClientCancelRetrievalDeal](#ClientCancelRetrievalDeal)
* [ClientDataTransferUpdates](#ClientDataTransferUpdates)
* [ClientDealPieceCID](#ClientDealPieceCID)
* [ClientDealSize](#ClientDealSize)
Expand Down Expand Up @@ -921,6 +922,21 @@ Inputs:

Response: `{}`

### ClientCancelRetrievalDeal
ClientCancelRetrievalDeal cancels an ongoing retrieval deal based on DealID


Perms: write

Inputs:
```json
[
5
]
```

Response: `{}`

### ClientDataTransferUpdates


Expand Down
23 changes: 23 additions & 0 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,29 @@ func (a *API) ClientListImports(ctx context.Context) ([]api.Import, error) {
return out, nil
}

func (a *API) ClientCancelRetrievalDeal(ctx context.Context, dealid retrievalmarket.DealID) error {
cerr := make(chan error)
go func() {
err := a.Retrieval.CancelDeal(dealid)

select {
case cerr <- err:
case <-ctx.Done():
}
}()

select {
case err := <-cerr:
if err != nil {
return xerrors.Errorf("canceling retrieval deal erred: %w", err)
}

return nil
case <-ctx.Done():
return xerrors.Errorf("canceling retrieval deal context timeout: %w", ctx.Err())
}
}

func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error {
events := make(chan marketevents.RetrievalEvent)
go a.clientRetrieve(ctx, order, ref, events)
Expand Down