mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-26 21:46:37 +02:00
multi: add node omission list for blinded paths
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/feature"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -1150,6 +1151,10 @@ type blindedPathRestrictions struct {
|
||||
// path. This doesn't include our node, so if the maximum is 1, then
|
||||
// the path will contain our node along with an introduction node hop.
|
||||
maxNumHops uint8
|
||||
|
||||
// nodeOmissionSet holds a set of node IDs of nodes that we should
|
||||
// ignore during blinded path selection.
|
||||
nodeOmissionSet fn.Set[route.Vertex]
|
||||
}
|
||||
|
||||
// blindedHop holds the information about a hop we have selected for a blinded
|
||||
@@ -1253,6 +1258,12 @@ func processNodeForBlindedPath(g Graph, node route.Vertex,
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
// If we have explicitly been told to ignore this node for blinded paths
|
||||
// then we skip it too.
|
||||
if restrictions.nodeOmissionSet.Contains(node) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
supports, err := supportsRouteBlinding(node)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
|
@@ -3705,7 +3705,26 @@ func TestFindBlindedPaths(t *testing.T) {
|
||||
"charlie,eve,bob,dave",
|
||||
})
|
||||
|
||||
// 4) Finally, we will test the special case where the destination node
|
||||
// 4) Repeat the above test but instruct the function to never use
|
||||
// charlie.
|
||||
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
|
||||
minNumHops: 2,
|
||||
maxNumHops: 3,
|
||||
nodeOmissionSet: fn.NewSet[route.Vertex](
|
||||
ctx.keyFromAlias("charlie"),
|
||||
),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// We expect the following paths:
|
||||
// - F, B, D
|
||||
// - E, B, D
|
||||
assertPaths(paths, []string{
|
||||
"frank,bob,dave",
|
||||
"eve,bob,dave",
|
||||
})
|
||||
|
||||
// 5) Finally, we will test the special case where the destination node
|
||||
// is also the recipient.
|
||||
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
|
||||
minNumHops: 0,
|
||||
|
@@ -664,6 +664,10 @@ type BlindedPathRestrictions struct {
|
||||
|
||||
// MaxNumPaths is the maximum number of blinded paths to select.
|
||||
MaxNumPaths uint8
|
||||
|
||||
// NodeOmissionSet is a set of nodes that should not be used within any
|
||||
// of the blinded paths that we generate.
|
||||
NodeOmissionSet fn.Set[route.Vertex]
|
||||
}
|
||||
|
||||
// FindBlindedPaths finds a selection of paths to the destination node that can
|
||||
@@ -676,8 +680,9 @@ func (r *ChannelRouter) FindBlindedPaths(destination route.Vertex,
|
||||
// path length restrictions.
|
||||
paths, err := findBlindedPaths(
|
||||
r.cfg.RoutingGraph, destination, &blindedPathRestrictions{
|
||||
minNumHops: restrictions.MinDistanceFromIntroNode,
|
||||
maxNumHops: restrictions.NumHops,
|
||||
minNumHops: restrictions.MinDistanceFromIntroNode,
|
||||
maxNumHops: restrictions.NumHops,
|
||||
nodeOmissionSet: restrictions.NodeOmissionSet,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
@@ -3236,4 +3236,19 @@ func TestFindBlindedPathsWithMC(t *testing.T) {
|
||||
"alice,bob,dave",
|
||||
"alice,frank,dave",
|
||||
})
|
||||
|
||||
// Test that if the user explicitly indicates that we should ignore
|
||||
// the Frank node during path selection, then this is done.
|
||||
routes, err = ctx.router.FindBlindedPaths(
|
||||
dave, 1000, probabilitySrc, &BlindedPathRestrictions{
|
||||
MinDistanceFromIntroNode: 2,
|
||||
NumHops: 2,
|
||||
MaxNumPaths: 3,
|
||||
NodeOmissionSet: fn.NewSet(frank),
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assertPaths(routes, []string{
|
||||
"alice,bob,dave",
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user