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

Add the option on path creator to specify the incoming channel on blinded path #9127

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

MPins
Copy link
Contributor

@MPins MPins commented Sep 21, 2024

Fixes #8993

Change Description

Add the option on path creator to specify the incoming chained channel list

Steps to Test

lncli addinvoice --blind --blinded_path_incoming_channel_list channel_id1 amount
lncli addinvoice --blind --blinded_path_incoming_channel_list channel_id1,channel_id2 amount

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@MPins
Copy link
Contributor Author

MPins commented Sep 21, 2024

Hello @ellemouton if you think I'm on the right way I can add the option to choose a channel also.

@MPins MPins changed the title Add the option on path creator to specify the incoming node Add the option on path creator to specify the incoming node on blinded path Sep 21, 2024
@MPins
Copy link
Contributor Author

MPins commented Sep 22, 2024

Maybe change the name to "incoming_node" is a better idea! But I'll wait for others opinion also.

@ellemouton
Copy link
Collaborator

thanks @MPins - in tokyo at the moment for the LN summit so will take a look at this a bit later this week or next week

@ziggie1984
Copy link
Collaborator

I think it makes sense to just specify the incoming channel, I don't see a lot of use cases for the whole blinded route, but maybe we already prepare the code so that it will be easy to just upgrade to the whole blinded path if it has benefits.

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

Thank you for your first contribution 🎉

Please squash all commits related to the lnrpc change into one.

Moreover while reviewing this PR I found out that we have a bug in your probabiliy calculation. We basically should have the prob. of full certainty for the last hop however we need to change the logic in our probability estimator which still seems to not account for the blinded usecase see here (only when from == Self do we set the full local probability, that needs to now be inverted for the last hop as well):

func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex,
amt lnwire.MilliSatoshi, capacity btcutil.Amount) float64 {
m.mu.Lock()
defer m.mu.Unlock()
now := m.cfg.clock.Now()
results, _ := m.state.getLastPairResult(fromNode)
// Use a distinct probability estimation function for local channels.
if fromNode == m.cfg.selfNode {
return m.estimator.LocalPairProbability(now, results, toNode)
}
return m.estimator.PairProbability(
now, results, toNode, amt, capacity,
)
}

@MPins
Copy link
Contributor Author

MPins commented Oct 4, 2024

I think it makes sense to just specify the incoming channel, I don't see a lot of use cases for the whole blinded route, but maybe we already prepare the code so that it will be easy to just upgrade to the whole blinded path if it has benefits.

In most cases it would be sufficient to specify the node, the channel must be specified in cases where there is more than one channel with the same node. Of course, specifying the channel covers both use cases. I'm not sure if we should keep both options for the user, perhaps it would be more intuitive to specify the income node for most users.

@ziggie1984
Copy link
Collaborator

I prefer the channel, because than you have more control rather than the pubkey. But at the end not sure if its really worth it to treat different channels to the same peer differently because we have non-strict forwarding. So probably both options are ok ...

@MPins
Copy link
Contributor Author

MPins commented Oct 7, 2024

Thank you for your first contribution 🎉

Please squash all commits related to the lnrpc change into one.

Moreover while reviewing this PR I found out that we have a bug in your probabiliy calculation. We basically should have the prob. of full certainty for the last hop however we need to change the logic in our probability estimator which still seems to not account for the blinded usecase see here (only when from == Self do we set the full local probability, that needs to now be inverted for the last hop as well):

func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex,
amt lnwire.MilliSatoshi, capacity btcutil.Amount) float64 {
m.mu.Lock()
defer m.mu.Unlock()
now := m.cfg.clock.Now()
results, _ := m.state.getLastPairResult(fromNode)
// Use a distinct probability estimation function for local channels.
if fromNode == m.cfg.selfNode {
return m.estimator.LocalPairProbability(now, results, toNode)
}
return m.estimator.PairProbability(
now, results, toNode, amt, capacity,
)
}

Thank you for your carefully revision. I'll be working on it some time on the following days. About the probability, I invest some time trying to understanding it, but I didn't get the bug on it! From my understanding, probability is about sending the payment, right? How the payment node would even know that we are choosing the income channel/node? I'm probably missing something, I would appreciate if you give me directions to expand my understanding.

@MPins
Copy link
Contributor Author

MPins commented Oct 7, 2024

I prefer the channel, because than you have more control rather than the pubkey. But at the end not sure if its really worth it to treat different channels to the same peer differently because we have non-strict forwarding. So probably both options are ok ...

