Skip to content

Commit 7f5f806

Browse files
authored
Merge pull request #8672 from mohamedawnallah/makeDeleteAllPaymentsArgsRequired
rpcserver: Make sure the arguments are provided when calling `DeleteAllPayments` RPC
2 parents 8ce3622 + b683b38 commit 7f5f806

File tree

7 files changed

+984
-933
lines changed

7 files changed

+984
-933
lines changed

cmd/lncli/cmd_payments.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@ func deletePayments(ctx *cli.Context) error {
17831783
what)
17841784
_, err = client.DeleteAllPayments(
17851785
ctxc, &lnrpc.DeleteAllPaymentsRequest{
1786+
AllPayments: includeNonFailed,
17861787
FailedPaymentsOnly: !includeNonFailed,
17871788
FailedHtlcsOnly: failedHTLCsOnly,
17881789
},

docs/release-notes/release-notes-0.18.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor
355355
`budget`, and `deadline_height`, the fields `force`, `requested_conf_target`,
356356
and `next_broadcast_height` are deprecated.
357357

358+
* [Delete All Payments RPC](https://github.com/lightningnetwork/lnd/pull/8672)
359+
adds `all_payments` option to the `DeleteAllPayments` RPC. This update
360+
ensures that the arguments are provided when calling `DeleteAllPayments` RPC,
361+
whether through gRPC or the REST API, due to the destructive nature of the
362+
operation.
363+
358364
## lncli Updates
359365

360366
* [Documented all available `lncli`

lnrpc/lightning.pb.go

Lines changed: 944 additions & 932 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,6 +4231,10 @@ message DeleteAllPaymentsRequest {
42314231
Only delete failed HTLCs from payments, not the payment itself.
42324232
*/
42334233
bool failed_htlcs_only = 2;
4234+
4235+
// Delete all payments. NOTE: Using this option requires careful
4236+
// consideration as it is a destructive operation.
4237+
bool all_payments = 3;
42344238
}
42354239

42364240
message DeletePaymentResponse {

lnrpc/lightning.swagger.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,13 @@
22682268
"in": "query",
22692269
"required": false,
22702270
"type": "boolean"
2271+
},
2272+
{
2273+
"name": "all_payments",
2274+
"description": "Delete all payments. NOTE: Using this option requires careful\nconsideration as it is a destructive operation.",
2275+
"in": "query",
2276+
"required": false,
2277+
"type": "boolean"
22712278
}
22722279
],
22732280
"tags": [

lntest/rpc/lnd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (h *HarnessRPC) DeleteAllPayments() {
7070
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
7171
defer cancel()
7272

73-
req := &lnrpc.DeleteAllPaymentsRequest{}
73+
req := &lnrpc.DeleteAllPaymentsRequest{AllPayments: true}
7474
_, err := h.LN.DeleteAllPayments(ctxt, req)
7575
h.NoError(err, "DeleteAllPayments")
7676
}

rpcserver.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6763,6 +6763,27 @@ func (r *rpcServer) DeleteAllPayments(ctx context.Context,
67636763
req *lnrpc.DeleteAllPaymentsRequest) (
67646764
*lnrpc.DeleteAllPaymentsResponse, error) {
67656765

6766+
switch {
6767+
// Since this is a destructive operation, at least one of the options
6768+
// must be set to true.
6769+
case !req.AllPayments && !req.FailedPaymentsOnly &&
6770+
!req.FailedHtlcsOnly:
6771+
6772+
return nil, fmt.Errorf("at least one of the options " +
6773+
"`all_payments`, `failed_payments_only`, or " +
6774+
"`failed_htlcs_only` must be set to true")
6775+
6776+
// `all_payments` cannot be true with `failed_payments_only` or
6777+
// `failed_htlcs_only`. `all_payments` includes all records, making
6778+
// these options contradictory.
6779+
case req.AllPayments &&
6780+
(req.FailedPaymentsOnly || req.FailedHtlcsOnly):
6781+
6782+
return nil, fmt.Errorf("`all_payments` cannot be set to true " +
6783+
"while either `failed_payments_only` or " +
6784+
"`failed_htlcs_only` is also set to true")
6785+
}
6786+
67666787
rpcsLog.Infof("[DeleteAllPayments] failed_payments_only=%v, "+
67676788
"failed_htlcs_only=%v", req.FailedPaymentsOnly,
67686789
req.FailedHtlcsOnly)

0 commit comments

Comments
 (0)