1
1
package itest
2
2
3
3
import (
4
- "bytes"
5
4
"context"
5
+ "crypto/rand"
6
6
"fmt"
7
7
"math"
8
8
"math/big"
@@ -32,6 +32,7 @@ import (
32
32
"github.com/lightningnetwork/lnd/lntest"
33
33
"github.com/lightningnetwork/lnd/lntest/node"
34
34
"github.com/lightningnetwork/lnd/lntest/port"
35
+ "github.com/lightningnetwork/lnd/lntypes"
35
36
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
36
37
"github.com/lightningnetwork/lnd/lnwire"
37
38
"github.com/stretchr/testify/require"
@@ -633,8 +634,8 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
633
634
// to rounding errors that happened when sending multiple shards with
634
635
// MPP, we need to do some slight adjustments.
635
636
charlieAssetBalance += 1
636
- erinAssetBalance += 4
637
- fabiaAssetBalance -= 4
637
+ erinAssetBalance += 3
638
+ fabiaAssetBalance -= 3
638
639
yaraAssetBalance -= 1
639
640
itest .AssertBalances (
640
641
t .t , charlieTap , charlieAssetBalance ,
@@ -1075,8 +1076,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
1075
1076
// MPP, we need to do some slight adjustments.
1076
1077
charlieAssetBalance += 2
1077
1078
daveAssetBalance -= 1
1078
- erinAssetBalance += 4
1079
- fabiaAssetBalance -= 4
1079
+ erinAssetBalance += 3
1080
+ fabiaAssetBalance -= 3
1080
1081
yaraAssetBalance -= 1
1081
1082
itest .AssertBalances (
1082
1083
t .t , charlieTap , charlieAssetBalance ,
@@ -2720,30 +2721,65 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
2720
2721
2721
2722
// We now manually add the invoice in order to inject the above,
2722
2723
// 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 },
2732
2741
}},
2733
- }},
2734
- })
2742
+ },
2743
+ )
2744
+ require .NoError (t .t , err )
2745
+
2746
+ htlcStream , err := dave .RouterClient .SubscribeHtlcEvents (
2747
+ ctx , & routerrpc.SubscribeHtlcEventsRequest {},
2748
+ )
2735
2749
require .NoError (t .t , err )
2736
2750
2737
2751
// Now Erin tries to pay the invoice. Since rfq quote cannot satisfy the
2738
2752
// 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
+ },
2743
2771
)
2772
+ require .NoError (t .t , err )
2773
+
2774
+ assertNumHtlcs (t .t , dave , 0 )
2744
2775
2745
2776
logBalance (t .t , nodes , assetID , "after small manual rfq" )
2746
2777
2778
+ _ = htlcStream .CloseSend ()
2779
+ _ , _ = erin .RouterClient .ResetMissionControl (
2780
+ context .Background (), & routerrpc.ResetMissionControlRequest {},
2781
+ )
2782
+
2747
2783
// Edge case: Fabia creates an invoice which Erin cannot satisfy with
2748
2784
// his side of asset liquidity. This tests that Erin will not try to
2749
2785
// add an HTLC with more asset units than what his local balance is. To
@@ -2753,7 +2789,7 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
2753
2789
// We now create a hodl invoice on Fabia, for 125k assets.
2754
2790
hodlInv = createAssetHodlInvoice (t .t , erin , fabia , 125_000 , assetID )
2755
2791
2756
- htlcStream , err : = erin .RouterClient .SubscribeHtlcEvents (
2792
+ htlcStream , err = erin .RouterClient .SubscribeHtlcEvents (
2757
2793
ctx , & routerrpc.SubscribeHtlcEventsRequest {},
2758
2794
)
2759
2795
require .NoError (t .t , err )
@@ -2797,10 +2833,11 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
2797
2833
2798
2834
// Now let's create a smaller invoice and pay it, to validate that the
2799
2835
// 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 )
2803
2837
2838
+ _ , _ = charlie .RouterClient .ResetMissionControl (
2839
+ context .Background (), & routerrpc.ResetMissionControlRequest {},
2840
+ )
2804
2841
payInvoiceWithAssets (
2805
2842
t .t , charlie , dave , invoiceResp .PaymentRequest , assetID ,
2806
2843
)
@@ -4154,14 +4191,18 @@ func testCustomChannelsForwardBandwidth(ctx context.Context,
4154
4191
4155
4192
// We now manually add the invoice in order to inject the above,
4156
4193
// 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
+ }
4157
4201
invoiceResp2 , err := fabia .AddInvoice (ctx , & lnrpc.Invoice {
4158
4202
Memo : "too small invoice" ,
4159
4203
ValueMsat : int64 (oneUnitMilliSat - 1 ),
4160
4204
RouteHints : []* lnrpc.RouteHint {{
4161
- HopHints : []* lnrpc.HopHint {{
4162
- NodeId : erin .PubKeyStr ,
4163
- ChanId : quote .AcceptedQuote .Scid ,
4164
- }},
4205
+ HopHints : []* lnrpc.HopHint {hopHint },
4165
4206
}},
4166
4207
})
4167
4208
require .NoError (t .t , err )
0 commit comments