Skip to content

Commit ab5cd5f

Browse files
committed
multi: fix payment failure overwrite
We now make sure we do not overwrite the payment failure status if it is already set and return an error. When using sendtoroute we might fail a payment twice hence we do not error out if we fail a payment twice.
1 parent 5fe900d commit ab5cd5f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: channeldb/payment_control.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,23 @@ func (p *PaymentControl) Fail(paymentHash lntypes.Hash,
582582
// lets the last attempt to fail with a terminal write its
583583
// failure to the PaymentControl without synchronizing with
584584
// other attempts.
585-
_, err = fetchPaymentStatus(bucket)
585+
status, err := fetchPaymentStatus(bucket)
586586
if errors.Is(err, ErrPaymentNotInitiated) {
587587
updateErr = ErrPaymentNotInitiated
588588
return nil
589589
} else if err != nil {
590590
return err
591591
}
592592

593+
// We make sure that if the payment is already failed we do not
594+
// overwrite the failure reason and remain consistent. We do
595+
// not return the error in the batch function to avoid retrying
596+
// the transaction.
597+
if status == StatusFailed {
598+
updateErr = ErrPaymentAlreadyFailed
599+
return nil
600+
}
601+
593602
// Put the failure reason in the bucket for record keeping.
594603
v := []byte{byte(reason)}
595604
err = bucket.Put(paymentFailInfoKey, v)

Diff for: routing/router.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,12 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
12001200
// as failed if we don't skip temp error.
12011201
if !skipTempErr {
12021202
err := r.cfg.Control.FailPayment(paymentIdentifier, reason)
1203-
if err != nil {
1203+
1204+
// We might to attempt to fail the payment twice here because
1205+
// the payment might already be failed when handling the switch
1206+
// error in the result collector.
1207+
if err != nil &&
1208+
!errors.Is(err, channeldb.ErrPaymentAlreadyFailed) {
12041209
return nil, err
12051210
}
12061211
}

0 commit comments

Comments
 (0)