Skip to content

Commit b0f0715

Browse files
committed
routing: fix fee limit condition
When iterating edges, pathfinding checks early whether using an edge would violate the requested total fee limit for a route. This check is done on the net amount (an amount the inbound fee is calculated with). However, a possible next hop's fee discount leads to a reduction in fees and as such using the net amount leads to assuming a higher cumulative fee than the route really has, excluding the path erroneously. We perform the fee limit check on the amount to send, which includes both inbound and outbound fees. This should be possible as the first hop's outbound fee is zero and therefore doesn't have to be checked in the end.
1 parent 557b337 commit b0f0715

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

docs/release-notes/release-notes-0.18.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8896) that caused
3737
LND to use a default fee rate for the batch channel opening flow.
3838

39+
* The fee limit for payments [was made
40+
compatible](https://github.com/lightningnetwork/lnd/pull/8941) with inbound
41+
fees.
42+
3943
# New Features
4044
## Functional Enhancements
4145
## RPC Additions
@@ -150,6 +154,7 @@
150154
# Contributors (Alphabetical Order)
151155

152156
* Andras Banki-Horvath
157+
* bitromortac
153158
* Bufo
154159
* Elle Mouton
155160
* Matheus Degiovani

itest/lnd_routing_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,8 @@ func testFeeLimitAfterQueryRoutes(ht *lntest.HarnessTest) {
13971397
FeeLimitMsat: 0,
13981398
}
13991399

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-
)
1400+
// We assert that a route compatible with the fee limit is available.
1401+
ht.SendPaymentAssertSettled(alice, sendReq)
14061402

14071403
// Once we're done, close the channels.
14081404
ht.CloseChannel(alice, chanPointAliceBob)

routing/pathfind.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,24 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
723723
amountToSend := toNodeDist.netAmountReceived +
724724
lnwire.MilliSatoshi(inboundFee)
725725

726+
// Check if accumulated fees would exceed fee limit when this
727+
// node would be added to the path.
728+
totalFee := int64(amountToSend) - int64(amt)
729+
730+
log.Trace(lnutils.NewLogClosure(func() string {
731+
return fmt.Sprintf(
732+
"Checking fromVertex (%v) with "+
733+
"minInboundFee=%v, inboundFee=%v, "+
734+
"amountToSend=%v, amt=%v, totalFee=%v",
735+
fromVertex, minInboundFee, inboundFee,
736+
amountToSend, amt, totalFee,
737+
)
738+
}))
739+
740+
if totalFee > 0 && lnwire.MilliSatoshi(totalFee) > r.FeeLimit {
741+
return
742+
}
743+
726744
// Request the success probability for this edge.
727745
edgeProbability := r.ProbabilitySource(
728746
fromVertex, toNodeDist.node, amountToSend,
@@ -779,24 +797,6 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
779797
netAmountToReceive := amountToSend +
780798
lnwire.MilliSatoshi(outboundFee)
781799

782-
// Check if accumulated fees would exceed fee limit when this
783-
// node would be added to the path.
784-
totalFee := int64(netAmountToReceive) - int64(amt)
785-
786-
log.Trace(lnutils.NewLogClosure(func() string {
787-
return fmt.Sprintf(
788-
"Checking fromVertex (%v) with "+
789-
"minInboundFee=%v, inboundFee=%v, "+
790-
"amountToSend=%v, amt=%v, totalFee=%v",
791-
fromVertex, minInboundFee, inboundFee,
792-
amountToSend, amt, totalFee,
793-
)
794-
}))
795-
796-
if totalFee > 0 && lnwire.MilliSatoshi(totalFee) > r.FeeLimit {
797-
return
798-
}
799-
800800
// Calculate total probability of successfully reaching target
801801
// by multiplying the probabilities. Both this edge and the rest
802802
// of the route must succeed.

0 commit comments

Comments
 (0)