Skip to content

Commit

Permalink
add lotus client cancel-retrieval command.
Browse files Browse the repository at this point in the history
Squash of #5871.

add cancel-retrieval-deal cmd

changes as per review

fix: cancel retrieval deal - disallow negative deal ID

fix: rename command to retrieve-cancel

rename command to cancel-retrieval; rename args to follow Lotus style.
  • Loading branch information
nonsense authored and raulk committed Mar 26, 2021
1 parent 5bd412a commit 33c46a1
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ type FullNode interface {
// which are stuck due to insufficient funds
ClientRetrieveTryRestartInsufficientFunds(ctx context.Context, paymentChannel address.Address) error

// 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
5 changes: 5 additions & 0 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ type FullNodeStruct struct {
ClientDataTransferUpdates func(ctx context.Context) (<-chan api.DataTransferChannel, error) `perm:"write"`
ClientRestartDataTransfer func(ctx context.Context, transferID datatransfer.TransferID, otherPeer peer.ID, isInitiator bool) error `perm:"write"`
ClientCancelDataTransfer func(ctx context.Context, transferID datatransfer.TransferID, otherPeer peer.ID, isInitiator bool) error `perm:"write"`
ClientCancelRetrievalDeal func(p0 context.Context, p1 retrievalmarket.DealID) error `perm:"write"`
ClientRetrieveTryRestartInsufficientFunds func(ctx context.Context, paymentChannel address.Address) error `perm:"write"`

StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"`
Expand Down Expand Up @@ -680,6 +681,10 @@ func (c *FullNodeStruct) GasEstimateMessageGas(ctx context.Context, msg *types.M
return c.Internal.GasEstimateMessageGas(ctx, msg, spec, tsk)
}

func (s *FullNodeStruct) ClientCancelRetrievalDeal(p0 context.Context, p1 retrievalmarket.DealID) error {
return s.Internal.ClientCancelRetrievalDeal(p0, p1)
}

func (c *FullNodeStruct) GasEstimateGasLimit(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (int64, error) {
return c.Internal.GasEstimateGasLimit(ctx, msg, tsk)
}
Expand Down
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.

28 changes: 28 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var clientCmd = &cli.Command{
WithCategory("data", clientStat),
WithCategory("retrieval", clientFindCmd),
WithCategory("retrieval", clientRetrieveCmd),
WithCategory("retrieval", clientCancelRetrievalDealCmd),
WithCategory("util", clientCommPCmd),
WithCategory("util", clientCarGenCmd),
WithCategory("util", clientBalancesCmd),
Expand Down Expand Up @@ -1975,6 +1976,33 @@ var clientCancelTransfer = &cli.Command{
},
}

var clientCancelRetrievalDealCmd = &cli.Command{
Name: "cancel-retrieval",
Usage: "Cancel a retrieval deal by deal ID; this also cancels the associated transfer",
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "deal-id",
Usage: "specify retrieval deal by deal ID",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)

id := cctx.Int64("deal-id")
if id < 0 {
return errors.New("deal id cannot be negative")
}

return api.ClientCancelRetrievalDeal(ctx, retrievalmarket.DealID(id))
},
}

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 @@ -34,6 +34,7 @@
* [Client](#Client)
* [ClientCalcCommP](#ClientCalcCommP)
* [ClientCancelDataTransfer](#ClientCancelDataTransfer)
* [ClientCancelRetrievalDeal](#ClientCancelRetrievalDeal)
* [ClientDataTransferUpdates](#ClientDataTransferUpdates)
* [ClientDealPieceCID](#ClientDealPieceCID)
* [ClientDealSize](#ClientDealSize)
Expand Down Expand Up @@ -889,6 +890,21 @@ Inputs:

Response: `{}`

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


Perms: write

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

Response: `{}`

### ClientDataTransferUpdates
There are not yet any comments for this method.

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("failed to cancel retrieval deal: %w", err)
}

return nil
case <-ctx.Done():
return xerrors.Errorf("context timeout while canceling retrieval deal: %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

0 comments on commit 33c46a1

Please sign in to comment.