diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index fa3a1a8e968..fcbfcdccdfd 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -2822,3 +2822,74 @@ func restoreChanBackup(ctx *cli.Context) error { return nil } + +var deletePaymentsCommand = cli.Command{ + Name: "delpayments", + Category: "payments", + Usage: "Delete all payments, only failed payments, or only the HTLCs associated with faild payments", + Description: ` + Delete payments on disk to free up disk space. Failed payments include the + 1.3KB onion route associated with each payment route so over time they can + take up space. Repeated payment attempt result in + failed payments that are never automatically deleted. + + This command allows you to either delete all payments, only failed + payments, or only the HTLCs associated with failed payments. + `, + ArgsUsage: "[--all | --failed | --filed_htlc]", + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "all", + Usage: "delete ALL payments, which includes successful and failed ones", + }, + cli.BoolFlag{ + Name: "failed", + Usage: "only delete FAILED payments", + }, + cli.BoolFlag{ + Name: "failed_htlc", + Usage: "only delete the HTLC data associated with failed payments", + }, + }, + Action: deletePayments, +} + +func deletePayments(ctx *cli.Context) error { + ctxc := getContext() + client, cleanUp := getClient(ctx) + defer cleanUp() + + // Show command help if no arguments provided + if ctx.NArg() == 0 && ctx.NumFlags() == 0 { + cli.ShowCommandHelp(ctx, "delpayments") + return nil + } + + req := &lnrpc.DeleteAllPaymentsRequest{} + var delType string + switch { + case ctx.Bool("all"): + delType = "all payments" + break + + case ctx.Bool("failed"): + delType = "failed payments" + req.FailedPaymentsOnly = true + + case ctx.Bool("failed_htlc"): + delType = "failed HTLCs" + req.FailedHtlcsOnly = true + + default: + return fmt.Errorf("must specify one of the selector flags") + } + + fmt.Printf("Deleting %v...\n", delType) + _, err := client.DeleteAllPayments(ctxc, req) + if err != nil { + return err + } + + fmt.Printf("%v successfully deleted!\n", delType) + return nil +} diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 83b9d1df5c4..731b05686c0 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -383,6 +383,7 @@ func main() { versionCommand, profileSubCommand, getStateCommand, + deletePaymentsCommand, } // Add any extra commands determined by build flags. diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index c0717d5b4b2..dadde9f65a4 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -70,7 +70,7 @@ the remote peer supports said channel type and agrees, the previous implicit negotiation based on the shared set of feature bits is bypassed, and the proposed channel type is used. -## RPC Server +## RPC Server & `lncli` * [Return payment address and add index from addholdinvoice call](https://github.com/lightningnetwork/lnd/pull/5533). @@ -106,6 +106,10 @@ proposed channel type is used. requests made with custom macaroons (and also the responses to those requests). + * [A new lncli command has been added to expose the RPC command to delete + payments over the command + line](https://github.com/lightningnetwork/lnd/pull/5778): `delpayments`. + ### Batched channel funding [Multiple channels can now be opened in a single diff --git a/lnrpc/lightning.proto b/lnrpc/lightning.proto index 86690a76087..770923b280d 100644 --- a/lnrpc/lightning.proto +++ b/lnrpc/lightning.proto @@ -345,7 +345,7 @@ service Lightning { */ rpc DeletePayment (DeletePaymentRequest) returns (DeletePaymentResponse); - /* + /* lncli: `delpayments` DeleteAllPayments deletes all outgoing payments from DB. Note that it will not attempt to delete In-Flight payments, since that would be unsafe. */ diff --git a/lnrpc/lightning.swagger.json b/lnrpc/lightning.swagger.json index 75428c6c761..bb6fa50a32a 100644 --- a/lnrpc/lightning.swagger.json +++ b/lnrpc/lightning.swagger.json @@ -1859,7 +1859,7 @@ ] }, "delete": { - "summary": "DeleteAllPayments deletes all outgoing payments from DB. Note that it will\nnot attempt to delete In-Flight payments, since that would be unsafe.", + "summary": "lncli: `delpayments`\nDeleteAllPayments deletes all outgoing payments from DB. Note that it will\nnot attempt to delete In-Flight payments, since that would be unsafe.", "operationId": "Lightning_DeleteAllPayments", "responses": { "200": { diff --git a/lnrpc/lightning_grpc.pb.go b/lnrpc/lightning_grpc.pb.go index e2fdb367587..4c3ad4ef3d8 100644 --- a/lnrpc/lightning_grpc.pb.go +++ b/lnrpc/lightning_grpc.pb.go @@ -252,7 +252,7 @@ type LightningClient interface { //DeletePayment deletes an outgoing payment from DB. Note that it will not //attempt to delete an In-Flight payment, since that would be unsafe. DeletePayment(ctx context.Context, in *DeletePaymentRequest, opts ...grpc.CallOption) (*DeletePaymentResponse, error) - // + // lncli: `delpayments` //DeleteAllPayments deletes all outgoing payments from DB. Note that it will //not attempt to delete In-Flight payments, since that would be unsafe. DeleteAllPayments(ctx context.Context, in *DeleteAllPaymentsRequest, opts ...grpc.CallOption) (*DeleteAllPaymentsResponse, error) @@ -1492,7 +1492,7 @@ type LightningServer interface { //DeletePayment deletes an outgoing payment from DB. Note that it will not //attempt to delete an In-Flight payment, since that would be unsafe. DeletePayment(context.Context, *DeletePaymentRequest) (*DeletePaymentResponse, error) - // + // lncli: `delpayments` //DeleteAllPayments deletes all outgoing payments from DB. Note that it will //not attempt to delete In-Flight payments, since that would be unsafe. DeleteAllPayments(context.Context, *DeleteAllPaymentsRequest) (*DeleteAllPaymentsResponse, error)