Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: fix payment failure overwrite #9543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion channeldb/payment_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,24 @@ func (p *PaymentControl) Fail(paymentHash lntypes.Hash,
// lets the last attempt to fail with a terminal write its
// failure to the PaymentControl without synchronizing with
// other attempts.
_, err = fetchPaymentStatus(bucket)
status, err := fetchPaymentStatus(bucket)
if errors.Is(err, ErrPaymentNotInitiated) {
updateErr = ErrPaymentNotInitiated
return nil
} else if err != nil {
return err
}

// We make sure that if the payment is already failed we do not
// overwrite the failure reason and remain consistent. We do
// not return the error in the batch function to avoid retrying
// the transaction.
if status == StatusFailed {
updateErr = ErrPaymentAlreadyFailed

return nil
}

// Put the failure reason in the bucket for record keeping.
v := []byte{byte(reason)}
err = bucket.Put(paymentFailInfoKey, v)
Expand Down
7 changes: 6 additions & 1 deletion routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,12 @@
// as failed if we don't skip temp error.
if !skipTempErr {
err := r.cfg.Control.FailPayment(paymentIdentifier, reason)
if err != nil {

Copy link
Member

Choose a reason for hiding this comment

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

I think a better approach is to perform a check on this payment, if it's already failed, we skip calling the above FailPayment. We don't wanna this single case to change the underlying logic/assumptions for our CRUD.

// We might attempt to fail the payment twice here because the
// payment might already be failed when handling the switch
// error in the result collector.
if err != nil &&
!errors.Is(err, channeldb.ErrPaymentAlreadyFailed) {

Check failure on line 1208 in routing/router.go

View workflow job for this annotation

GitHub Actions / lint code

multi-line statement should be followed by a newline (whitespace)
return nil, err
}
}
Expand Down
Loading