lnd: add DeletePayment to the RPC

The RPC DeletePayment allows deleteing  single payment from its ID. When calling with `FailedHtlcsOnly` set in the request only failed HTLCs of this payment will be deleted.
This commit is contained in:
Bjarne Magnussen
2021-09-13 11:32:28 +02:00
parent a5641c5351
commit 7f53656753
8 changed files with 878 additions and 496 deletions

View File

@ -442,6 +442,10 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
Entity: "offchain",
Action: "read",
}},
"/lnrpc.Lightning/DeletePayment": {{
Entity: "offchain",
Action: "write",
}},
"/lnrpc.Lightning/DeleteAllPayments": {{
Entity: "offchain",
Action: "write",
@ -5934,6 +5938,31 @@ func (r *rpcServer) ListPayments(ctx context.Context,
return paymentsResp, nil
}
// DeletePayment deletes a payment from the DB given its payment hash. If
// failedHtlcsOnly is set, only failed HTLC attempts of the payment will be
// deleted.
func (r *rpcServer) DeletePayment(ctx context.Context,
req *lnrpc.DeletePaymentRequest) (
*lnrpc.DeletePaymentResponse, error) {
hash, err := lntypes.MakeHash(req.PaymentHash)
if err != nil {
return nil, err
}
rpcsLog.Infof("[DeletePayment] payment_identifier=%v, "+
"failed_htlcs_only=%v", hash, req.FailedHtlcsOnly)
err = r.server.chanStateDB.DeletePayment(
hash, req.FailedHtlcsOnly,
)
if err != nil {
return nil, err
}
return &lnrpc.DeletePaymentResponse{}, nil
}
// DeleteAllPayments deletes all outgoing payments from DB.
func (r *rpcServer) DeleteAllPayments(ctx context.Context,
req *lnrpc.DeleteAllPaymentsRequest) (