diff --git a/routing/pathfind.go b/routing/pathfind.go index 0d1af9b9..176935f8 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -513,6 +513,15 @@ func findPath(g *graphParams, r *RestrictParams, // mapped to within `next`. next := make(map[Vertex]*channeldb.ChannelEdgePolicy) + ignoredEdges := r.IgnoredEdges + if ignoredEdges == nil { + ignoredEdges = make(map[EdgeLocator]struct{}) + } + ignoredNodes := r.IgnoredNodes + if ignoredNodes == nil { + ignoredNodes = make(map[Vertex]struct{}) + } + // processEdge is a helper closure that will be used to make sure edges // satisfy our specific requirements. processEdge := func(fromNode *channeldb.LightningNode, @@ -544,12 +553,12 @@ func findPath(g *graphParams, r *RestrictParams, // If this vertex or edge has been black listed, then we'll // skip exploring this edge. - if _, ok := r.IgnoredNodes[fromVertex]; ok { + if _, ok := ignoredNodes[fromVertex]; ok { return } locator := newEdgeLocator(edge) - if _, ok := r.IgnoredEdges[*locator]; ok { + if _, ok := ignoredEdges[*locator]; ok { return } @@ -784,9 +793,6 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph, amt lnwire.MilliSatoshi, feeLimit lnwire.MilliSatoshi, numPaths uint32, bandwidthHints map[uint64]lnwire.MilliSatoshi) ([][]*channeldb.ChannelEdgePolicy, error) { - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - // TODO(roasbeef): modifying ordering within heap to eliminate final // sorting step? var ( @@ -804,9 +810,7 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph, bandwidthHints: bandwidthHints, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: feeLimit, + FeeLimit: feeLimit, }, source, target, amt, ) @@ -839,8 +843,8 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph, // we'll exclude from the next path finding attempt. // These are required to ensure the paths are unique // and loopless. - ignoredEdges = make(map[EdgeLocator]struct{}) - ignoredVertexes = make(map[Vertex]struct{}) + ignoredEdges := make(map[EdgeLocator]struct{}) + ignoredVertexes := make(map[Vertex]struct{}) // Our spur node is the i-th node in the prior shortest // path, and our root path will be all nodes in the diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index b6479f2b..a4f759f0 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -598,9 +598,6 @@ func TestFindLowestFeePath(t *testing.T) { } sourceVertex := Vertex(sourceNode.PubKeyBytes) - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - const ( startingHeight = 100 finalHopCLTV = 1 @@ -613,9 +610,7 @@ func TestFindLowestFeePath(t *testing.T) { graph: testGraphInstance.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, paymentAmt, ) @@ -744,9 +739,6 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc } sourceVertex := Vertex(sourceNode.PubKeyBytes) - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - const ( startingHeight = 100 finalHopCLTV = 1 @@ -759,9 +751,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc graph: graphInstance.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: test.feeLimit, + FeeLimit: test.feeLimit, }, sourceNode, target, paymentAmt, ) @@ -1224,9 +1214,6 @@ func TestNewRoutePathTooLong(t *testing.T) { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - paymentAmt := lnwire.NewMSatFromSatoshis(100) // We start by confirming that routing a payment 20 hops away is @@ -1237,9 +1224,7 @@ func TestNewRoutePathTooLong(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, paymentAmt, ) @@ -1255,9 +1240,7 @@ func TestNewRoutePathTooLong(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, paymentAmt, ) @@ -1283,9 +1266,6 @@ func TestPathNotAvailable(t *testing.T) { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - // With the test graph loaded, we'll test that queries for target that // are either unreachable within the graph, or unknown result in an // error. @@ -1304,9 +1284,7 @@ func TestPathNotAvailable(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, unknownNode, 100, ) @@ -1328,8 +1306,6 @@ func TestPathInsufficientCapacity(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) // Next, test that attempting to find a path in which the current // channel graph cannot support due to insufficient capacity triggers @@ -1347,9 +1323,7 @@ func TestPathInsufficientCapacity(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1373,8 +1347,6 @@ func TestRouteFailMinHTLC(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) // We'll not attempt to route an HTLC of 10 SAT from roasbeef to Son // Goku. However, the min HTLC of Son Goku is 1k SAT, as a result, this @@ -1386,9 +1358,7 @@ func TestRouteFailMinHTLC(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1438,8 +1408,6 @@ func TestRouteFailMaxHTLC(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) // First, attempt to send a payment greater than the max HTLC we are // about to set, which should succeed. @@ -1450,9 +1418,7 @@ func TestRouteFailMaxHTLC(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1476,9 +1442,7 @@ func TestRouteFailMaxHTLC(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1505,8 +1469,6 @@ func TestRouteFailDisabledEdge(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) // First, we'll try to route from roasbeef -> sophon. This should // succeed without issue, and return a single path via phamnuwen @@ -1517,9 +1479,7 @@ func TestRouteFailDisabledEdge(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1549,9 +1509,7 @@ func TestRouteFailDisabledEdge(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1578,9 +1536,7 @@ func TestRouteFailDisabledEdge(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1605,8 +1561,6 @@ func TestPathSourceEdgesBandwidth(t *testing.T) { if err != nil { t.Fatalf("unable to fetch source node: %v", err) } - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) // First, we'll try to route from roasbeef -> sophon. This should // succeed without issue, and return a path via songoku, as that's the @@ -1618,9 +1572,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) { graph: graph.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1646,9 +1598,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) { bandwidthHints: bandwidths, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1668,9 +1618,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) { bandwidthHints: bandwidths, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -1703,9 +1651,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) { bandwidthHints: bandwidths, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, payAmt, ) @@ -2022,9 +1968,6 @@ func TestRestrictOutgoingChannel(t *testing.T) { } sourceVertex := Vertex(sourceNode.PubKeyBytes) - ignoredEdges := make(map[EdgeLocator]struct{}) - ignoredVertexes := make(map[Vertex]struct{}) - const ( startingHeight = 100 finalHopCLTV = 1 @@ -2041,8 +1984,6 @@ func TestRestrictOutgoingChannel(t *testing.T) { graph: testGraphInstance.graph, }, &RestrictParams{ - IgnoredNodes: ignoredVertexes, - IgnoredEdges: ignoredEdges, FeeLimit: noFeeLimit, OutgoingChannelID: &outgoingChannelID, }, diff --git a/routing/router_test.go b/routing/router_test.go index 3514be2f..9c07d668 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -1949,9 +1949,6 @@ func TestFindPathFeeWeighting(t *testing.T) { t.Fatalf("unable to fetch source node: %v", err) } - ignoreVertex := make(map[Vertex]struct{}) - ignoreEdge := make(map[EdgeLocator]struct{}) - amt := lnwire.MilliSatoshi(100) target := ctx.aliases["luoji"] @@ -1967,9 +1964,7 @@ func TestFindPathFeeWeighting(t *testing.T) { graph: ctx.graph, }, &RestrictParams{ - IgnoredNodes: ignoreVertex, - IgnoredEdges: ignoreEdge, - FeeLimit: noFeeLimit, + FeeLimit: noFeeLimit, }, sourceNode, target, amt, )