Skip to content
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

Closed

Conversation

Crypt-iQ
Copy link
Collaborator

@Crypt-iQ Crypt-iQ commented Jun 3, 2019

Fixes #3055

Fixed some integration tests + unit tests. Pretty self-explanatory. Wasn't sure if I should have added an integration test?

@halseth halseth requested a review from joostjager June 11, 2019 13:45
@@ -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
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do this week

Copy link
Collaborator Author

@Crypt-iQ Crypt-iQ Jul 11, 2019

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/payment_session.go Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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

lntest/itest/lnd_test.go Show resolved Hide resolved
routing/payment_session_test.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef requested review from wpaulino and halseth and removed request for wpaulino July 9, 2019 23:26
@Crypt-iQ Crypt-iQ requested a review from Roasbeef as a code owner July 11, 2019 18:26
// 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 {
Copy link
Member

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.

Copy link
Collaborator Author

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)

Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

@Roasbeef
Copy link
Member

Roasbeef commented Jul 17, 2019 via email

@Crypt-iQ Crypt-iQ force-pushed the inflight_block_fix_0531 branch 3 times, most recently from 5b5dd0c to 1cce9d9 Compare July 19, 2019 17:07
routing/pathfind_test.go Outdated Show resolved Hide resolved
routing/pathfind_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a squash :)

@@ -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.
Copy link
Contributor

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

@@ -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.
Copy link
Contributor

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.
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@halseth
Copy link
Contributor

halseth commented Jul 24, 2019

@Crypt-iQ Decided to make the changes only apply to SendPayment for now, and then we can move the queryroutes/sendToRoute discussion to a new PR.

@Crypt-iQ
Copy link
Collaborator Author

Crypt-iQ commented Jul 24, 2019

@Crypt-iQ Decided to make the changes only apply to SendPayment for now, and then we can move the queryroutes/sendToRoute discussion to a new PR.

See #3339

@cfromknecht cfromknecht removed this from the 0.7.1 milestone Jul 24, 2019
@cfromknecht cfromknecht added this to the 0.8.0 milestone Jul 24, 2019
@wpaulino wpaulino modified the milestones: 0.8.0, 0.8.1 Sep 17, 2019
@wpaulino wpaulino added v0.8.1 and removed v0.8.0 labels Sep 17, 2019
@wpaulino
Copy link
Contributor

Needs a rebase!

@wpaulino wpaulino removed the v0.8.1 label Oct 8, 2019
@joostjager joostjager modified the milestones: 0.8.1, 0.9 Oct 8, 2019
@joostjager
Copy link
Collaborator

Closing until we have good reasons to also add implicit padding for the low-level calls SendToRoute and QueryRoutes.

@joostjager joostjager closed this Oct 14, 2019
@joostjager joostjager removed this from the 0.9 milestone Oct 14, 2019
@joostjager joostjager removed the v0.9.0 label Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix P2 should be fixed if one has time routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

routing: payment fails if block mined while htlc is in flight
6 participants