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

Use all valid routes during blinded path construction #9334

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lnrpc/invoicesrpc/addinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ type BlindedPathConfig struct {
// less than this.
MinNumPathHops uint8

// MaxNumPaths is the maximum number of blinded paths to select.
MaxNumPaths uint8

// DefaultDummyHopPolicy holds the default policy values to use for
// dummy hops in a blinded path in the case where they cant be derived
// through other means.
Expand Down Expand Up @@ -542,6 +545,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
},
MinNumHops: blindCfg.MinNumPathHops,
DefaultDummyHopPolicy: blindCfg.DefaultDummyHopPolicy,
MaxNumPaths: blindCfg.MaxNumPaths,
},
)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion routing/blindedpath/blinded_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ type BuildBlindedPathCfg struct {
// route.
MinNumHops uint8

// MaxNumPaths is the maximum number of blinded paths to select.
MaxNumPaths uint8

// DefaultDummyHopPolicy holds the policy values that should be used for
// dummy hops in the cases where it cannot be derived via other means
// such as averaging the policy values of other hops on the path. This
Expand Down Expand Up @@ -132,8 +135,11 @@ func BuildBlindedPaymentPaths(cfg *BuildBlindedPathCfg) (
paths := make([]*zpay32.BlindedPaymentPath, 0, len(routes))

// For each route returned, we will construct the associated blinded
// payment path.
// payment path, until the maximum number of allowed paths.
MPins marked this conversation as resolved.
Show resolved Hide resolved
for _, route := range routes {
if len(paths) >= int(cfg.MaxNumPaths) {
break
}
// Extract the information we need from the route.
candidatePath := extractCandidatePath(route)

Expand Down
13 changes: 4 additions & 9 deletions routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,13 @@ func (r *ChannelRouter) FindBlindedPaths(destination route.Vertex,
return routes[i].probability > routes[j].probability
})

// Now just choose the best paths up until the maximum number of allowed
// paths.
bestRoutes := make([]*route.Route, 0, restrictions.MaxNumPaths)
// Return all routes.
allRoutes := make([]*route.Route, 0, len(routes))
for _, route := range routes {
if len(bestRoutes) >= int(restrictions.MaxNumPaths) {
break
}

bestRoutes = append(bestRoutes, route.route)
allRoutes = append(allRoutes, route.route)
}

return bestRoutes, nil
return allRoutes, nil
}

// generateNewSessionKey generates a new ephemeral private key to be used for a
Expand Down
23 changes: 1 addition & 22 deletions routing/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 3,
},
)
require.NoError(t, err)
Expand Down Expand Up @@ -3201,8 +3200,7 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
}

// Now, let's lower the MC probability of the B-D to 0.5 and F-D link to
// 0.25. We will leave the MaxNumPaths as 3 and so all paths should
// still be returned but the order should be:
// 0.25:
// 1) A -> C -> D
// 2) A -> B -> D
// 3) A -> F -> D
Expand All @@ -3212,7 +3210,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 3,
},
)
require.NoError(t, err)
Expand All @@ -3229,7 +3226,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 3,
},
)
require.NoError(t, err)
Expand All @@ -3239,27 +3235,12 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
"alice,charlie,dave",
})

// Change the MaxNumPaths to 1 to assert that only the best route is
// returned.
routes, err = ctx.router.FindBlindedPaths(
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 1,
},
)
require.NoError(t, err)
assertPaths(routes, []string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we still check here the expected number of paths now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we could, but it would be redundant since this is already tested in the previous tests.

"alice,bob,dave",
})

// Test the edge case where Dave, the recipient, is also the
// introduction node.
routes, err = ctx.router.FindBlindedPaths(
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 0,
NumHops: 0,
MaxNumPaths: 1,
},
)
require.NoError(t, err)
Expand All @@ -3274,7 +3255,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 3,
},
)
require.NoError(t, err)
Expand All @@ -3289,7 +3269,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
MinDistanceFromIntroNode: 2,
NumHops: 2,
MaxNumPaths: 3,
NodeOmissionSet: fn.NewSet(frank),
},
)
Expand Down
1 change: 1 addition & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6168,6 +6168,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
MaxHTLCMsat: 0,
},
MinNumPathHops: blindingRestrictions.NumHops,
MaxNumPaths: blindingRestrictions.MaxNumPaths,
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 unit-test which tests this selection

}
}

Expand Down
Loading