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

Allow user specify routing hints in private invoice. #3672

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

roeierez
Copy link
Contributor

@roeierez roeierez commented Nov 4, 2019

This PR changes the AddInvoice/AddHoldInvoice RPC endpoints to be able to get routing hints and populate them in the resulted invoice.
In fact the RoutingHints already existed in both lnrpc.Invoice and lnrpc.AddHoldInvoiceRequest but were ignored and this change only adds them to the invoice.

This is useful in the following cases:

  1. When ones want to expose specific private channels, or to get payment via them.
  2. When the default routing hints logic skips some channels due to incomplete graph state (see issue Private channel can't receive despite being notified as active. #3660). This is specifically important to enable receiving funds on mobile wallets that just bootstrapped with a new channel.

@halseth
Copy link
Contributor

halseth commented Nov 7, 2019

Can be consolidated with #3022? Or is it different?

@roeierez
Copy link
Contributor Author

roeierez commented Nov 7, 2019

Can be consolidated with #3022? Or is it different?

Yes, needs to. I didn't see the other PR when opened this. I Actually think the approach there is better (user needs to only pass channel ids as hops).
I believe what made me walk this path is that I saw routing_hints field in AddHoldInvoiceRequest, worth removing it as part of #3022.

@roeierez
Copy link
Contributor Author

roeierez commented Nov 7, 2019

@halseth Looking again at #3022 it won't be usable for the use case in this PR. In #3022 the private channels passed only serve as filter while at this PR they are given by the user explicitly.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour P3 might get fixed, nice to have payments Related to invoices/payments routing labels Nov 9, 2019
@halseth
Copy link
Contributor

halseth commented Nov 11, 2019

in what cases will it be useful to add hints for channels not known by the receiver (and hence the #3022 approach won't work)?

EDIT: Just read the latest response on #3660, and see that it could be useful in the case where the remote node info is not yet known.

@roeierez
Copy link
Contributor Author

EDIT: Just read the latest response on #3660, and see that it could be useful in the case where the remote node info is not yet known.

Yes that's the case.

Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Catching up on the overlap between this and #3022:
3022: User provides a list of channels which restricts which channels we use to create hop hints, with the intention of limiting which channels are used for hop hints for balancing reasons
3672: User specifically provides the hop hints they need, to cover the case where the current logic does not allow creating a hint for the desired channel yet

@roeierez what are your thoughts on limiting the hints used for invoices to the route hints provided by the user? This would cover the use case of #3022 because the user can just provide hints for the channels they want to include.

There is a UX consideration of having to construct hints yourself wrt work for the user + potential for error. Generally, it would be nice to be able to check that the user provided hints are ok, but not in the case of #3660. We could potentially address this with a getHopHint endpoint which will produce a hop hint for a given channel and perform validation on the channel? Most users can query this endpoint to get hints for the channels which they want to use, and in special use cases you can just roll your own?

Tagging @Crypt-iQ, author of #3022, to loop him into this discussion.

@roeierez
Copy link
Contributor Author

roeierez commented Dec 2, 2019

@roeierez what are your thoughts on limiting the hints used for invoices to the route hints provided by the user? This would cover the use case of #3022 because the user can just provide hints for the channels they want to include.

I am fine with this approach.

There is a UX consideration of having to construct hints yourself wrt work for the user + potential for error. Generally, it would be nice to be able to check that the user provided hints are ok, but not in the case of #3660. We could potentially address this with a getHopHint endpoint which will produce a hop hint for a given channel and perform validation on the channel? Most users can query this endpoint to get hints for the channels which they want to use, and in special use cases you can just roll your own?

I actually like the approach of #3022 where the user is only pass channel ids as input instead of RouteHint structures and your arguments explains that well.
I would suggest to go with the #3022 with some small changes to solve this use case as well.

I can think of two approaches for such adaptation:

  1. If user passes explicit channel ids, then skip validation (public channel) in LND and force populating the route hints.
  2. Add additional flag to force populating the route hints.

Since this is a bit "advanced" use case I tend to go with #1.

@Crypt-iQ
Copy link
Collaborator

Crypt-iQ commented Dec 5, 2019

I think either method (3022 or 3672) would work. My motivation for opening 3022 was for privacy reasons since creating an invoice populates all private channels by default with no option for specificity. As long as that is addressed (which both methods would), I'm fine :)

@Roasbeef Roasbeef requested a review from halseth July 23, 2020 03:04
@Roasbeef Roasbeef added this to the 0.12.0 milestone Jul 23, 2020
@halseth
Copy link
Contributor

halseth commented Jul 23, 2020

@roeierez Do you want to pick this up again? I think we can get this merged addressing the following:

  1. If private == false and the user specifies route hints, add only these route hints when creating the invoice (this should address the privacy concern from invoicesrpc: specify private hops for addinvoice, addholdinvoice #3022).
  2. If private == true, add additional route hints for private channels to the invoice.

This should also let the user specify public channels as route hints, which can be useful in certain cases.

We should also update the RPC documentation to reflect the behaviour.

@roeierez
Copy link
Contributor Author

@roeierez Do you want to pick this up again?

Sounds good. I'll address the feedback.

@hsjoberg
Copy link
Contributor

hsjoberg commented Sep 10, 2020

Needs rebase. The route hints code was refactored in #4521.

Unless I'm missing something, but this PR seems more powerful than #3022 as it allows for fake channels and the Pay to Open use-case explained here: #4018. Perhaps the other PR could be reworked to work with this one?

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.

A few nits otherwise LGTM 👍

lnrpc/invoicesrpc/addinvoice.go Outdated Show resolved Hide resolved
usedChannels := make(map[uint64]struct{})
for i, h := range invoice.RouteHints {
if i >= 20 {
break
Copy link
Contributor

Choose a reason for hiding this comment

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

return error instead?

@halseth
Copy link
Contributor

halseth commented Sep 11, 2020

Also needs rebase as pointed out by @hsjoberg

@Crypt-iQ
Copy link
Collaborator

Closed the other one in favor of this one @roeierez

@halseth halseth requested a review from Crypt-iQ September 11, 2020 12:43
@hsjoberg
Copy link
Contributor

Note that this one currently does not support providing route hints via the CLI, only RPC

Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

I think we'll want lncli to be updated with the same capabilities.

lnrpc/rpc.proto Outdated
@@ -2659,7 +2659,8 @@ message Invoice {

/*
Route hints that can each be individually used to assist in reaching the
invoice's destination.
invoice's destination. The specified routing hints will be included in
the invoice.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment changes need to re-generate protos as the comments are replicated in other lnrpc files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the comment change, not needed after all.

break
}
options = append(options, zpay32.RouteHint(h))
usedChannels[h[0].ChannelID] = struct{}{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should index like this - what if h is empty? Why is only the first channel added to usedChannels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Crypt-iQ
Added validation for h is empty, missed that so thanks for catching it.
Regarding indexing, I am thinking only the first hop is our direct channel, am I missing something?

@Roasbeef
Copy link
Member

Roasbeef commented Nov 4, 2020

Is this PR still active? The 0.12 window is closing in a week or so.

@halseth
Copy link
Contributor

halseth commented Nov 4, 2020

ping @roeierez

@roeierez
Copy link
Contributor Author

roeierez commented Nov 5, 2020

ping @roeierez

Yes, I am here :). Going to pick this up again.

@roeierez roeierez force-pushed the invoice-hints branch 4 times, most recently from 036ccb5 to a022990 Compare November 6, 2020 05:52
@roeierez
Copy link
Contributor Author

roeierez commented Nov 6, 2020

@halseth rebased and adapted to the code changes that have been introduced since the start of this PR.
Also added an integration test.

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.

Apart from a few nits this LGTM 👯‍♂️

lnrpc/invoicesrpc/addinvoice.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/addinvoice.go Outdated Show resolved Hide resolved
lnrpc/invoicesrpc/addinvoice.go Show resolved Hide resolved
lntest/itest/lnd_single_hop_invoice_test.go Outdated Show resolved Hide resolved
@halseth halseth requested review from Crypt-iQ and removed request for Crypt-iQ November 6, 2020 10:12
Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Great to get this in!


// Optional route hints that can each be individually used to assist in
// reaching the invoice's destination.
RouteHints [][]zpay32.HopHint
Copy link
Collaborator

Choose a reason for hiding this comment

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

nittynit: godocs shoudl start with the var name RouteHints...

lntest/itest/lnd_single_hop_invoice_test.go Show resolved Hide resolved
@hsjoberg
Copy link
Contributor

hsjoberg commented Nov 6, 2020

utACK @ 4463a4c, although I've tested previous iterations.

@Roasbeef Roasbeef merged commit 99b0913 into lightningnetwork:master Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour P3 might get fixed, nice to have payments Related to invoices/payments routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants