11package itest
22
33import (
4- "bytes"
54 "context"
5+ "crypto/rand"
66 "fmt"
77 "math"
88 "math/big"
@@ -32,6 +32,7 @@ import (
3232 "github.com/lightningnetwork/lnd/lntest"
3333 "github.com/lightningnetwork/lnd/lntest/node"
3434 "github.com/lightningnetwork/lnd/lntest/port"
35+ "github.com/lightningnetwork/lnd/lntypes"
3536 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
3637 "github.com/lightningnetwork/lnd/lnwire"
3738 "github.com/stretchr/testify/require"
@@ -633,8 +634,8 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
633634 // to rounding errors that happened when sending multiple shards with
634635 // MPP, we need to do some slight adjustments.
635636 charlieAssetBalance += 1
636- erinAssetBalance += 4
637- fabiaAssetBalance -= 4
637+ erinAssetBalance += 3
638+ fabiaAssetBalance -= 3
638639 yaraAssetBalance -= 1
639640 itest .AssertBalances (
640641 t .t , charlieTap , charlieAssetBalance ,
@@ -1075,8 +1076,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
10751076 // MPP, we need to do some slight adjustments.
10761077 charlieAssetBalance += 2
10771078 daveAssetBalance -= 1
1078- erinAssetBalance += 4
1079- fabiaAssetBalance -= 4
1079+ erinAssetBalance += 3
1080+ fabiaAssetBalance -= 3
10801081 yaraAssetBalance -= 1
10811082 itest .AssertBalances (
10821083 t .t , charlieTap , charlieAssetBalance ,
@@ -2720,30 +2721,65 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
27202721
27212722 // We now manually add the invoice in order to inject the above,
27222723 // manually generated, quote.
2723- iResp , err := charlie .AddInvoice (ctx , & lnrpc.Invoice {
2724- Memo : "" ,
2725- Value : 200_000 ,
2726- RPreimage : bytes .Repeat ([]byte {11 }, 32 ),
2727- CltvExpiry : 60 ,
2728- RouteHints : []* lnrpc.RouteHint {{
2729- HopHints : []* lnrpc.HopHint {{
2730- NodeId : dave .PubKeyStr ,
2731- ChanId : quote .AcceptedQuote .Scid ,
2724+ hint := & lnrpc.HopHint {
2725+ NodeId : dave .PubKeyStr ,
2726+ ChanId : quote .AcceptedQuote .Scid ,
2727+ CltvExpiryDelta : 80 ,
2728+ FeeBaseMsat : 1000 ,
2729+ FeeProportionalMillionths : 1 ,
2730+ }
2731+ var preimage lntypes.Preimage
2732+ _ , _ = rand .Read (preimage [:])
2733+ payHash = preimage .Hash ()
2734+ iResp , err := charlie .AddHoldInvoice (
2735+ ctx , & invoicesrpc.AddHoldInvoiceRequest {
2736+ Memo : "" ,
2737+ Value : 200_000 ,
2738+ Hash : payHash [:],
2739+ RouteHints : []* lnrpc.RouteHint {{
2740+ HopHints : []* lnrpc.HopHint {hint },
27322741 }},
2733- }},
2734- })
2742+ },
2743+ )
2744+ require .NoError (t .t , err )
2745+
2746+ htlcStream , err := dave .RouterClient .SubscribeHtlcEvents (
2747+ ctx , & routerrpc.SubscribeHtlcEventsRequest {},
2748+ )
27352749 require .NoError (t .t , err )
27362750
27372751 // Now Erin tries to pay the invoice. Since rfq quote cannot satisfy the
27382752 // total amount of the invoice this payment will fail.
2739- payInvoiceWithSatoshi (
2740- t .t , erin , iResp , withPayErrSubStr ("context deadline exceeded" ),
2741- withFailure (lnrpc .Payment_FAILED , failureNone ),
2742- withGroupKey (groupID ),
2753+ payPayReqWithSatoshi (
2754+ t .t , erin , iResp .PaymentRequest ,
2755+ withFailure (lnrpc .Payment_IN_FLIGHT , failureNone ),
2756+ withGroupKey (groupID ), withMaxShards (4 ),
2757+ )
2758+
2759+ t .Logf ("Asserting number of HTLCs on each node..." )
2760+ assertMinNumHtlcs (t .t , dave , 2 )
2761+
2762+ t .Logf ("Asserting HTLC events on Dave..." )
2763+ assertHtlcEvents (
2764+ t .t , htlcStream , withNumEvents (1 ), withForwardFailure (),
2765+ )
2766+
2767+ _ , err = charlie .InvoicesClient .CancelInvoice (
2768+ ctx , & invoicesrpc.CancelInvoiceMsg {
2769+ PaymentHash : payHash [:],
2770+ },
27432771 )
2772+ require .NoError (t .t , err )
2773+
2774+ assertNumHtlcs (t .t , dave , 0 )
27442775
27452776 logBalance (t .t , nodes , assetID , "after small manual rfq" )
27462777
2778+ _ = htlcStream .CloseSend ()
2779+ _ , _ = erin .RouterClient .ResetMissionControl (
2780+ context .Background (), & routerrpc.ResetMissionControlRequest {},
2781+ )
2782+
27472783 // Edge case: Fabia creates an invoice which Erin cannot satisfy with
27482784 // his side of asset liquidity. This tests that Erin will not try to
27492785 // add an HTLC with more asset units than what his local balance is. To
@@ -2753,7 +2789,7 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
27532789 // We now create a hodl invoice on Fabia, for 125k assets.
27542790 hodlInv = createAssetHodlInvoice (t .t , erin , fabia , 125_000 , assetID )
27552791
2756- htlcStream , err : = erin .RouterClient .SubscribeHtlcEvents (
2792+ htlcStream , err = erin .RouterClient .SubscribeHtlcEvents (
27572793 ctx , & routerrpc.SubscribeHtlcEventsRequest {},
27582794 )
27592795 require .NoError (t .t , err )
@@ -2797,10 +2833,11 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
27972833
27982834 // Now let's create a smaller invoice and pay it, to validate that the
27992835 // channel is still healthy.
2800- invoiceResp = createAssetInvoice (
2801- t .t , erin , fabia , 50_000 , assetID ,
2802- )
2836+ invoiceResp = createAssetInvoice (t .t , erin , fabia , 50_000 , assetID )
28032837
2838+ _ , _ = charlie .RouterClient .ResetMissionControl (
2839+ context .Background (), & routerrpc.ResetMissionControlRequest {},
2840+ )
28042841 payInvoiceWithAssets (
28052842 t .t , charlie , dave , invoiceResp .PaymentRequest , assetID ,
28062843 )
@@ -4154,14 +4191,18 @@ func testCustomChannelsForwardBandwidth(ctx context.Context,
41544191
41554192 // We now manually add the invoice in order to inject the above,
41564193 // manually generated, quote.
4194+ hopHint := & lnrpc.HopHint {
4195+ NodeId : erin .PubKeyStr ,
4196+ ChanId : quote .AcceptedQuote .Scid ,
4197+ CltvExpiryDelta : 80 ,
4198+ FeeBaseMsat : 1000 ,
4199+ FeeProportionalMillionths : 1 ,
4200+ }
41574201 invoiceResp2 , err := fabia .AddInvoice (ctx , & lnrpc.Invoice {
41584202 Memo : "too small invoice" ,
41594203 ValueMsat : int64 (oneUnitMilliSat - 1 ),
41604204 RouteHints : []* lnrpc.RouteHint {{
4161- HopHints : []* lnrpc.HopHint {{
4162- NodeId : erin .PubKeyStr ,
4163- ChanId : quote .AcceptedQuote .Scid ,
4164- }},
4205+ HopHints : []* lnrpc.HopHint {hopHint },
41654206 }},
41664207 })
41674208 require .NoError (t .t , err )
0 commit comments