Skip to content

Commit

Permalink
routing: add the option to set the income channel on blinded path
Browse files Browse the repository at this point in the history
It was made general enough to specify chained channels hops.
  • Loading branch information
MPins committed Oct 21, 2024
1 parent 5db01ae commit 41e336d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions routing/pathfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,10 @@ type blindedPathRestrictions struct {
// nodeOmissionSet holds a set of node IDs of nodes that we should
// ignore during blinded path selection.
nodeOmissionSet fn.Set[route.Vertex]

// channelIncomeSet holds a chained channels that we
// should use as income hops during blinded path selection.
channelIncomeSet []uint64
}

// blindedHop holds the information about a hop we have selected for a blinded
Expand Down Expand Up @@ -1300,6 +1304,16 @@ func processNodeForBlindedPath(g Graph, node route.Vertex,
// node that can be used for blinded paths
err = g.ForEachNodeChannel(node,
func(channel *channeldb.DirectedChannel) error {
// If this channel was included into the chained
// channel route.
chanInSet := restrictions.channelIncomeSet
chanIx := len(alreadyVisited)
if chanIx < len(chanInSet) {
if chanInSet[chanIx] != channel.ChannelID {
return nil
}
}

// Keep track of how many incoming channels this node
// has. We only use a node as an introduction node if it
// has channels other than the one that lead us to it.
Expand Down
11 changes: 8 additions & 3 deletions routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ type BlindedPathRestrictions struct {
// 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]

// channelIncomeSet holds a chained channels route that we
// should use as income hops during blinded path selection.
ChannelIncomeSet []uint64
}

// FindBlindedPaths finds a selection of paths to the destination node that can
Expand All @@ -624,9 +628,10 @@ func (r *ChannelRouter) FindBlindedPaths(destination route.Vertex,
// path length restrictions.
paths, err := findBlindedPaths(
r.cfg.RoutingGraph, destination, &blindedPathRestrictions{
minNumHops: restrictions.MinDistanceFromIntroNode,
maxNumHops: restrictions.NumHops,
nodeOmissionSet: restrictions.NodeOmissionSet,
minNumHops: restrictions.MinDistanceFromIntroNode,
maxNumHops: restrictions.NumHops,
nodeOmissionSet: restrictions.NodeOmissionSet,
channelIncomeSet: restrictions.ChannelIncomeSet,
},
)
if err != nil {
Expand Down

0 comments on commit 41e336d

Please sign in to comment.