channeldb+rpcserver: return number of deleted payments

This commit is contained in:
Oliver Gugger
2024-11-06 15:30:21 +01:00
parent e3cc4d70c0
commit 15a5fe7704
3 changed files with 34 additions and 16 deletions

View File

@@ -826,10 +826,12 @@ func (d *DB) DeletePayment(paymentHash lntypes.Hash,
// DeletePayments deletes all completed and failed payments from the DB. If
// failedOnly is set, only failed payments will be considered for deletion. If
// failedHtlsOnly is set, the payment itself won't be deleted, only failed HTLC
// attempts.
func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error {
return kvdb.Update(d, func(tx kvdb.RwTx) error {
// failedHtlcsOnly is set, the payment itself won't be deleted, only failed HTLC
// attempts. The method returns the number of deleted payments, which is always
// 0 if failedHtlcsOnly is set.
func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) (int, error) {
var numPayments int
err := kvdb.Update(d, func(tx kvdb.RwTx) error {
payments := tx.ReadWriteBucket(paymentsRootBucket)
if payments == nil {
return nil
@@ -906,6 +908,7 @@ func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error {
}
deleteIndexes = append(deleteIndexes, seqNrs...)
numPayments++
return nil
})
if err != nil {
@@ -956,7 +959,14 @@ func (d *DB) DeletePayments(failedOnly, failedHtlcsOnly bool) error {
}
return nil
}, func() {})
}, func() {
numPayments = 0
})
if err != nil {
return 0, err
}
return numPayments, nil
}
// fetchSequenceNumbers fetches all the sequence numbers associated with a