Skip to content

Commit 557b337

Browse files
committed
itest: add test for failing send after queryroutes
1 parent 9b3b309 commit 557b337

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ var allTestCases = []*lntest.TestCase{
354354
Name: "route fee cutoff",
355355
TestFunc: testRouteFeeCutoff,
356356
},
357+
{
358+
Name: "route fee limit after queryroutes",
359+
TestFunc: testFeeLimitAfterQueryRoutes,
360+
},
357361
{
358362
Name: "rpc middleware interceptor",
359363
TestFunc: testRPCMiddlewareInterceptor,

itest/lnd_routing_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,84 @@ func testRouteFeeCutoff(ht *lntest.HarnessTest) {
13311331
ht.CloseChannel(carol, chanPointCarolDave)
13321332
}
13331333

1334+
// testFeeLimitAfterQueryRoutes tests that a payment's fee limit is consistent
1335+
// with the fee of a queried route.
1336+
func testFeeLimitAfterQueryRoutes(ht *lntest.HarnessTest) {
1337+
// Create a three hop network: Alice -> Bob -> Carol.
1338+
chanAmt := btcutil.Amount(100000)
1339+
chanPoints, nodes := createSimpleNetwork(
1340+
ht, []string{}, 3, lntest.OpenChannelParams{Amt: chanAmt},
1341+
)
1342+
alice, bob, carol := nodes[0], nodes[1], nodes[2]
1343+
chanPointAliceBob, chanPointBobCarol := chanPoints[0], chanPoints[1]
1344+
1345+
// We set an inbound fee discount on Bob's channel to Alice to
1346+
// effectively set the outbound fees charged to Carol to zero.
1347+
expectedPolicy := &lnrpc.RoutingPolicy{
1348+
FeeBaseMsat: 1000,
1349+
FeeRateMilliMsat: 1,
1350+
InboundFeeBaseMsat: -1000,
1351+
InboundFeeRateMilliMsat: -1,
1352+
TimeLockDelta: uint32(
1353+
chainreg.DefaultBitcoinTimeLockDelta,
1354+
),
1355+
MinHtlc: 1000,
1356+
MaxHtlcMsat: lntest.CalculateMaxHtlc(chanAmt),
1357+
}
1358+
1359+
updateFeeReq := &lnrpc.PolicyUpdateRequest{
1360+
Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{
1361+
ChanPoint: chanPointAliceBob,
1362+
},
1363+
BaseFeeMsat: expectedPolicy.FeeBaseMsat,
1364+
FeeRatePpm: uint32(expectedPolicy.FeeRateMilliMsat),
1365+
TimeLockDelta: expectedPolicy.TimeLockDelta,
1366+
MaxHtlcMsat: expectedPolicy.MaxHtlcMsat,
1367+
InboundFee: &lnrpc.InboundFee{
1368+
BaseFeeMsat: expectedPolicy.InboundFeeBaseMsat,
1369+
FeeRatePpm: expectedPolicy.InboundFeeRateMilliMsat,
1370+
},
1371+
}
1372+
bob.RPC.UpdateChannelPolicy(updateFeeReq)
1373+
1374+
// Wait for Alice to receive the channel update from Bob.
1375+
ht.AssertChannelPolicyUpdate(
1376+
alice, bob, expectedPolicy, chanPointAliceBob, false,
1377+
)
1378+
1379+
// We query the only route available to Carol.
1380+
queryRoutesReq := &lnrpc.QueryRoutesRequest{
1381+
PubKey: carol.PubKeyStr,
1382+
Amt: paymentAmt,
1383+
}
1384+
routesResp := alice.RPC.QueryRoutes(queryRoutesReq)
1385+
1386+
// Verify that the route has zero fees.
1387+
require.Len(ht, routesResp.Routes, 1)
1388+
require.Len(ht, routesResp.Routes[0].Hops, 2)
1389+
require.Zero(ht, routesResp.Routes[0].TotalFeesMsat)
1390+
1391+
// Attempt a payment with a fee limit of zero.
1392+
invoice := &lnrpc.Invoice{Value: paymentAmt}
1393+
invoiceResp := carol.RPC.AddInvoice(invoice)
1394+
sendReq := &routerrpc.SendPaymentRequest{
1395+
PaymentRequest: invoiceResp.PaymentRequest,
1396+
TimeoutSeconds: 60,
1397+
FeeLimitMsat: 0,
1398+
}
1399+
1400+
// We assert that the payment fails because the fee limit doesn't work
1401+
// correctly. This is fixed in the next commit.
1402+
ht.SendPaymentAssertFail(
1403+
alice, sendReq,
1404+
lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE,
1405+
)
1406+
1407+
// Once we're done, close the channels.
1408+
ht.CloseChannel(alice, chanPointAliceBob)
1409+
ht.CloseChannel(bob, chanPointBobCarol)
1410+
}
1411+
13341412
// computeFee calculates the payment fee as specified in BOLT07.
13351413
func computeFee(baseFee, feeRate, amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
13361414
return baseFee + amt*feeRate/1000000

lntest/node/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (nw *nodeWatcher) WaitForChannelPolicyUpdate(
221221
select {
222222
// Send a watch request every second.
223223
case <-ticker.C:
224-
// Did the event can close in the meantime? We want to
224+
// Did the event chan close in the meantime? We want to
225225
// avoid a "close of closed channel" panic since we're
226226
// re-using the same event chan for multiple requests.
227227
select {

0 commit comments

Comments
 (0)