-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add the option on path creator to specify the incoming channel on blinded path #9127
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
base: master
Are you sure you want to change the base?
Conversation
Hello @ellemouton if you think I'm on the right way I can add the option to choose a channel also. |
Maybe change the name to "incoming_node" is a better idea! But I'll wait for others opinion also. |
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 |
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. |
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.
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):
Lines 509 to 526 in 2d33317
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, | |
) | |
} |
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. |
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 ... |
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. |
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) |
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. |
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. |
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. |
Have a basic question here.
So why are we then giving the user the control of selecting a node in the cli, instead of directly specifying a channel? |
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. |
Good question, I also tend to only support the incoming channel id why:
|
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. |
I think that
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. |
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. |
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:
|
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? |
@ellemouton what's your take on this, we cannot really know whether peers have a universal policy to us?
|
Hello @ziggie1984 , the pending nits have been addressed. Thanks so much for your time and review! |
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 💪🥇
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.
Thanks for the updates here @MPins 🙏
While I think the logic works, the quality of the PR is not up to scratch:
- the logic is currently quite spread out and not as simple/contained as it can be.
- The commit structure is not great - making the PR difficult to review
- Our code formatting styles have not been followed in many places.
I've put together this draft/demo PR for you to take a look at. The main thing I show here is how I would go about 1) implementing the logic change and 2) structuring the commits
(it's obvs a draft and so is missing some things & youd need to still add on the itest commits - but i hope this can help you see what we're looking for here). Feel free to let me know if you have any questions 🙏
8dcf2cf
to
434313d
Compare
@ellemouton thank you so much for your time and careful review. You and @ziggie1984 are helping me a lot. I have addressed all the comments, and I believe the PR is now much easier to review. 🙏 |
for _, chanID := range restrictions.incomingChainedChannels { | ||
visited[nextTarget] = true | ||
|
||
err := g.ForEachNodeDirectedChannel(nextTarget, |
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.
Looking at the implementation of func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (
I would appreciate an explanation why we are not implemented the graphCache there cc @ellemouton
also keep in mind there is currently this issue regarding the cache: #9465
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.
Looking at the implementation of func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) ( I would appreciate an explanation why we are not implemented the graphCache there cc @ellemouton
we currently only use graph cache for pathfinding calls. Have a look at the implementation of the graph cache - everything in there is indexed by node id & not channel id. we'd need to store a whole new index in there to make this call efficient
In this commit, the blindedPathRestrictions are expanded to include a list of incoming channels that must be included in any blinded path. The unit tests are expanded to test this new logic.
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.
Create the ChanIDString function to return 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.
Assert that the BlindedPaths.MaxNumPaths value is non-zero.
Assert that the blindCfg.MaxNumPaths value is non-zero.
@ellemouton: review reminder |
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.
so close! Thanks for the updates :) looking much better now 🎉
(just btw - we'll hold off on merging this until 19 has been released. But we can defs get this in merge ready state before then 👍 )
maxNumHops: 3, | ||
incomingChainedChannels: []uint64{2, 7, 6, 3}, | ||
}) | ||
require.Error(t, err) |
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.
please assert the contents of the error as is done in the demo PR 🙏
require.ErrorContains(t, err, "circular route")
nodeOmissionSet: fn.NewSet(ctx.keyFromAlias("bob")), | ||
incomingChainedChannels: []uint64{2}, | ||
}) | ||
require.Error(t, err) |
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 think we should never use require.Error
just as is. We should always assert that we get an error we expect to get
maxNumHops: restrictions.NumHops, | ||
nodeOmissionSet: restrictions.NodeOmissionSet, | ||
incomingChainedChannels: incomingChainedChannels, | ||
}) |
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.
formatting
routeWithProbability := &routeWithProbability{ | ||
route: &route.Route{ | ||
SourcePubKey: introNode, | ||
Hops: hops, | ||
}, | ||
probability: totalRouteProbability, | ||
} | ||
|
||
// Don't bother adding a route if its success probability less |
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 dont follow why this move was needed here
@@ -1310,7 +1342,7 @@ func processNodeForBlindedPath(g Graph, node route.Vertex, | |||
} | |||
|
|||
// At this point, copy the alreadyVisited map. | |||
visited := make(map[route.Vertex]bool, len(alreadyVisited)) | |||
visited := make(map[route.Vertex]bool, len(alreadyVisited)+1) |
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.
but then we should add a comment to explain this.
iirc, the demo PR doesnt add this +1. Can we not do what was done there instead @MPins ?
@@ -533,6 +533,14 @@ | |||
"format": "byte" | |||
}, | |||
"description": "A list of node IDs of nodes that should not be used in any of our generated\nblinded paths." | |||
}, |
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.
@MPins - you resolved this comment but it hasnt been addressed?
"probability path(%.3f)", | ||
route.ChanIDString(routeWithProbability.route), | ||
routeWithProbability.probability, | ||
) |
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.
re my previous comment: ok cool - but then that code refactor should be done here. In the commit where it is currently done, it is a no-op
@@ -6212,6 +6212,41 @@ func (r *rpcServer) AddInvoice(ctx context.Context, | |||
|
|||
blindingRestrictions.NodeOmissionSet.Add(vertex) | |||
} |
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.
could use a commit message description
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
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.