diff --git a/doc/lightning-delpay.7 b/doc/lightning-delpay.7 index 2db30bc8ccb1..644e5fcf548e 100644 --- a/doc/lightning-delpay.7 +++ b/doc/lightning-delpay.7 @@ -8,14 +8,14 @@ lightning-delpay - Command for removing a completed or failed payment .SH DESCRIPTION The \fBdelpay\fR RPC command removes a payment as given in \fBlistsendpays\fR or \fBlistpays\fR with a complete or failed -status\. However, the command doesn't permit to remove a pending payment\. +status\. Deleting a \fBpending\fR payment is an error\. .RS .IP \[bu] -\fIpayment_hash\fR: Rapresents the unique identifier of a payment\. To find it, you can run \fBlistpays\fR or \fBlistsendpays\fR; +\fIpayment_hash\fR: The unique identifier of a payment\. Find it, you can run \fBlistpays\fR or \fBlistsendpays\fR; .IP \[bu] -\fIstatus\fR is the expected status of the payment\. It can be \fIcomplete\fR or \fIfailed\fR\. -Only delete if the payment status matches\. If not specified, defaults to \fIcomplete\fR\. +\fIstatus\fR: Expected status of the payment\. Valid values are \fIcomplete\fR or \fIfailed\fR\. +Only deletes if the payment status matches\. If not specified, defaults to \fIcomplete\fR\. .RE .SH EXAMPLE JSON REQUEST @@ -34,11 +34,11 @@ Only delete if the payment status matches\. If not specified, defaults to \fIcom .fi .SH RETURN VALUE -On success, the command will return a payment object, such as the \fBlistsendpays\fR\. In addition, if the payment is a MPP (Multi part payment) the command return a list of -payments; a payment object for each partid\. +On success, the command will return a payment object, such as the \fBlistsendpays\fR\. If the payment is aa MPP (multi part payment) the command return a list of +payments will be return -- one payment object for each partid\. -On failure, an error is returned and any payment is deleted\. If the lightning process fails before responding, the +On failure, an error is returned\. If the lightning process fails before responding, the caller should use \fBlightning-listsentpays\fR(7) or \fBlightning-listpays\fR(7) to query whether this payment was deleted or not\. @@ -46,9 +46,9 @@ The following error codes may occur: .RS .IP \[bu] --32602: Some parameter missed or some parameter is malformed; +-32602: Parameter missed or malformed; .IP \[bu] -211: Payment with payment_hash have a wrong status\. To check the correct status run the command \fBpaystatus\fR; +211: Payment status mismatch\. Check the correct status via \fBpaystatus\fR; .IP \[bu] 208: Payment with payment_hash not found\. diff --git a/doc/lightning-delpay.7.md b/doc/lightning-delpay.7.md index b578ef54976d..fa9924358ff6 100644 --- a/doc/lightning-delpay.7.md +++ b/doc/lightning-delpay.7.md @@ -10,11 +10,11 @@ DESCRIPTION ----------- The **delpay** RPC command removes a payment as given in **listsendpays** or **listpays** with a complete or failed -status. However, the command doesn't permit to remove a pending payment. +status. Deleting a `pending` payment is an error. -- *payment\_hash*: Rapresents the unique identifier of a payment. To find it, you can run **listpays** or **listsendpays**; -- *status* is the expected status of the payment. It can be *complete* or *failed*. -Only delete if the payment status matches. If not specified, defaults to *complete*. +- *payment\_hash*: The unique identifier of a payment. Find it, you can run **listpays** or **listsendpays**; +- *status*: Expected status of the payment. Valid values are *complete* or *failed*. +Only deletes if the payment status matches. If not specified, defaults to *complete*. EXAMPLE JSON REQUEST ------------ @@ -32,16 +32,16 @@ EXAMPLE JSON REQUEST RETURN VALUE ------------ -On success, the command will return a payment object, such as the **listsendpays**. In addition, if the payment is a MPP (Multi part payment) the command return a list of -payments; a payment object for each partid. +On success, the command will return a payment object, such as the **listsendpays**. If the payment is aa MPP (multi part payment) the command return a list of +payments will be return -- one payment object for each partid. -On failure, an error is returned and any payment is deleted. If the lightning process fails before responding, the +On failure, an error is returned. If the lightning process fails before responding, the caller should use lightning-listsentpays(7) or lightning-listpays(7) to query whether this payment was deleted or not. The following error codes may occur: -- -32602: Some parameter missed or some parameter is malformed; -- 211: Payment with payment\_hash have a wrong status. To check the correct status run the command **paystatus**; +- -32602: Parameter missed or malformed; +- 211: Payment status mismatch. Check the correct status via **paystatus**; - 208: Payment with payment\_hash not found. EXAMPLE JSON RESPONSE diff --git a/lightningd/pay.c b/lightningd/pay.c index e0eab41173db..2ed5e813914f 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -64,9 +64,11 @@ static const char *payment_status_to_string(const enum wallet_payment_status sta return "complete"; case PAYMENT_FAILED: return "failed"; - default: + case PAYMENT_PENDING: return "pending"; } + //This should never happen + abort(); } @@ -1548,8 +1550,7 @@ static struct command_result *json_delpay(struct command *cmd, status_str = "complete"; if (!string_to_payment_status(status_str, &status)) - return command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "Unrecognized status: %s", status_str); + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str); if (status == PAYMENT_PENDING) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid status: %s", @@ -1558,17 +1559,15 @@ static struct command_result *json_delpay(struct command *cmd, payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash); if (tal_count(payments) == 0) - return command_fail(cmd, PAY_NO_SUCH_PAYMENT, - "Unknown payment with payment_hash: %s", + return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s", type_to_string(tmpctx, struct sha256, payment_hash)); for (int i = 0; i < tal_count(payments); i++) { if (payments[i]->status != status) { - return command_fail(cmd, PAY_STATUS_UNEXPECTED, - "Payment with hash %s has %s status but it should be %s", + return command_fail(cmd, PAY_STATUS_UNEXPECTED, "Payment with hash %s has %s status but it should be %s", type_to_string(tmpctx, struct sha256, payment_hash), payment_status_to_string(payments[i]->status), - payment_status_to_string(status)); + payment_status_to_string(status)); } } diff --git a/tests/test_pay.py b/tests/test_pay.py index 2e57ae1ca2f8..8e8892b8da5e 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3272,13 +3272,13 @@ def test_delpay_argument_invalid(node_factory, bitcoind): with pytest.raises(RpcError): l2.rpc.delpay() - # invoice unpayed + # invoice unpaid inv = l1.rpc.invoice(10 ** 5, 'inv', 'inv') payment_hash = inv["payment_hash"] with pytest.raises(RpcError): l2.rpc.delpay(payment_hash) - # payment unpayed with wrong status (pending status is a illegal input) + # payment unpaid with wrong status (pending status is a illegal input) with pytest.raises(RpcError): l2.rpc.delpay(payment_hash, 'pending') @@ -3311,39 +3311,9 @@ def test_delpay_argument_invalid(node_factory, bitcoind): assert len(l2.rpc.listpays()['pays']) == 0 -def test_delpay(node_factory, bitcoind): - """ - This unit test try to catch some error inside the command - delpay when it receives the correct input from the user - """ - - l1, l2 = node_factory.get_nodes(2) - - amount_sat = 10 ** 6 - - # create l2->l1 channel. - l2.fundwallet(amount_sat * 5) - l1.rpc.connect(l2.info['id'], 'localhost', l2.port) - l2.rpc.fundchannel(l1.info['id'], amount_sat * 3) - - # Let the channel confirm. - bitcoind.generate_block(6) - sync_blockheight(bitcoind, [l1, l2]) - - invl1 = l1.rpc.invoice(Millisatoshi(amount_sat * 2 * 1000), "j", "j") - l2.rpc.pay(invl1["bolt11"]) - - before_del_pay = l2.rpc.listpays() - - l2.rpc.delpay(invl1["payment_hash"]) - - after_del_pay = l2.rpc.listpays()["pays"] - assert len(after_del_pay) == (len(before_del_pay) - 1) - - def test_delpay_payment_split(node_factory, bitcoind): """ - This test test the correct bheaivord of the commmand delpay with a mpp + Test behavior of delpay with an MPP """ MPP_TARGET_SIZE = 10**7 # Taken from libpluin-pay.c amt = 5 * MPP_TARGET_SIZE