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: allow route to self #3736

Merged
merged 5 commits into from
Nov 26, 2019

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Nov 18, 2019

This PR makes it possible to find routes to yourself. It is useful for rebalancing purposes if combined with #3739 and an outgoing channel restriction.

Usage from the command line:

  1. lncli addinvoice <amt>
  2. lncli payinvoice --allow_self_payment --outgoing_chan_id <outgoing_chan> --last_hop <last_hop> <payreq_from_1>

This will push out amt through outgoing_chan back to yourself via one of your channels with your peer last_hop. The exact incoming channel cannot be specified because routing nodes forward non-strict.

Note that if you pay to yourself without any of these restrictions, it may happen that the payment comes back in through the same channel that was used to send it out. In that case balances don't change. They may only go down because of the routing fees paid.

Fixes #1645

@joostjager joostjager force-pushed the route-to-self branch 2 times, most recently from f128194 to bfc27d6 Compare November 18, 2019 09:20
@joostjager joostjager changed the title route to self routing: allow route to self Nov 18, 2019
@joostjager joostjager force-pushed the route-to-self branch 3 times, most recently from e651429 to 86027ba Compare November 18, 2019 09:57
@joostjager joostjager marked this pull request as ready for review November 18, 2019 12:00
@joostjager joostjager requested a review from Roasbeef as a code owner November 18, 2019 12:00
@joostjager joostjager added channel management The management of the nodes channels enhancement Improvements to existing features / behaviour payments Related to invoices/payments routing labels Nov 19, 2019
@joostjager joostjager removed the request for review from Roasbeef November 19, 2019 07:55
@joostjager joostjager self-assigned this Nov 19, 2019
@joostjager joostjager added this to the 0.9.0 milestone Nov 19, 2019
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Clean and well crafted PR!
It's very nice to see that we can now rebalance easily, even through the command line.

Only found a few nits, nothing critical.

routing/pathfind_test.go Outdated Show resolved Hide resolved
routing/pathfind.go Outdated Show resolved Hide resolved
routing/pathfind.go Outdated Show resolved Hide resolved
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Note that if you pay to yourself without any of these restrictions, it may happen that the payment comes back in through the same channel that was used to send it out. In that case balances don't change. They may only go down because of the routing fees paid.

Given that this doesn't really have a use case, perhaps we could detect this and return an error?

routing/pathfind_test.go Outdated Show resolved Hide resolved
routing/pathfind_test.go Show resolved Hide resolved
@joostjager
Copy link
Contributor Author

Given that this doesn't really have a use case, perhaps we could detect this and return an error?

I wouldn't really want to hard block this. I think we can assume that people using send to self know what they are doing. I also think we cannot really rule out that such use case would emerge at some point. There is for example the trick where you drop off more routing fees than required as a way to do spontaneous payment.

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.

The exact incoming channel cannot be specified because routing nodes forward non-strict.

We may not be able to choose which channel the HTLC is forwarded over, but we can reject the payment if it doesn't come over the intended channel and retry. Now that we index the invoice htlcs by circuit key, it should be straight forward (apart from needing to add this restriction on the invoice).

Note that if you pay to yourself without any of these restrictions, it may happen that the payment comes back in through the same channel that was used to send it out. In that case balances don't change. They may only go down because of the routing fees paid.

I don't think this would be the expected behavior for simply calling payinvoice <payreq>, and seems pretty easy to mess up. IMO this should produce a warning when source==destination, especially considering it changes the existing behavior which would normally fail. Perhaps adding an --allow-cycle flag would suffice?

routing/pathfind.go Show resolved Hide resolved
@joostjager
Copy link
Contributor Author

We may not be able to choose which channel the HTLC is forwarded over, but we can reject the payment if it doesn't come over the intended channel and retry. Now that we index the invoice htlcs by circuit key, it should be straight forward (apart from needing to add this restriction on the invoice).

I consider this out of scope for this PR? It is definitely useful functionality, also to prevent tying up capital on expensive peers.

I don't think this would be the expected behavior for simply calling payinvoice , and seems pretty easy to mess up. IMO this should produce a warning when source==destination, especially considering it changes the existing behavior which would normally fail. Perhaps adding an --allow-cycle flag would suffice?

Flag added

This prepares for routing to self. When checking the condition at the
start, the loop would terminate immediately because the source is equal
to the target.
This prepares for routing to self.
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 🍣

@joostjager joostjager merged commit 949a5c5 into lightningnetwork:master Nov 26, 2019
@ZapUser77
Copy link

ZapUser77 commented Nov 27, 2019

Thanks. Glad to see that merged in.

@WaspLN
Copy link

WaspLN commented Feb 14, 2020

Great feature. But when I tried to test it, I get the Error "[lncli] invalid vertex string length of 18, want 66"

./lncli payinvoice --allow_self_payment --outgoing_chan_id=627075670727393280 --last_hop=629203225665667072 --pay_req=lnbc200n1p0yvcaspp5np5m8g5jc6tzjj9n2fuw7we8d6hatcckewlhtljnnx5a5d2n7xnsdqqcqzpgsp5c3t24zcxua7424x0gtudkfqjdym0tcxf65rgh2pdu78mxw8hccys9qy9qsqgvnavsn5wz7a9xt3nese3rfgz488c3qc64tcav6zj5wcupmdsfc5muku93qmuelg3a0x0g8auj0xdm9tx4d44ppwxad8ffjrqq29ljsqq7lzua
[lncli] invalid vertex string length of 18, want 66

The channel_point is 66 chars long, but chan_id is 18 characters long. If I use channel_point in the place of chan_id I get a parse error

./lncli payinvoice --allow_self_payment --outgoing_chan_id=a7344c7a373612d3dfb56781a4122c015b6d8a2e6ea192974cc05637ce591666:0 --last_hop=12111e9c2f604734ddf907ea2fc3833aab53fb0f7fd5cb109f06effe8070cd28 --pay_req=lnbc200n1p0yvcaspp5np5m8g5jc6tzjj9n2fuw7we8d6hatcckewlhtljnnx5a5d2n7xnsdqqcqzpgsp5c3t24zcxua7424x0gtudkfqjdym0tcxf65rgh2pdu78mxw8hccys9qy9qsqgvnavsn5wz7a9xt3nese3rfgz488c3qc64tcav6zj5wcupmdsfc5muku93qmuelg3a0x0g8auj0xdm9tx4d44ppwxad8ffjrqq29ljsqq7lzua
Incorrect Usage.
[lncli] invalid value "a7344c7a373612d3dfb56781a4122c015b6d8a2e6ea192974cc05637ce591666:0" for flag -outgoing_chan_id: parse error

It seems LND is not happy with my chan_id and I don't know why ?

@joostjager
Copy link
Contributor Author

Last hop needs to be a node public key (33 bytes)

@WaspLN
Copy link

WaspLN commented Feb 14, 2020

Yes, that worked! I missed that little detail. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channel management The management of the nodes channels enhancement Improvements to existing features / behaviour payments Related to invoices/payments routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Ability to route to Self as destination
6 participants