-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
routing: fix fee limit condition #8941
routing: fix fee limit condition #8941
Conversation
Important Review skippedAuto reviews are limited to specific labels. Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix! Just a few nits, otherwise LGTM.
remove itest, add more lightweight test?
We do test inbound fees in testMultiHopPayments
, but the FeeLimitMsat
behavior was never tested there. We then have testRouteFeeCutoff
which I think it's a bit difficult to add this test as it complicates things. So I'd prefer we keep the newly added test as it's straightforward.
A unit test can also be helpful, tho I'd say it's better to refactor the extremely long method findPath
first.
Given this is a fairly small change and a bug fix, I think we can still make it into 0.18.3? cc @saubyk
itest/lnd_routing_test.go
Outdated
func testFeeLimitAfterQueryRoutes(ht *lntest.HarnessTest) { | ||
// For this test, we'll create the following topology: | ||
// | ||
// Alice ---- Bob ---- Carol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there's this newer method you can use to quickly setup a topology,
// Create a three hop network: Alice -> Bob -> Carol.
chanPoints, nodes := createSimpleNetwork(ht, cfg, 3, openChannelParams)
@@ -722,6 +722,13 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, | |||
amountToSend := toNodeDist.netAmountReceived + | |||
lnwire.MilliSatoshi(inboundFee) | |||
|
|||
// Check if accumulated fees would exceed fee limit when this | |||
// node would be added to the path. | |||
totalFee := int64(amountToSend) - int64(amt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this log helpful when checking the behavior from the itest,
log.Tracef("Checking toNode(%v) with minInboundFee=%v, inboundFee=%v, amountToSend=%v, amt=%v, totalFee=%v", toNodeDist.node, minInboundFee, inboundFee, amountToSend, amt, totalFee)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the trace log, would be helpful when debugging inbound fees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the trace log to be visible in both itest cases (without and with the fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the super quick fix, LGTM, peding @yyforyongyu's comments 🎉
@@ -722,6 +722,13 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, | |||
amountToSend := toNodeDist.netAmountReceived + | |||
lnwire.MilliSatoshi(inboundFee) | |||
|
|||
// Check if accumulated fees would exceed fee limit when this | |||
// node would be added to the path. | |||
totalFee := int64(amountToSend) - int64(amt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the trace log, would be helpful when debugging inbound fees.
if totalFee > 0 && lnwire.MilliSatoshi(totalFee) > r.FeeLimit { | ||
return | ||
} | ||
|
||
// Request the success probability for this edge. | ||
edgeProbability := r.ProbabilitySource( | ||
fromVertex, toNodeDist.node, amountToSend, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also correct weight := edgeWeight(netAmountToReceive, fee, timeLockDelta)
to weight := edgeWeight(amountToSend, fee, timeLockDelta)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case it should be weight := edgeWeight(amountToSend, outboundFee, timeLockDelta)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fee is just passed in there to be converted to int64
, but isn't really related to the time lock weight, which is a bit strange and can be addressed in a refactor, so I think weight := edgeWeight(amountToSend, fee, timeLockDelta)
is correct (and otherwise we wouldn't take inbound fees into account in the weight if fee
would be changed to outboundFee
).
d53a038
to
b737bca
Compare
Thanks for the quick reviews! I added some logging and a fix for the time lock weight. Strange this doesn't compile with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rebase to use the new log closure, otherwise LGTM.
routing/pathfind.go
Outdated
// node would be added to the path. | ||
totalFee := int64(amountToSend) - int64(amt) | ||
|
||
log.Trace(newLogClosure(func() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now lnutils.NewLogClosure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was very strange, I could build the same commit on two different machines, maybe a github caching thing
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.
The time lock weight for a hop is supposed to be proportional to the amount that is sent/locked, but in a previous change we switched to the net amount, where inbound fees aren't yet applied. This is corrected in this commit.
b737bca
to
0358b3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM🎉
Change Description
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. With this PR, we perform the fee limit check on the amount to send, which includes both inbound and outbound fees, to fix #8940.
Todo: