|
| 1 | +package itest |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/lightningnetwork/lnd/lnrpc" |
| 5 | + "github.com/lightningnetwork/lnd/lnrpc/routerrpc" |
| 6 | + "github.com/lightningnetwork/lnd/lntest" |
| 7 | +) |
| 8 | + |
| 9 | +// testMaxHtlcPathPayment tests that when a payment is attempted, the path |
| 10 | +// finding logic correctly takes into account the max_htlc value of the first |
| 11 | +// channel. |
| 12 | +func testMaxHtlcPathPayment(ht *lntest.HarnessTest) { |
| 13 | + // Create a channel Alice->Bob. |
| 14 | + chanPoints, nodes := ht.CreateSimpleNetwork( |
| 15 | + [][]string{nil, nil}, lntest.OpenChannelParams{ |
| 16 | + Amt: 1000000, |
| 17 | + }, |
| 18 | + ) |
| 19 | + alice, bob := nodes[0], nodes[1] |
| 20 | + chanPoint := chanPoints[0] |
| 21 | + |
| 22 | + // Alice and Bob should have one channel open with each other now. |
| 23 | + ht.AssertNodeNumChannels(alice, 1) |
| 24 | + ht.AssertNodeNumChannels(bob, 1) |
| 25 | + |
| 26 | + // Define a max_htlc value that is lower than the default. |
| 27 | + const ( |
| 28 | + maxHtlcMsat = 50000000 |
| 29 | + minHtlcMsat = 1000 |
| 30 | + timeLockDelta = 80 |
| 31 | + baseFeeMsat = 0 |
| 32 | + feeRate = 0 |
| 33 | + ) |
| 34 | + |
| 35 | + // Update Alice's channel policy to set the new max_htlc value. |
| 36 | + req := &lnrpc.PolicyUpdateRequest{ |
| 37 | + Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{ |
| 38 | + ChanPoint: chanPoint, |
| 39 | + }, |
| 40 | + MaxHtlcMsat: maxHtlcMsat, |
| 41 | + MinHtlcMsat: minHtlcMsat, |
| 42 | + BaseFeeMsat: baseFeeMsat, |
| 43 | + FeeRate: feeRate, |
| 44 | + TimeLockDelta: timeLockDelta, |
| 45 | + } |
| 46 | + alice.RPC.UpdateChannelPolicy(req) |
| 47 | + |
| 48 | + expectedPolicy := &lnrpc.RoutingPolicy{ |
| 49 | + FeeBaseMsat: baseFeeMsat, |
| 50 | + FeeRateMilliMsat: feeRate, |
| 51 | + TimeLockDelta: timeLockDelta, |
| 52 | + MinHtlc: minHtlcMsat, |
| 53 | + MaxHtlcMsat: maxHtlcMsat, |
| 54 | + } |
| 55 | + |
| 56 | + // Wait for the policy update to propagate to Bob. |
| 57 | + ht.AssertChannelPolicyUpdate( |
| 58 | + bob, alice, expectedPolicy, chanPoint, false, |
| 59 | + ) |
| 60 | + |
| 61 | + // Create an invoice for an amount greater than the max htlc value. |
| 62 | + invoiceAmt := int64(maxHtlcMsat + 10_000_000) |
| 63 | + invoice := &lnrpc.Invoice{ValueMsat: invoiceAmt} |
| 64 | + resp := bob.RPC.AddInvoice(invoice) |
| 65 | + |
| 66 | + // Attempt to pay the invoice from Alice. The payment should be |
| 67 | + // splitted into two parts, one for the max_htlc value and one for the |
| 68 | + // remaining amount and succeed. |
| 69 | + payReq := &routerrpc.SendPaymentRequest{ |
| 70 | + PaymentRequest: resp.PaymentRequest, |
| 71 | + FeeLimitMsat: noFeeLimitMsat, |
| 72 | + } |
| 73 | + ht.SendPaymentAssertSettled(alice, payReq) |
| 74 | +} |
0 commit comments