From c0d00449f847e1be064e989526e6e8ec99dc384b Mon Sep 17 00:00:00 2001 From: MPins Date: Thu, 5 Dec 2024 11:24:34 -0300 Subject: [PATCH 1/5] blindedpath: add the MaxNumPaths restriction on BuildBlindedPaymentPaths --- routing/blindedpath/blinded_path.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/routing/blindedpath/blinded_path.go b/routing/blindedpath/blinded_path.go index 5c16751858..660c1d652a 100644 --- a/routing/blindedpath/blinded_path.go +++ b/routing/blindedpath/blinded_path.go @@ -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 @@ -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. for _, route := range routes { + if len(paths) >= int(cfg.MaxNumPaths) { + break + } // Extract the information we need from the route. candidatePath := extractCandidatePath(route) From b7741af6fcf48be4f6b57b3643cbd005905066d4 Mon Sep 17 00:00:00 2001 From: MPins Date: Thu, 5 Dec 2024 11:19:01 -0300 Subject: [PATCH 2/5] invoicesrpc: included MaxNumPaths to be used on BuildBlindedPaymentPaths --- lnrpc/invoicesrpc/addinvoice.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index 114e357188..684cbafd57 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -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. @@ -542,6 +545,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, }, MinNumHops: blindCfg.MinNumPathHops, DefaultDummyHopPolicy: blindCfg.DefaultDummyHopPolicy, + MaxNumPaths: blindCfg.MaxNumPaths, }, ) if err != nil { From e6f8f8dcb90247318c4e28e2386ba8292c460521 Mon Sep 17 00:00:00 2001 From: MPins Date: Thu, 5 Dec 2024 11:29:05 -0300 Subject: [PATCH 3/5] routing: no MaxNumPaths restriction on FindBlindedPaths --- routing/router.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/routing/router.go b/routing/router.go index 9eabe0b2ae..389425925a 100644 --- a/routing/router.go +++ b/routing/router.go @@ -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 From 415eddd6b32d2e3ae3a61f15953219749dc22c2f Mon Sep 17 00:00:00 2001 From: MPins Date: Fri, 13 Dec 2024 06:38:55 -0300 Subject: [PATCH 4/5] routing: modify the TestFindBlindedPathsWithMC to not use MaxNumPaths MaxNumPaths restriction moved from FindBlindedPaths to BuildBlindedPaymentPaths this way we can interact through all possibly routes when creating a new blinded path. --- routing/router_test.go | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/routing/router_test.go b/routing/router_test.go index 2923f1fb90..190c318a03 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -3167,7 +3167,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) { dave, 1000, probabilitySrc, &BlindedPathRestrictions{ MinDistanceFromIntroNode: 2, NumHops: 2, - MaxNumPaths: 3, }, ) require.NoError(t, err) @@ -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 @@ -3212,7 +3210,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) { dave, 1000, probabilitySrc, &BlindedPathRestrictions{ MinDistanceFromIntroNode: 2, NumHops: 2, - MaxNumPaths: 3, }, ) require.NoError(t, err) @@ -3229,7 +3226,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) { dave, 1000, probabilitySrc, &BlindedPathRestrictions{ MinDistanceFromIntroNode: 2, NumHops: 2, - MaxNumPaths: 3, }, ) require.NoError(t, err) @@ -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{ - "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) @@ -3274,7 +3255,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) { dave, 1000, probabilitySrc, &BlindedPathRestrictions{ MinDistanceFromIntroNode: 2, NumHops: 2, - MaxNumPaths: 3, }, ) require.NoError(t, err) @@ -3289,7 +3269,6 @@ func TestFindBlindedPathsWithMC(t *testing.T) { dave, 1000, probabilitySrc, &BlindedPathRestrictions{ MinDistanceFromIntroNode: 2, NumHops: 2, - MaxNumPaths: 3, NodeOmissionSet: fn.NewSet(frank), }, ) From cfa17cb4d6bc7fed4bf9022c068887a365812b95 Mon Sep 17 00:00:00 2001 From: MPins Date: Thu, 5 Dec 2024 11:35:45 -0300 Subject: [PATCH 5/5] lnd: added MaxNumPaths on blindedPathCfg to be used on AddInvoice --- rpcserver.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rpcserver.go b/rpcserver.go index d7d2e0186c..4d6a6612e2 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6168,6 +6168,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context, MaxHTLCMsat: 0, }, MinNumPathHops: blindingRestrictions.NumHops, + MaxNumPaths: blindingRestrictions.MaxNumPaths, } }