I think we can move forward with both options, but in my opinion they should be exclusive. I mean, if the channel is chosen, the node cannot be chosen. (just to avoid redundant info)

@ziggie1984
Copy link
Collaborator

So my initial idea was, that we can know the probability of the last channel in a blinded path with very high accuracy because its our own channel and we know the liquidity distribution when creating the blinded path. However looking into the codebase I think we should keep it as is, we do allow MPP payments for blinded paths so the amount can be splitted among the incoming channels in general. Moreover when we specify the incoming channel to receive on (via this PR) we already made the decision that this is the right channel to receive on the full amount, so maybe we can keep the probability estimation of the last hop/channel as is. Given the fact that we include all routes with a minimum route prob. of 1% we are good as is I think.

@MPins
Copy link
Contributor Author

MPins commented Oct 8, 2024

So my initial idea was, that we can know the probability of the last channel in a blinded path with very high accuracy because its our own channel and we know the liquidity distribution when creating the blinded path. However looking into the codebase I think we should keep it as is, we do allow MPP payments for blinded paths so the amount can be splitted among the incoming channels in general. Moreover when we specify the incoming channel to receive on (via this PR) we already made the decision that this is the right channel to receive on the full amount, so maybe we can keep the probability estimation of the last hop/channel as is. Given the fact that we include all routes with a minimum route prob. of 1% we are good as is I think.

Got it ... besides that, as it is blinded I can't think a way of considering that it is our own node without breaking the main reason for using a blinded path, that is not revealing our own node on a invoice.

@ziggie1984
Copy link
Collaborator

Got it ... besides that, as it is blinded I can't think a way of considering that it is our own node without breaking the main reason for using a blinded path, that is not revealing our own node on a invoice.

Hmm not sure what you mean, but I was just referring to the creator of the blinded path taking the incoming channel distribution directly into account without really relying on the MC data. The path would still be blinded for the sender so the sender would just have a sorted list of blinded paths in the bolt11 invoice.

@MPins
Copy link
Contributor Author

MPins commented Oct 8, 2024

Got it ... besides that, as it is blinded I can't think a way of considering that it is our own node without breaking the main reason for using a blinded path, that is not revealing our own node on a invoice.

Hmm not sure what you mean, but I was just referring to the creator of the blinded path taking the incoming channel distribution directly into account without really relying on the MC data. The path would still be blinded for the sender so the sender would just have a sorted list of blinded paths in the bolt11 invoice.

Never mind ... I was thinking that the GetProbability func would be called when the payment is being processed by the sender.

@MPins
Copy link
Contributor Author

MPins commented Oct 8, 2024

So my initial idea was, that we can know the probability of the last channel in a blinded path with very high accuracy because its our own channel and we know the liquidity distribution when creating the blinded path. However looking into the codebase I think we should keep it as is, we do allow MPP payments for blinded paths so the amount can be splitted among the incoming channels in general. Moreover when we specify the incoming channel to receive on (via this PR) we already made the decision that this is the right channel to receive on the full amount, so maybe we can keep the probability estimation of the last hop/channel as is. Given the fact that we include all routes with a minimum route prob. of 1% we are good as is I think.

I just saw that it is called by FindBlindedPaths ... Thank you, I have a better understanding of the whole process now.

I think you right ... maybe it should be changed ... not sure if it should be included in this PR or maybe on a specific one for that.

@saubyk
Copy link
Collaborator

saubyk commented Oct 13, 2024

Have a basic question here.
The problem statement in the linked issue is regarding specifying an incoming channel...

  • to have better control over payment success probability
  • to better control the liquidity distribution available on the node

So why are we then giving the user the control of selecting a node in the cli, instead of directly specifying a channel?
I believe the user should only specify the channel not the node (which I find confusing)

@MPins
Copy link
Contributor Author

MPins commented Oct 13, 2024

Have a basic question here. The problem statement in the linked issue is regarding specifying an incoming channel...

  • to have better control over payment success probability
  • to better control the liquidity distribution available on the node

So why are we then giving the user the control of selecting a node in the cli, instead of directly specifying a channel? I believe the user should only specify the channel not the node (which I find confusing)

The idea to have the option to specify the node instead of the channel is because in the most cases it would be enough and from the node runner perspective it would be more intuitive specifying just the income node.

@MPins MPins changed the title Add the option on path creator to specify the incoming node on blinded path Add the option on path creator to specify the incoming node or channel on blinded path Oct 13, 2024
@ziggie1984
Copy link
Collaborator

So why are we then giving the user the control of selecting a node in the cli, instead of directly specifying a channel?
I believe the user should only specify the channel not the node (which I find confusing)

