diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 4ba96097..d3ecf843 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -226,6 +226,7 @@ func (m *missionControl) NewPaymentSession(routeHints [][]zpay32.HopHint, bandwidthHints: bandwidthHints, errFailedPolicyChans: make(map[EdgeLocator]struct{}), mc: m, + pathFinder: findPath, }, nil } @@ -240,6 +241,7 @@ func (m *missionControl) NewPaymentSessionFromRoutes(routes []*Route) *paymentSe preBuiltRoutes: routes, errFailedPolicyChans: make(map[EdgeLocator]struct{}), mc: m, + pathFinder: findPath, } } diff --git a/routing/pathfind.go b/routing/pathfind.go index f7afa93d..30d2b0da 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -39,6 +39,11 @@ const ( RiskFactorBillionths = 15 ) +// pathFinder defines the interface of a path finding algorithm. +type pathFinder = func(g *graphParams, r *RestrictParams, + source, target Vertex, amt lnwire.MilliSatoshi) ( + []*channeldb.ChannelEdgePolicy, error) + // Hop represents an intermediate or final node of the route. This naming // is in line with the definition given in BOLT #4: Onion Routing Protocol. // The struct houses the channel along which this hop can be reached and diff --git a/routing/payment_session.go b/routing/payment_session.go index 20a5808a..9537bf45 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -33,6 +33,8 @@ type paymentSession struct { haveRoutes bool preBuiltRoutes []*Route + + pathFinder pathFinder } // ReportVertexFailure adds a vertex to the graph prune view after a client @@ -141,7 +143,7 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment, // Taking into account this prune view, we'll attempt to locate a path // to our destination, respecting the recommendations from // missionControl. - path, err := findPath( + path, err := p.pathFinder( &graphParams{ graph: p.mc.graph, additionalEdges: p.additionalEdges,