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