rpcserver+channeldb: delete only failed payments if requested

This commit is contained in:
Johan T. Halseth
2019-06-11 15:11:24 +02:00
parent 0ef2ca06c1
commit 7e3738d773
3 changed files with 68 additions and 12 deletions

View File

@@ -677,7 +677,7 @@ func fetchPaymentWithSequenceNumber(tx kvdb.RTx, paymentHash lntypes.Hash,
}
// DeletePayments deletes all completed and failed payments from the DB.
func (db *DB) DeletePayments() error {
func (db *DB) DeletePayments(failedOnly bool) error {
return kvdb.Update(db, func(tx kvdb.RwTx) error {
payments := tx.ReadWriteBucket(paymentsRootBucket)
if payments == nil {
@@ -715,6 +715,12 @@ func (db *DB) DeletePayments() error {
return nil
}
// If we requested to only delete failed payments, we
// can return if this one is not.
if failedOnly && paymentStatus != StatusFailed {
return nil
}
// Add the bucket to the set of buckets we can delete.
deleteBuckets = append(deleteBuckets, k)