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: add block padding to prevent inflight HTLC failures #3153
routing: add block padding to prevent inflight HTLC failures #3153
Conversation
routing/router.go
Outdated
@@ -1402,6 +1402,10 @@ func (r *ChannelRouter) FindRoute(source, target route.Vertex, | |||
finalCLTVDelta = finalExpiry[0] | |||
} | |||
|
|||
// Add BlockPadding to the finalCltvDelta so that the receiving node | |||
// does not reject the HTLC if a block is mined while its in-flight. | |||
finalCLTVDelta += BlockPadding |
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 am in doubt whether we should also pad when the user specified an explicit final cltv expiry for queryroutes
. It is a more low level function and it may be confusing if it doesn't returns what was requested?
Maybe the same thing holds for sendpayment
with a set expiry? Perhaps the padding should just happen when only an encoded payment request is supplied.
Will get back to you.
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.
@Crypt-iQ it seems best to only apply the padding if no explicit final cltv delta is set in the rpc request.
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.
looks like this still needs to be moved
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.
Will do this week
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.
Addressed the comments. This is related to #3150 since if there is no expiry set, the payment request will likely fail because of receiver-side checks (if the node is an lnd node and use a default expiry which is set to 40). The result of that discussion was to require the final cltv delta. Thoughts?
routing/router.go
Outdated
@@ -1402,6 +1402,10 @@ func (r *ChannelRouter) FindRoute(source, target route.Vertex, | |||
finalCLTVDelta = finalExpiry[0] | |||
} | |||
|
|||
// Add BlockPadding to the finalCltvDelta so that the receiving node | |||
// does not reject the HTLC if a block is mined while its in-flight. | |||
finalCLTVDelta += BlockPadding |
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.
looks like this still needs to be moved
061cd5d
to
1522457
Compare
routing/payment_session.go
Outdated
// Add BlockPadding to the finalCltvDelta so that the receiving node | ||
// does not reject the HTLC if a block is mined while its in-flight. | ||
// This is only added if no finalCltvDelta was set. | ||
if finalCltvDelta == 0 { |
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.
If we only add block padding in this case, then it doesn't address the common case where a users payment fails due to a block being mined right as they send. We always set our finalCltvDelta
if the payment goes through SendPayment
.
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.
Ahhhh! I missed that. Joost had a comment above where he said the block padding should only be specified iff no finalCltvDelta
was supplied. But it seems that has some problems as well.
see: #3153 (comment)
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.
From my reading, his comment only applied to queryroutes
. IMO, we should also apply the padding there, as users are known to execute commands that resemble: queryroutes | sendtoroute
.
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.
Yeah that's true, should it be set any time a route is requested then or perhaps this could be the default with an option to turn the padding off?
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.
Another way to see this is, is from the perspective of keeping the api surface as small as possible. QueryRoutes
(the rpc) is for advanced api users and you could also say that they should just supply just an absolute block height. This should include the final cltv expiry of the invoice and block padding. It would give more control over the time locks of the route returned, which may be required if there is chaining involved with time locks of other payments.
QueryRoutes
(the rpc) is different from queryroutes
(the cli command). We could choose to have lncli
do some of the calculation to still be able to queryroutes | sendtoroute
.
SGTM
…On Tue, Jul 16, 2019, 5:08 PM Eugene ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In routing/payment_session.go
<#3153 (comment)>:
> @@ -154,6 +158,13 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
return nil, fmt.Errorf("pre-built route already tried")
}
+ // Add BlockPadding to the finalCltvDelta so that the receiving node
+ // does not reject the HTLC if a block is mined while its in-flight.
+ // This is only added if no finalCltvDelta was set.
+ if finalCltvDelta == 0 {
Yeah that's true, should it be set any time a route is requested then or
perhaps this could be the default with an option to turn the padding off?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3153?email_source=notifications&email_token=AAHTWLQGVGPESX4D6VKWYNDP7ZPGJA5CNFSM4HSR3NZ2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB6UTSTI#discussion_r304174865>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHTWLV4STKS442375XZIFLP7ZPGJANCNFSM4HSR3NZQ>
.
|
5b5dd0c
to
1cce9d9
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.
Needs a squash :)
routing/payment_session.go
Outdated
@@ -8,6 +8,10 @@ import ( | |||
"github.com/lightningnetwork/lnd/routing/route" | |||
) | |||
|
|||
// BlockPadding is used to increment the finalCltvDelta value for the last hop | |||
// to prevent an HTLC being failed if a block is mined while it's in-flight. |
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.
s/a block/some blocks
routing/payment_session.go
Outdated
@@ -65,6 +69,10 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment, | |||
return nil, fmt.Errorf("pre-built route already tried") | |||
} | |||
|
|||
// Add BlockPadding to the finalCltvDelta so that the receiving node | |||
// does not reject the HTLC if a block is mined while its in-flight. |
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.
s/if a block/in case some blocks
This commit adds the BlockPadding value (currently 3) to newRoute calls so that if some blocks are mined while the htlc is in-flight, the exit hop won't reject it.
This commit adds a no_padding option to queryroutes lncli and rpc calls. This allows a caller to force lnd to omit any block padding that would otherwise be added as a safety measure.
1cce9d9
to
76a2790
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 ✅
@Crypt-iQ Decided to make the changes only apply to |
Needs a rebase! |
Closing until we have good reasons to also add implicit padding for the low-level calls |
Fixes #3055
Fixed some integration tests + unit tests. Pretty self-explanatory. Wasn't sure if I should have added an integration test?