Skip to content

Commit 24d92f3

Browse files
authored
Merge pull request #1106 from GeorgeTsagk/custom-chans-existing-routehints
Custom channels liquidity edge case: AddInvoice with existing route hints
2 parents 712847f + bf4d46b commit 24d92f3

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

itest/assets_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,13 +1423,15 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
14231423
return
14241424
}
14251425

1426-
result, _, err := getAssetPaymentResult(t, stream, false)
1426+
tapPayment, err := getAssetPaymentResult(t, stream, false)
14271427
require.NoError(t, err)
1428-
if result.Status == lnrpc.Payment_FAILED {
1429-
t.Logf("Failure reason: %v", result.FailureReason)
1428+
1429+
payment := tapPayment.lndPayment
1430+
if payment.Status == lnrpc.Payment_FAILED {
1431+
t.Logf("Failure reason: %v", payment.FailureReason)
14301432
}
1431-
require.Equal(t, cfg.payStatus, result.Status)
1432-
require.Equal(t, cfg.failureReason, result.FailureReason)
1433+
require.Equal(t, cfg.payStatus, payment.Status)
1434+
require.Equal(t, cfg.failureReason, payment.FailureReason)
14331435
}
14341436

14351437
func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
@@ -1755,12 +1757,13 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
17551757
sendReq.MaxShardSizeMsat = 80_000_000
17561758
}
17571759

1758-
var rfqBytes, peerPubKey []byte
1760+
var rfqBytes []byte
17591761
cfg.rfq.WhenSome(func(i rfqmsg.ID) {
17601762
rfqBytes = make([]byte, len(i[:]))
17611763
copy(rfqBytes, i[:])
17621764
})
17631765

1766+
var peerPubKey []byte
17641767
if rfqPeer != nil {
17651768
peerPubKey = rfqPeer.PubKey[:]
17661769
}
@@ -1785,7 +1788,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
17851788

17861789
// If an error is returned by the RPC method (meaning the stream itself
17871790
// was established, no network or auth error), we expect the error to be
1788-
// returned on the first read on the stream.
1791+
// returned on the stream.
17891792
if cfg.errSubStr != "" {
17901793
msg, err := stream.Recv()
17911794

@@ -1804,14 +1807,18 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
18041807
rateVal rfqmath.FixedPoint[rfqmath.BigInt]
18051808
)
18061809

1807-
result, rateVal, err := getAssetPaymentResult(
1810+
tapPayment, err := getAssetPaymentResult(
18081811
t, stream, cfg.payStatus == lnrpc.Payment_IN_FLIGHT,
18091812
)
18101813
require.NoError(t, err)
1811-
require.Equal(t, cfg.payStatus, result.Status)
1812-
require.Equal(t, cfg.failureReason, result.FailureReason)
1814+
1815+
payment := tapPayment.lndPayment
1816+
require.Equal(t, cfg.payStatus, payment.Status)
1817+
require.Equal(t, cfg.failureReason, payment.FailureReason)
18131818

18141819
amountMsat := lnwire.MilliSatoshi(decodedInvoice.NumMsat)
1820+
1821+
rateVal = tapPayment.assetRate
18151822
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, rateVal)
18161823
numUnits = milliSatsFP.ScaleTo(0).ToUint64()
18171824

itest/litd_accounts_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,21 @@ func getPaymentResult(stream routerrpc.Router_SendPaymentV2Client,
445445
}
446446
}
447447

448+
// TapPayment encapsulates all the information related to the outcome of a tap
449+
// asset payment. It contains the outcome of the LND payment and also the asset
450+
// rate that was used to swap the assets to satoshis.
451+
type TapPayment struct {
452+
// lndPayment contains the lnd part of the payment result.
453+
lndPayment *lnrpc.Payment
454+
455+
// assetRate contains the asset rate that was used to convert the assets
456+
// to sats.
457+
assetRate rfqmath.FixedPoint[rfqmath.BigInt]
458+
}
459+
448460
func getAssetPaymentResult(t *testing.T,
449461
s tapchannelrpc.TaprootAssetChannels_SendPaymentClient,
450-
isHodl bool) (*lnrpc.Payment, rfqmath.FixedPoint[rfqmath.BigInt],
451-
error) {
462+
isHodl bool) (*TapPayment, error) {
452463

453464
// No idea why it makes a difference whether we wait before calling
454465
// s.Recv() or not, but it does. Without the sleep, the test will fail
@@ -461,7 +472,7 @@ func getAssetPaymentResult(t *testing.T,
461472
for {
462473
msg, err := s.Recv()
463474
if err != nil {
464-
return nil, rateVal, err
475+
return nil, err
465476
}
466477

467478
// Ignore RFQ quote acceptance messages read from the send
@@ -501,19 +512,24 @@ func getAssetPaymentResult(t *testing.T,
501512

502513
payment := msg.GetPaymentResult()
503514
if payment == nil {
504-
return nil, rateVal,
505-
fmt.Errorf("unexpected message: %v", msg)
515+
err := fmt.Errorf("unexpected message: %v", msg)
516+
return nil, err
517+
}
518+
519+
result := &TapPayment{
520+
lndPayment: payment,
521+
assetRate: rateVal,
506522
}
507523

508524
// If this is a hodl payment, then we'll return the first
509525
// expected response. Otherwise, we'll wait until the in flight
510526
// clears to we can observe the other payment states.
511527
switch {
512528
case isHodl:
513-
return payment, rateVal, nil
529+
return result, nil
514530

515531
case payment.Status != lnrpc.Payment_IN_FLIGHT:
516-
return payment, rateVal, nil
532+
return result, nil
517533
}
518534
}
519535
}

itest/litd_custom_channels_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,42 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
29592959
payInvoiceWithSatoshi(
29602960
t.t, dave, invoiceResp, withFeeLimit(100_000_000),
29612961
)
2962+
2963+
logBalance(t.t, nodes, assetID, "after policy checks")
2964+
2965+
resBuy, err := daveTap.RfqClient.AddAssetBuyOrder(
2966+
ctx, &rfqrpc.AddAssetBuyOrderRequest{
2967+
AssetSpecifier: &assetSpecifier,
2968+
AssetMaxAmt: 1_000,
2969+
Expiry: uint64(inOneHour.Unix()),
2970+
PeerPubKey: charlie.PubKey[:],
2971+
TimeoutSeconds: 100,
2972+
},
2973+
)
2974+
require.NoError(t.t, err)
2975+
2976+
scid := resBuy.GetAcceptedQuote().Scid
2977+
2978+
invResp := createAssetInvoice(
2979+
t.t, charlie, dave, 1_000, assetID,
2980+
withInvGroupKey(groupID), withRouteHints([]*lnrpc.RouteHint{
2981+
{
2982+
HopHints: []*lnrpc.HopHint{
2983+
{
2984+
NodeId: charlie.PubKeyStr,
2985+
ChanId: scid,
2986+
},
2987+
},
2988+
},
2989+
}),
2990+
)
2991+
2992+
payInvoiceWithAssets(
2993+
t.t, charlie, dave, invResp.PaymentRequest, assetID,
2994+
withGroupKey(groupID),
2995+
)
2996+
2997+
logBalance(t.t, nodes, assetID, "after invoice with route hints")
29622998
}
29632999

29643000
// testCustomChannelsLiquidityEdgeCases is a test that runs through some

0 commit comments

Comments
 (0)