Skip to content

Commit e54206f

Browse files
authored
Merge pull request #9990 from ziggie1984/follow-up-payment-addr-spec-update
itest coverage increase following the spec update regarding MPP payments
2 parents 01dfee6 + d6b89b9 commit e54206f

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ circuit. The indices are only available for forwarding events saved after v0.20.
9999

100100
## Code Health
101101

102+
- [Increase itest coverage](https://github.com/lightningnetwork/lnd/pull/9990)
103+
for payments. Now the payment address is mandatory for the writer and
104+
reader of a payment request.
105+
102106
## Breaking Changes
103107
## Performance Improvements
104108

@@ -159,3 +163,4 @@ circuit. The indices are only available for forwarding events saved after v0.20.
159163
* Funyug
160164
* Mohamed Awnallah
161165
* Pins
166+
* Ziggie

invoices/invoiceregistry.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,11 @@ func (i *InvoiceRegistry) notifyExitHopHtlcLocked(
10381038
)
10391039
switch {
10401040
case errors.Is(err, ErrInvoiceNotFound) ||
1041-
errors.Is(err, ErrNoInvoicesCreated):
1041+
errors.Is(err, ErrNoInvoicesCreated) ||
1042+
errors.Is(err, ErrInvRefEquivocation):
1043+
1044+
log.Debugf("Invoice not found with error: %v, failing htlc",
1045+
err)
10421046

10431047
// If the invoice was not found, return a failure resolution
10441048
// with an invoice not found result.

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ var allTestCases = []*lntest.TestCase{
683683
Name: "invoice migration",
684684
TestFunc: testInvoiceMigration,
685685
},
686+
{
687+
Name: "payment address mismatch",
688+
TestFunc: testWrongPaymentAddr,
689+
},
686690
{
687691
Name: "fee replacement",
688692
TestFunc: testFeeReplacement,

itest/lnd_payment_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,3 +1396,64 @@ func testSendPaymentKeysendMPPFail(ht *lntest.HarnessTest) {
13961396
_, err = ht.ReceivePaymentUpdate(client)
13971397
require.Error(ht, err)
13981398
}
1399+
1400+
// testWrongPaymentAddr is a test that checks that a payment using a wrong
1401+
// payment address will fail.
1402+
func testWrongPaymentAddr(ht *lntest.HarnessTest) {
1403+
// Set the feerate to be 10 sat/vb.
1404+
ht.SetFeeEstimate(2500)
1405+
1406+
// Open a channel with 100k satoshis between Alice and Bob with Alice
1407+
// being the sole funder of the channel.
1408+
chanAmt := btcutil.Amount(100_000)
1409+
openChannelParams := lntest.OpenChannelParams{
1410+
Amt: chanAmt,
1411+
}
1412+
cfgs := [][]string{nil, nil}
1413+
1414+
invoiceAmt := int64(1000)
1415+
1416+
// Create a two hop network: Alice -> Bob.
1417+
_, nodes := ht.CreateSimpleNetwork(cfgs, openChannelParams)
1418+
1419+
alice, bob := nodes[0], nodes[1]
1420+
1421+
request1 := bob.RPC.AddInvoice(&lnrpc.Invoice{
1422+
ValueMsat: invoiceAmt,
1423+
CltvExpiry: finalCltvDelta,
1424+
})
1425+
1426+
request2 := bob.RPC.AddInvoice(&lnrpc.Invoice{
1427+
ValueMsat: invoiceAmt,
1428+
CltvExpiry: finalCltvDelta,
1429+
})
1430+
payReq2 := alice.RPC.DecodePayReq(request2.PaymentRequest)
1431+
1432+
ht.AssertNumInvoices(bob, 2)
1433+
1434+
// Now we don't want to use the payment request to send the payment
1435+
// because we want to use the payment_addr two for the payment of the
1436+
// invoice 1 to simulate the case where the payment address is wrong.
1437+
route := alice.RPC.BuildRoute(
1438+
&routerrpc.BuildRouteRequest{
1439+
PaymentAddr: payReq2.PaymentAddr,
1440+
AmtMsat: invoiceAmt,
1441+
FinalCltvDelta: finalCltvDelta,
1442+
HopPubkeys: [][]byte{bob.PubKey[:]},
1443+
},
1444+
)
1445+
1446+
// Send the payment and expect it to fail the payment.
1447+
htlcAttempt := alice.RPC.SendToRouteV2(
1448+
&routerrpc.SendToRouteRequest{
1449+
Route: route.Route,
1450+
PaymentHash: request1.RHash,
1451+
},
1452+
)
1453+
require.Equal(ht, lnrpc.HTLCAttempt_FAILED, htlcAttempt.Status)
1454+
1455+
// Make sure the payment is marked as failed also in the database.
1456+
ht.AssertPaymentStatus(
1457+
alice, lntypes.Hash(request1.RHash), lnrpc.Payment_FAILED,
1458+
)
1459+
}

0 commit comments

Comments
 (0)