mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-04 18:01:57 +01:00
routing: use routingGraph interface in payment session
Preparation for more test coverage of payment session. The function findPath now has the call signature of the former findPathInternal function.
This commit is contained in:
@@ -811,10 +811,8 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
|
||||
|
||||
paymentAmt := lnwire.NewMSatFromSatoshis(test.paymentAmt)
|
||||
target := graphInstance.aliasMap[test.target]
|
||||
path, err := findPath(
|
||||
&graphParams{
|
||||
graph: graphInstance.graph,
|
||||
},
|
||||
path, err := dbFindPath(
|
||||
graphInstance.graph, nil, nil,
|
||||
&RestrictParams{
|
||||
FeeLimit: test.feeLimit,
|
||||
ProbabilitySource: noProbabilitySource,
|
||||
@@ -1005,11 +1003,8 @@ func TestPathFindingWithAdditionalEdges(t *testing.T) {
|
||||
find := func(r *RestrictParams) (
|
||||
[]*channeldb.ChannelEdgePolicy, error) {
|
||||
|
||||
return findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
additionalEdges: additionalEdges,
|
||||
},
|
||||
return dbFindPath(
|
||||
graph.graph, additionalEdges, nil,
|
||||
r, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, doge.PubKeyBytes, paymentAmt,
|
||||
0,
|
||||
@@ -1433,10 +1428,8 @@ func TestPathNotAvailable(t *testing.T) {
|
||||
var unknownNode route.Vertex
|
||||
copy(unknownNode[:], unknownNodeBytes)
|
||||
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, unknownNode, 100, 0,
|
||||
)
|
||||
@@ -1482,7 +1475,7 @@ func TestDestTLVGraphFallback(t *testing.T) {
|
||||
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
||||
defer ctx.cleanup()
|
||||
|
||||
sourceNode, err := ctx.graphParams.graph.SourceNode()
|
||||
sourceNode, err := ctx.graph.SourceNode()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fetch source node: %v", err)
|
||||
|
||||
@@ -1491,10 +1484,8 @@ func TestDestTLVGraphFallback(t *testing.T) {
|
||||
find := func(r *RestrictParams,
|
||||
target route.Vertex) ([]*channeldb.ChannelEdgePolicy, error) {
|
||||
|
||||
return findPath(
|
||||
&graphParams{
|
||||
graph: ctx.graphParams.graph,
|
||||
},
|
||||
return dbFindPath(
|
||||
ctx.graph, nil, nil,
|
||||
r, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, 100, 0,
|
||||
)
|
||||
@@ -1765,10 +1756,8 @@ func TestPathInsufficientCapacity(t *testing.T) {
|
||||
target := graph.aliasMap["sophon"]
|
||||
|
||||
payAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -1798,10 +1787,8 @@ func TestRouteFailMinHTLC(t *testing.T) {
|
||||
// attempt should fail.
|
||||
target := graph.aliasMap["songoku"]
|
||||
payAmt := lnwire.MilliSatoshi(10)
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -1897,10 +1884,8 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
||||
// succeed without issue, and return a single path via phamnuwen
|
||||
target := graph.aliasMap["sophon"]
|
||||
payAmt := lnwire.NewMSatFromSatoshis(105000)
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -1925,10 +1910,8 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
||||
t.Fatalf("unable to update edge: %v", err)
|
||||
}
|
||||
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -1950,10 +1933,8 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
||||
|
||||
// If we attempt to route through that edge, we should get a failure as
|
||||
// it is no longer eligible.
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -1984,10 +1965,8 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
||||
// cheapest path.
|
||||
target := graph.aliasMap["sophon"]
|
||||
payAmt := lnwire.NewMSatFromSatoshis(50000)
|
||||
path, err := findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
},
|
||||
path, err := dbFindPath(
|
||||
graph.graph, nil, nil,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -2007,11 +1986,8 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
||||
|
||||
// Since both these edges has a bandwidth of zero, no path should be
|
||||
// found.
|
||||
_, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
bandwidthHints: bandwidths,
|
||||
},
|
||||
_, err = dbFindPath(
|
||||
graph.graph, nil, bandwidths,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -2025,11 +2001,8 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
||||
|
||||
// Now, if we attempt to route again, we should find the path via
|
||||
// phamnuven, as the other source edge won't be considered.
|
||||
path, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
bandwidthHints: bandwidths,
|
||||
},
|
||||
path, err = dbFindPath(
|
||||
graph.graph, nil, bandwidths,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -2056,11 +2029,8 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
||||
|
||||
// Since we ignore disable flags for local channels, a path should
|
||||
// still be found.
|
||||
path, err = findPath(
|
||||
&graphParams{
|
||||
graph: graph.graph,
|
||||
bandwidthHints: bandwidths,
|
||||
},
|
||||
path, err = dbFindPath(
|
||||
graph.graph, nil, bandwidths,
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt, 0,
|
||||
)
|
||||
@@ -2811,7 +2781,7 @@ func TestRouteToSelf(t *testing.T) {
|
||||
|
||||
type pathFindingTestContext struct {
|
||||
t *testing.T
|
||||
graphParams graphParams
|
||||
graph *channeldb.ChannelGraph
|
||||
restrictParams RestrictParams
|
||||
pathFindingConfig PathFindingConfig
|
||||
testGraphInstance *testGraphInstance
|
||||
@@ -2838,10 +2808,8 @@ func newPathFindingTestContext(t *testing.T, testChannels []*testChannel,
|
||||
testGraphInstance: testGraphInstance,
|
||||
source: route.Vertex(sourceNode.PubKeyBytes),
|
||||
pathFindingConfig: *testPathFindingConfig,
|
||||
graphParams: graphParams{
|
||||
graph: testGraphInstance.graph,
|
||||
},
|
||||
restrictParams: *noRestrictions,
|
||||
graph: testGraphInstance.graph,
|
||||
restrictParams: *noRestrictions,
|
||||
}
|
||||
|
||||
return ctx
|
||||
@@ -2868,8 +2836,8 @@ func (c *pathFindingTestContext) findPath(target route.Vertex,
|
||||
amt lnwire.MilliSatoshi) ([]*channeldb.ChannelEdgePolicy,
|
||||
error) {
|
||||
|
||||
return findPath(
|
||||
&c.graphParams, &c.restrictParams, &c.pathFindingConfig,
|
||||
return dbFindPath(
|
||||
c.graph, nil, nil, &c.restrictParams, &c.pathFindingConfig,
|
||||
c.source, target, amt, 0,
|
||||
)
|
||||
}
|
||||
@@ -2887,3 +2855,33 @@ func (c *pathFindingTestContext) assertPath(path []*channeldb.ChannelEdgePolicy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dbFindPath calls findPath after getting a db transaction from the database
|
||||
// graph.
|
||||
func dbFindPath(graph *channeldb.ChannelGraph,
|
||||
additionalEdges map[route.Vertex][]*channeldb.ChannelEdgePolicy,
|
||||
bandwidthHints map[uint64]lnwire.MilliSatoshi,
|
||||
r *RestrictParams, cfg *PathFindingConfig,
|
||||
source, target route.Vertex, amt lnwire.MilliSatoshi,
|
||||
finalHtlcExpiry int32) ([]*channeldb.ChannelEdgePolicy, error) {
|
||||
|
||||
routingTx, err := newDbRoutingTx(graph)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
err := routingTx.close()
|
||||
if err != nil {
|
||||
log.Errorf("Error closing db tx: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return findPath(
|
||||
&graphParams{
|
||||
additionalEdges: additionalEdges,
|
||||
bandwidthHints: bandwidthHints,
|
||||
graph: routingTx,
|
||||
},
|
||||
r, cfg, source, target, amt, finalHtlcExpiry,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user