Good question, I also tend to only support the incoming channel id why:

  1. When creating the blinded path we do not create a Unified Edge meaning that we do NOT take all the different policies for all the channels with the same peer into account. Moreover we cannot be sure that all policies are the same, other implementations iirc can have different policies for different channels, therefore I recommend only using the channel ID here.
  2. Although the lightning network supports non-strict forwarding which means the forwarder can basically select another channel if he wants to, but as mentioned before, we are not unifying the edges to create the worst case policy to the last node. So I think we should stick to the incoming channel id here and should not allow the node id.

@ziggie1984
Copy link
Collaborator

Imagine your peer has 2 channels with you and different policies, now when creating the blinded path and using the nodeid, you cannot control the particular channel and the sender will probably use the route with the better constraints. We already have something similar when sending a payment where we can select the outgoing channel. We should prob. stick to this form.

@MPins
Copy link
Contributor Author

MPins commented Oct 13, 2024

I think that

Imagine your peer has 2 channels with you and different policies, now when creating the blinded path and using the nodeid, you cannot control the particular channel and the sender will probably use the route with the better constraints. We already have something similar when sending a payment where we can select the outgoing channel. We should prob. stick to this form.

When sending payment you can also choose the last hop (penultimate node in the path) to route through for the payment, but it is other use case. So I think you both are right, I'm going to take the node option out.

@ziggie1984
Copy link
Collaborator

Good observation that we also allow the last hop in the payment flow, but LND does unify the edges in the sending flow and selects the most expensive policy that's why it makes sense to have this last hop setting.

@MPins
Copy link
Contributor Author

MPins commented Oct 13, 2024

Good observation that we also allow the last hop in the payment flow, but LND does unify the edges in the sending flow and selects the most expensive policy that's why it makes sense to have this last hop setting.

Perfect ... I'm going to take the node option out. Thank you @saubyk for starting this exchange of ideas.

@saubyk
Copy link
Collaborator

saubyk commented Oct 13, 2024

Good observation that we also allow the last hop in the payment flow, but LND does unify the edges in the sending flow and selects the most expensive policy that's why it makes sense to have this last hop setting.

Perfect ... I'm going to take the node option out. Thank you @saubyk for starting this exchange of ideas.

Thanks. Not to add the confusion, but I do understand the logic of selecting the node from a UX standpoint and especially when you imagine a user doing it in a UI. Selecting a pub key (with an alias) is much easier than selecting a channel ID. But I think that problem can be addressed at the application level, where the UI can establish that node-channel linkage and present a user friendly way for the user to make a selection.

@ellemouton
Copy link
Collaborator

I prefer the channel, because than you have more control rather than the pubkey.

The problem is that you dont actually every have this control due to non-strict forwarding. At the end of the day, the peer may choose any channel to fwd on as long as the peer on the other end is the same peer.

Regarding the impl here and if we only want to specify final hop or list of hops, I think things should be made general enough for both:

  • so if user specifies 1 peer, then LND takes that as a fixed final hop and uses its current logic to build on that given the other config values
  • use can specify a list of hops and LND will just do the same thing as above.

@MPins
Copy link
Contributor Author

MPins commented Oct 16, 2024

  • use can specify a list of hops and LND will just do the same thing as above.

The way it is done here the user can specify the last hop many times (peers or channels, not both). If I understand you correctly it should be kept this way. Right?

@ziggie1984
Copy link
Collaborator

ziggie1984 commented Oct 16, 2024

@ellemouton what's your take on this, we cannot really know whether peers have a universal policy to us?

Imagine your peer has 2 channels with you and different policies, now when creating the blinded path and using the nodeid, you cannot control the particular channel and the sender will probably use the route with the better constraints. We already have something similar when sending a payment where we can select the outgoing channel. We should prob. stick to this form.

@MPins MPins force-pushed the issue-8993 branch 4 times, most recently from c3f90f5 to e82adc7 Compare February 3, 2025 18:52
@MPins MPins requested a review from ziggie1984 February 3, 2025 19:07
@MPins
Copy link
Contributor Author

MPins commented Feb 11, 2025

Hello @ellemouton and @ziggie1984 this is a kindly reminder that the PR is ready for your review. Thanks.

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

Very close this one as well 🤝

  • Had an edge case where we need to make sure if the min_distance is specified and is smaller than the chained_channels array, that we either error out or set it to the length of the array.

  • Moreover I think when looking for the routes, we should just lookup the channel directly without looping through all the channels of a node, because the callbacks are designed in a way that we cannot easily abort them and have to loop through all the channels.

