@@ -517,19 +517,25 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
517517 // Now that Bob has claimed his HTLCs, Alice should mark the two
518518 // payments as failed.
519519 //
520- // Alice will mark this payment as failed with no route as the only
521- // route she has is Alice->Bob->Carol. This won't be the case if she
522- // has a second route, as another attempt will be tried.
523- //
524- // TODO(yy): we should instead mark this payment as timed out if she has
525- // a second route to try this payment, which is the timeout set by Alice
526- // when sending the payment.
527- expectedReason := lnrpc .PaymentFailureReason_FAILURE_REASON_NO_ROUTE
528- p := ht .AssertPaymentFailureReason (alice , preimage , expectedReason )
520+ // Alice's payment can fail with either NO_ROUTE or TIMEOUT depending
521+ // on timing. There's a race between:
522+ // 1. The channel closure propagating to Alice's graph (-> NO_ROUTE)
523+ // 2. The payment attempt timeout firing (-> TIMEOUT)
524+ // Both failure reasons are correct.
525+ p := ht .AssertPaymentFailureReasonAny (alice , preimage ,
526+ lnrpc .PaymentFailureReason_FAILURE_REASON_NO_ROUTE ,
527+ lnrpc .PaymentFailureReason_FAILURE_REASON_TIMEOUT ,
528+ )
529+
530+ // The HTLC-level failure code should be PERMANENT_CHANNEL_FAILURE
531+ // regardless of which payment-level failure reason we got.
529532 require .Equal (ht , lnrpc .Failure_PERMANENT_CHANNEL_FAILURE ,
530533 p .Htlcs [0 ].Failure .Code )
531534
532- p = ht .AssertPaymentFailureReason (alice , preimageDust , expectedReason )
535+ p = ht .AssertPaymentFailureReasonAny (alice , preimageDust ,
536+ lnrpc .PaymentFailureReason_FAILURE_REASON_NO_ROUTE ,
537+ lnrpc .PaymentFailureReason_FAILURE_REASON_TIMEOUT ,
538+ )
533539 require .Equal (ht , lnrpc .Failure_PERMANENT_CHANNEL_FAILURE ,
534540 p .Htlcs [0 ].Failure .Code )
535541}
0 commit comments