routing: add time_pref parameter to queryroutes and sendpayment

This commit is contained in:
Joost Jager committed 2022-04-13 20:26:46 +02:00
1 parent 269a8e74d3
commit ba5abdc090
17 files changed
+2034 -1918

No files matched your search

+38 -20
View File
@@ -1059,7 +1059,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
CltvLimit: math.MaxUint32,
},
testPathFindingConfig,
sourceNode.PubKeyBytes, target, paymentAmt,
sourceNode.PubKeyBytes, target, paymentAmt, 0,
startingHeight+finalHopCLTV,
)
if test.expectFailureNoPath {
@@ -1248,7 +1248,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
graph.graph, additionalEdges, &mockBandwidthHints{},
r, testPathFindingConfig,
sourceNode.PubKeyBytes, doge.PubKeyBytes, paymentAmt,
0,
0, 0,
)
}
@@ -1669,7 +1669,7 @@ func runPathNotAvailable(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, unknownNode, 100, 0,
sourceNode.PubKeyBytes, unknownNode, 100, 0, 0,
)
if err != errNoPathFound {
t.Fatalf("path shouldn't have been found: %v", err)
@@ -1722,7 +1722,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
return dbFindPath(
ctx.graph, nil, &mockBandwidthHints{},
r, testPathFindingConfig,
sourceNode.PubKeyBytes, target, 100, 0,
sourceNode.PubKeyBytes, target, 100, 0, 0,
)
}
@@ -1983,7 +1983,7 @@ func runPathInsufficientCapacity(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != errInsufficientBalance {
t.Fatalf("graph shouldn't be able to support payment: %v", err)
@@ -2012,7 +2012,7 @@ func runRouteFailMinHTLC(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != errNoPathFound {
t.Fatalf("graph shouldn't be able to support payment: %v", err)
@@ -2105,7 +2105,7 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
@@ -2131,7 +2131,7 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
@@ -2154,7 +2154,7 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != errNoPathFound {
t.Fatalf("graph shouldn't be able to support payment: %v", err)
@@ -2184,7 +2184,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
path, err := dbFindPath(
graph.graph, nil, &mockBandwidthHints{},
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
@@ -2207,7 +2207,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
_, err = dbFindPath(
graph.graph, nil, bandwidths,
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != errNoPathFound {
t.Fatalf("graph shouldn't be able to support payment: %v", err)
@@ -2222,7 +2222,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
path, err = dbFindPath(
graph.graph, nil, bandwidths,
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
@@ -2250,7 +2250,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
path, err = dbFindPath(
graph.graph, nil, bandwidths,
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
@@ -2296,7 +2296,7 @@ func TestPathFindSpecExample(t *testing.T) {
carol := ctx.aliases["C"]
const amt lnwire.MilliSatoshi = 4999999
route, err := ctx.router.FindRoute(
bobNode.PubKeyBytes, carol, amt, noRestrictions, nil, nil,
bobNode.PubKeyBytes, carol, amt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
@@ -2352,7 +2352,7 @@ func TestPathFindSpecExample(t *testing.T) {
// We'll now request a route from A -> B -> C.
route, err = ctx.router.FindRoute(
source.PubKeyBytes, carol, amt, noRestrictions, nil, nil,
source.PubKeyBytes, carol, amt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
@@ -2686,6 +2686,7 @@ func runProbabilityRouting(t *testing.T, useCache bool) {
minProbability float64
expectedChan uint64
amount btcutil.Amount
timePref float64
}{
// Test two variations with probabilities that should multiply
// to the same total route probability. In both cases the three
@@ -2709,6 +2710,18 @@ func runProbabilityRouting(t *testing.T, useCache bool) {
amount: 100,
},
// If we increase the time preference, we expect the algorithm
// to choose - with everything else being equal - the more
// expensive, more reliable route.
{
name: "three hop timepref",
p10: 0.5, p11: 0.8, p20: 0.7,
minProbability: 0.1,
expectedChan: 20,
amount: 100,
timePref: 1,
},
// If a larger amount is sent, the effect of the proportional
// attempt cost becomes more noticeable. This amount in this
// test brings the attempt cost to 9 + 1% * 300 = 12 sat. The
@@ -2765,7 +2778,8 @@ func runProbabilityRouting(t *testing.T, useCache bool) {
t.Run(tc.name, func(t *testing.T) {
testProbabilityRouting(
t, useCache, tc.amount, tc.p10, tc.p11, tc.p20,
t, useCache, tc.amount, tc.timePref,
tc.p10, tc.p11, tc.p20,
tc.minProbability, tc.expectedChan,
)
})
@@ -2773,7 +2787,8 @@ func runProbabilityRouting(t *testing.T, useCache bool) {
}
func testProbabilityRouting(t *testing.T, useCache bool,
paymentAmt btcutil.Amount, p10, p11, p20, minProbability float64,
paymentAmt btcutil.Amount, timePref float64,
p10, p11, p20, minProbability float64,
expectedChan uint64) {
t.Parallel()
@@ -2834,6 +2849,8 @@ func testProbabilityRouting(t *testing.T, useCache bool,
MinProbability: minProbability,
}
ctx.timePref = timePref
path, err := ctx.findPath(
target, lnwire.NewMSatFromSatoshis(paymentAmt),
)
@@ -3044,6 +3061,7 @@ type pathFindingTestContext struct {
pathFindingConfig PathFindingConfig
testGraphInstance *testGraphInstance
source route.Vertex
timePref float64
}
func newPathFindingTestContext(t *testing.T, useCache bool,
@@ -3097,7 +3115,7 @@ func (c *pathFindingTestContext) findPath(target route.Vertex,
return dbFindPath(
c.graph, nil, c.bandwidthHints, &c.restrictParams,
&c.pathFindingConfig, c.source, target, amt, 0,
&c.pathFindingConfig, c.source, target, amt, c.timePref, 0,
)
}
@@ -3123,7 +3141,7 @@ func dbFindPath(graph *channeldb.ChannelGraph,
additionalEdges map[route.Vertex][]*channeldb.CachedEdgePolicy,
bandwidthHints bandwidthHints,
r *RestrictParams, cfg *PathFindingConfig,
source, target route.Vertex, amt lnwire.MilliSatoshi,
source, target route.Vertex, amt lnwire.MilliSatoshi, timePref float64,
finalHtlcExpiry int32) ([]*channeldb.CachedEdgePolicy, error) {
sourceNode, err := graph.SourceNode()
@@ -3148,6 +3166,6 @@ func dbFindPath(graph *channeldb.ChannelGraph,
bandwidthHints: bandwidthHints,
graph: routingGraph,
},
r, cfg, source, target, amt, finalHtlcExpiry,
r, cfg, source, target, amt, timePref, finalHtlcExpiry,
)
}