@@ -788,3 +788,59 @@ func testForwardBlindedRoute(ht *lntest.HarnessTest) {
788788 ht .AssertHTLCNotActive (ht .Bob , testCase .channels [1 ], hash [:])
789789 ht .AssertHTLCNotActive (ht .Alice , testCase .channels [0 ], hash [:])
790790}
791+
792+ // Tests handling of errors from the receiving node in a blinded route, testing
793+ // a payment over: Alice -- Bob -- Carol -- Dave, where Bob is the introduction
794+ // node.
795+ //
796+ // Note that at present the payment fails at Dave because we do not yet support
797+ // receiving to blinded routes. In future, we can substitute this test out to
798+ // trigger an IncorrectPaymentDetails failure. In the meantime, this test
799+ // provides valuable coverage for the case where a node in the route is not
800+ // spec compliant (ie, does not return the blinded failure and just uses a
801+ // normal one) because Dave will not appropriately convert the error.
802+ func testReceiverBlindedError (ht * lntest.HarnessTest ) {
803+ ctx , testCase := newBlindedForwardTest (ht )
804+ defer testCase .cleanup ()
805+ route := testCase .setup (ctx )
806+
807+ sendAndResumeBlindedPayment (ctx , ht , testCase , route )
808+ }
809+
810+ // sendAndResumeBlindedPayment sends a blinded payment through the test
811+ // network provided, intercepting the payment at Carol and allowing it to
812+ // resume. This utility function allows us to ensure that payments at least
813+ // reach Carol and asserts that all errors appear to originate from the
814+ // introduction node.
815+ func sendAndResumeBlindedPayment (ctx context.Context , ht * lntest.HarnessTest ,
816+ testCase * blindedForwardTest , route * routing.BlindedPayment ) {
817+
818+ blindedRoute := testCase .createRouteToBlinded (10_000_000 , route )
819+
820+ // Before we dispatch the payment, spin up a goroutine that will
821+ // intercept the HTLC on Carol's forward. This allows us to ensure
822+ // that the HTLC actually reaches the location we expect it to.
823+ resolveHTLC := testCase .interceptFinalHop ()
824+
825+ // First, test sending the payment all the way through to Dave. We
826+ // expect this payment to fail, because he does not know how to
827+ // process payments to a blinded route (not yet supported).
828+ testCase .sendBlindedPayment (ctx , blindedRoute )
829+
830+ // When Carol intercepts the HTLC, instruct her to resume the payment
831+ // so that it'll reach Dave and fail.
832+ resolveHTLC (routerrpc .ResolveHoldForwardAction_RESUME )
833+
834+ // Wait for the HTLC to reflect as failed for Alice.
835+ preimage , err := lntypes .MakePreimage (testCase .preimage [:])
836+ require .NoError (ht , err )
837+ pmt := ht .AssertPaymentStatus (ht .Alice , preimage , lnrpc .Payment_FAILED )
838+ require .Len (ht , pmt .Htlcs , 1 )
839+ require .EqualValues (
840+ ht , 1 , pmt .Htlcs [0 ].Failure .FailureSourceIndex ,
841+ )
842+ require .Equal (
843+ ht , lnrpc .Failure_INVALID_ONION_BLINDING ,
844+ pmt .Htlcs [0 ].Failure .Code ,
845+ )
846+ }
0 commit comments