Apart from that, kudos to your patience working on this PR, it's definitly not easy to get a direction change in between and having a bit of a time delay in reviews 🧘‍♂️

Comment on lines 3987 to 3988
generated blinded paths as incoming hops. The first channel in the list
is the one closest to this one.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: take the descrption from the lncli cmd which is good: A list of chained channels that should be used in any of our generated blinded paths as incoming hops starting with the channel which points to the destination/target. These chained channels need to be connected otherwise the blinded route generation will fail.

cli.StringSliceFlag{
Name: "blinded_path_incoming_channel_list",
Usage: "The chained channels (specified via channel " +
"id) starting from the receiver node which " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: starting form a channel which points to the receiver node.

@@ -168,7 +175,7 @@ func addInvoice(ctx *cli.Context) error {

blindedPathCfg, err := parseBlindedPathCfg(ctx)
if err != nil {
return fmt.Errorf("could not parse blinded path config: %w",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why don't we wrap anymore ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind ... should be wrapping.

@@ -1192,6 +1192,10 @@ type blindedPathRestrictions struct {
// nodeOmissionSet holds a set of node IDs of nodes that we should
// ignore during blinded path selection.
nodeOmissionSet fn.Set[route.Vertex]

// incomingChainedChannels holds a route of chained channels that we
// should use as incoming hops during blinded path selection.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: please also add the detailed description that the first entry in the list is the channel which points to the destination/target.

},
})

// Assert that it contains two paths with 3 hops, both with dave as the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Maybe add to the comment the destination always is the last hop, I personally had to look it up.

// 2) Extend the search to include 2 hops other than the destination.
// 2) Now with bob-dave as the incoming channel.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a testcase minNumHops = 0, and maxNum = 1, and check how many paths are returned ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

currently this would return 2 paths, one being only the intro-node and the other one being the incomin-channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure ... Actually it will return 3 paths, one being only the intro-node and the others with one hop other than the destination hop.

dave
bob,dave
charlie,dave

Copy link
Collaborator

@ziggie1984 ziggie1984 Feb 20, 2025

Choose a reason for hiding this comment

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

exactly and I think the "only dave route" is not what we want, if we specify an incoming channel but have mistakenly set the global minimum to 0.

@@ -773,3 +773,19 @@ func (r *Route) String() string {
b.String(), r.TotalTimeLock,
)
}

// ChanIDString returns the route's channel IDs as a formatted string.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, please keep the commit msg smaller than 50 chars for the header.

Copy link
Contributor Author

@MPins MPins left a comment

Choose a reason for hiding this comment

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

Thank you .. I'm participating on btc++, that's why it is taking more time to addresss your last review.

@@ -168,7 +175,7 @@ func addInvoice(ctx *cli.Context) error {

blindedPathCfg, err := parseBlindedPathCfg(ctx)
if err != nil {
return fmt.Errorf("could not parse blinded path config: %w",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind ... should be wrapping.

@lightninglabs-deploy
Copy link

@ellemouton: review reminder
@MPins, remember to re-request review from reviewers when ready

MPins added 2 commits March 2, 2025 00:14
Add an option to the addinvoice rpc which allows to specify the blinded
path via a list of chained channels.
Including the blinded path incoming channel list argument to the addinvoice command,
parsing and verifying that it has one or a comma separeted list of channels id.
@MPins MPins force-pushed the issue-8993 branch 5 times, most recently from 20f0ecf to 80cf806 Compare March 2, 2025 10:40
MPins added 9 commits March 3, 2025 07:42
Adding the incoming channel list parameter to FindBlindedPaths function
on router.go, adding the ability to restrict the blinded route to the
chained channel list for incoming channel. The first entry in the list
is the channel which points to the destination/target.
This commit makes sure that when an incoming channel list is
supplied for the blinded route, that it changes the other blinding
restrictions accordingly. Moreover it introduces a sanity check when
the number of paths for the blinded route is set to 0.
ChanIDString returns a string representation of the route's
channel IDs, formatting them in the order they appear in the
route (e.g., "chanID1 -> chanID2").
Discarded routes with a success probability lower than the minimum
threshold are now logged accordingly when finding a blinded path.
@MPins MPins requested a review from ziggie1984 March 3, 2025 11:31
@MPins
Copy link
Contributor Author

MPins commented Mar 3, 2025

Hello @ziggie1984 and @ellemouton ready for the next review 😊 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Route Blinding: allow path creator to specify incoming channel
5 participants