Skip to content

Commit 3415480

Browse files
committed
routing+itest: fix route blinding path selection bug
Here we fix a bug which would not include the selected incoming blinded path chain from being included in the selected path set if it meets the minimum length requirement. The appropriate unit test and itest is updated to demonstrate the fix.
1 parent 51f1932 commit 3415480

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

itest/lnd_route_blinding_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,9 +1589,10 @@ func testPartiallySpecifiedBlindedPath(ht *lntest.HarnessTest) {
15891589
},
15901590
})
15911591

1592-
// Assert that it contains one path with 3 hops, with eve as the
1593-
// introduction node.
1594-
assertPathDetails(invoice, 3, eve.PubKey[:])
1592+
// Assert that it contains two paths: one 3 hop one starting at Eve and
1593+
// a 3 hop one starting at Dave (this one will be padded with a dummy
1594+
// hop) in order to keep all the paths equidistant.
1595+
assertPathDetails(invoice, 3, eve.PubKey[:], dave.PubKey[:])
15951596

15961597
// Check that Frank can pay the invoice.
15971598
ht.CompletePaymentRequests(frank, []string{invoice.PaymentRequest})

routing/pathfind.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,31 +1339,35 @@ func findBlindedPaths(g Graph, target route.Vertex,
13391339
return nil, err
13401340
}
13411341

1342-
orderedPaths := make([][]blindedHop, len(paths))
1343-
1344-
// When there is no path to add, but incomingChainedChannels can be
1345-
// used.
1346-
if len(paths) == 0 && haveIncomingPath {
1347-
orderedPaths = [][]blindedHop{incomingPath}
1348-
} else {
1349-
// Reverse each path so that the order is correct (from
1350-
// introduction node to last hop node) and then append this node
1351-
// on as the destination of each path.
1352-
for i, path := range paths {
1353-
sort.Slice(path, func(i, j int) bool {
1354-
return j < i
1355-
})
1342+
// Reverse each path so that the order is correct (from introduction
1343+
// node to last hop node) and then append the incoming path (if any was
1344+
// specified) to the end of the path.
1345+
orderedPaths := make([][]blindedHop, 0, len(paths))
1346+
for _, path := range paths {
1347+
sort.Slice(path, func(i, j int) bool {
1348+
return j < i
1349+
})
13561350

1357-
orderedPaths[i] = append(path, incomingPath...)
1358-
}
1351+
orderedPaths = append(
1352+
orderedPaths, append(path, incomingPath...),
1353+
)
1354+
}
1355+
1356+
// There is a chance we have an incoming path that by itself satisfies
1357+
// the minimum hop restriction. In that case, we add it as its own path.
1358+
if haveIncomingPath &&
1359+
len(incomingPath) > int(restrictions.minNumHops) {
1360+
1361+
orderedPaths = append(orderedPaths, incomingPath)
13591362
}
13601363

13611364
// Handle the special case that allows a blinded path with the
1362-
// introduction node as the destination node.
1365+
// introduction node as the destination node. This only applies if no
1366+
// incoming path was specified since in that case, by definition, the
1367+
// caller wants a non-zero length blinded path.
13631368
if restrictions.minNumHops == 0 && !haveIncomingPath {
13641369
singleHopPath := [][]blindedHop{{{vertex: target}}}
13651370

1366-
//nolint:makezero
13671371
orderedPaths = append(
13681372
orderedPaths, singleHopPath...,
13691373
)

routing/pathfind_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,9 +3941,11 @@ func TestFindBlindedPaths(t *testing.T) {
39413941
require.NoError(t, err)
39423942

39433943
// We expect the following paths:
3944+
// - B, D
39443945
// - F, B, D
39453946
// - E, B, D
39463947
assertPaths(paths, []string{
3948+
"bob,dave",
39473949
"frank,bob,dave",
39483950
"eve,bob,dave",
39493951
})

0 commit comments

Comments
 (0)