Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions payments/db/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,49 @@ func (s *SQLStore) FetchPayment(paymentHash lntypes.Hash) (*MPPayment, error) {

return mpPayment, 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 (s *SQLStore) DeletePayment(paymentHash lntypes.Hash,
failedHtlcsOnly bool) error {

ctx := context.TODO()

err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
fetchPayment, err := db.FetchPayment(ctx, paymentHash[:])
if err != nil {
return fmt.Errorf("failed to fetch payment: %w", err)
}
completePayment, err := s.fetchPaymentWithCompleteData(
ctx, db, fetchPayment,
)
if err != nil {
Comment on lines +556 to +559
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we need to fetch the complete payment here?

return fmt.Errorf("failed to fetch payment with "+
"complete data: %w", err)
}

if err := completePayment.Status.removable(); err != nil {
return fmt.Errorf("payment %v cannot be deleted: %w",
paymentHash, err)
}

// If we are only deleting failed HTLCs, we delete them.
if failedHtlcsOnly {
return s.db.DeleteFailedAttempts(
ctx, fetchPayment.Payment.ID,
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like the next commit should be before this one?


return db.DeletePayment(ctx, fetchPayment.Payment.ID)

}, func() {
})
Comment on lines +580 to +581
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoOpReset

if err != nil {
return fmt.Errorf("failed to delete payment "+
"(failedHtlcsOnly: %v, paymentHash: %v): %w",
failedHtlcsOnly, paymentHash, err)
}

return nil
}