diff --git a/api/api_full.go b/api/api_full.go index ca3a02c747e..5ca8644cd46 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -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) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 34b18cd4198..5ca91bd1768 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -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"` @@ -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) } diff --git a/api/mocks/mock_full.go b/api/mocks/mock_full.go index 0b76c784dcd..6d60b8690ec 100644 --- a/api/mocks/mock_full.go +++ b/api/mocks/mock_full.go @@ -9,6 +9,7 @@ import ( address "github.com/filecoin-project/go-address" bitfield "github.com/filecoin-project/go-bitfield" datatransfer "github.com/filecoin-project/go-data-transfer" + retrievalmarket "github.com/filecoin-project/go-fil-markets/retrievalmarket" storagemarket "github.com/filecoin-project/go-fil-markets/storagemarket" auth "github.com/filecoin-project/go-jsonrpc/auth" multistore "github.com/filecoin-project/go-multistore" @@ -444,6 +445,20 @@ func (mr *MockFullNodeMockRecorder) ClientCancelDataTransfer(arg0, arg1, arg2, a return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClientCancelDataTransfer", reflect.TypeOf((*MockFullNode)(nil).ClientCancelDataTransfer), arg0, arg1, arg2, arg3) } +// ClientCancelRetrievalDeal mocks base method +func (m *MockFullNode) ClientCancelRetrievalDeal(arg0 context.Context, arg1 retrievalmarket.DealID) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ClientCancelRetrievalDeal", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ClientCancelRetrievalDeal indicates an expected call of ClientCancelRetrievalDeal +func (mr *MockFullNodeMockRecorder) ClientCancelRetrievalDeal(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClientCancelRetrievalDeal", reflect.TypeOf((*MockFullNode)(nil).ClientCancelRetrievalDeal), arg0, arg1) +} + // ClientDataTransferUpdates mocks base method func (m *MockFullNode) ClientDataTransferUpdates(arg0 context.Context) (<-chan api.DataTransferChannel, error) { m.ctrl.T.Helper() diff --git a/cli/client.go b/cli/client.go index 98f4b022927..67fc7faff24 100644 --- a/cli/client.go +++ b/cli/client.go @@ -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), @@ -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", diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index 49afeeb1a0a..f7098f91008 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -34,6 +34,7 @@ * [Client](#Client) * [ClientCalcCommP](#ClientCalcCommP) * [ClientCancelDataTransfer](#ClientCancelDataTransfer) + * [ClientCancelRetrievalDeal](#ClientCancelRetrievalDeal) * [ClientDataTransferUpdates](#ClientDataTransferUpdates) * [ClientDealPieceCID](#ClientDealPieceCID) * [ClientDealSize](#ClientDealSize) @@ -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. diff --git a/node/impl/client/client.go b/node/impl/client/client.go index ac526ac6030..54fef4264dd 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -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)