@@ -2237,6 +2237,57 @@ func testCustomChannelsLiquidtyEdgeCasesCore(ctx context.Context,
2237
2237
)
2238
2238
2239
2239
logBalance (t .t , nodes , assetID , "after small manual rfq" )
2240
+
2241
+ // Edge case: Fabia creates an invoice which Erin cannot satisfy with
2242
+ // his side of asset liquidity. This tests that Erin will not try to
2243
+ // add an HTLC with more asset units than what his local balance is. To
2244
+ // validate that the channel is still healthy, we follow up with a
2245
+ // smaller invoice payment which is meant to succeed.
2246
+
2247
+ // We now create a hodl invoice on Fabia, for 125k assets.
2248
+ hodlInv = createAssetHodlInvoice (t .t , erin , fabia , 125_000 , assetID )
2249
+
2250
+ // Charlie tries to pay, this is not meant to succeed, as Erin does not
2251
+ // have enough assets to forward to Fabia.
2252
+ payInvoiceWithAssets (
2253
+ t .t , charlie , dave , hodlInv .payReq , assetID ,
2254
+ withFailure (lnrpc .Payment_IN_FLIGHT , failureNone ),
2255
+ )
2256
+
2257
+ // Let's check that at least 2 HTLCs were added on the Erin->Fabia link,
2258
+ // which means that Erin would have an extra incoming HTLC for each
2259
+ // outgoing one. So we expect a minimum of 4 HTLCs present on Erin.
2260
+ assertMinNumHtlcs (t .t , erin , 4 )
2261
+
2262
+ logBalance (t .t , nodes , assetID , "with min 4 present HTLCs" )
2263
+
2264
+ // Now Fabia cancels the invoice, this is meant to cancel back any
2265
+ // locked in HTLCs and reset Erin's local balance back to its original
2266
+ // value.
2267
+ payHash = hodlInv .preimage .Hash ()
2268
+ _ , err = fabia .InvoicesClient .CancelInvoice (
2269
+ ctx , & invoicesrpc.CancelInvoiceMsg {
2270
+ PaymentHash : payHash [:],
2271
+ },
2272
+ )
2273
+ require .NoError (t .t , err )
2274
+
2275
+ // Let's assert that Erin cancelled all his HTLCs.
2276
+ assertNumHtlcs (t .t , erin , 0 )
2277
+
2278
+ logBalance (t .t , nodes , assetID , "after hodl cancel & 0 present HTLCs" )
2279
+
2280
+ // Now let's create a smaller invoice and pay it, to validate that the
2281
+ // channel is still healthy.
2282
+ invoiceResp = createAssetInvoice (
2283
+ t .t , erin , fabia , 50_000 , assetID ,
2284
+ )
2285
+
2286
+ payInvoiceWithAssets (
2287
+ t .t , charlie , dave , invoiceResp .PaymentRequest , assetID ,
2288
+ )
2289
+
2290
+ logBalance (t .t , nodes , assetID , "after safe asset htlc failure" )
2240
2291
}
2241
2292
2242
2293
// testCustomChannelsLiquidityEdgeCases is a test that runs through some
0 commit comments