routing: swap out final hop blinded route pub keys

If multiple blinded paths are provided, they will each have a different
pub key for the destination node. This makes using our existing
pathfinding logic tricky since it depends on having a single destination
node (characterised by a single pub key). We want to re-use this logic.
So what we do is swap out the pub keys of the destinaion hop with a
pseudo target pub key. This will then be used during pathfinding. Later
on once a path is found, we will swap the real destination keys back in
so that onion creation can be done.
This commit is contained in:
Elle Mouton
2024-05-15 15:52:17 +02:00
parent 4a22ec8413
commit 8df03de3e9
6 changed files with 99 additions and 42 deletions

View File

@@ -153,19 +153,24 @@ func newRoute(sourceVertex route.Vertex,
// sender of the payment.
nextIncomingAmount lnwire.MilliSatoshi
blindedPath *sphinx.BlindedPath
blindedPayment *BlindedPayment
)
if blindedPathSet != nil {
blindedPath = blindedPathSet.GetPath().BlindedPath
}
pathLength := len(pathEdges)
for i := pathLength - 1; i >= 0; i-- {
// Now we'll start to calculate the items within the per-hop
// payload for the hop this edge is leading to.
edge := pathEdges[i].policy
// If this is an edge from a blinded path and the
// blindedPayment variable has not been set yet, then set it now
// by extracting the corresponding blinded payment from the
// edge.
isBlindedEdge := pathEdges[i].blindedPayment != nil
if isBlindedEdge && blindedPayment == nil {
blindedPayment = pathEdges[i].blindedPayment
}
// We'll calculate the amounts, timelocks, and fees for each hop
// in the route. The base case is the final hop which includes
// their amount and timelocks. These values will accumulate
@@ -212,8 +217,9 @@ func newRoute(sourceVertex route.Vertex,
// node's CLTV delta. The exception is for the case
// where the final hop is the blinded path introduction
// node.
if blindedPath == nil ||
len(blindedPath.BlindedHops) == 1 {
if blindedPathSet == nil ||
len(blindedPathSet.GetPath().BlindedPath.
BlindedHops) == 1 {
// As this is the last hop, we'll use the
// specified final CLTV delta value instead of
@@ -245,7 +251,7 @@ func newRoute(sourceVertex route.Vertex,
metadata = finalHop.metadata
if blindedPath != nil {
if blindedPathSet != nil {
totalAmtMsatBlinded = finalHop.totalAmt
}
} else {
@@ -305,11 +311,25 @@ func newRoute(sourceVertex route.Vertex,
// If we are creating a route to a blinded path, we need to add some
// additional data to the route that is required for blinded forwarding.
// We do another pass on our edges to append this data.
if blindedPath != nil {
if blindedPathSet != nil {
// If the passed in BlindedPaymentPathSet is non-nil but no
// edge had a BlindedPayment attached, it means that the path
// chosen was an introduction-node-only path. So in this case,
// we can assume the relevant payment is the only one in the
// payment set.
if blindedPayment == nil {
blindedPayment = blindedPathSet.GetPath()
}
var (
inBlindedRoute bool
dataIndex = 0
blindedPath = blindedPayment.BlindedPath
numHops = len(blindedPath.BlindedHops)
realFinal = blindedPath.BlindedHops[numHops-1].
BlindedNodePub
introVertex = route.NewVertex(
blindedPath.IntroductionPoint,
)
@@ -337,6 +357,11 @@ func newRoute(sourceVertex route.Vertex,
if i != len(hops)-1 {
hop.AmtToForward = 0
hop.OutgoingTimeLock = 0
} else {
// For the final hop, we swap out the pub key
// bytes to the original destination node pub
// key for that payment path.
hop.PubKeyBytes = route.NewVertex(realFinal)
}
dataIndex++