routing: abstract path finding interface

This commit is contained in:
Joost Jager 2019-02-13 11:35:55 +01:00
parent 6006549ed5
commit e3bb3d46a2
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 10 additions and 1 deletions

View File

@ -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,
}
}

View File

@ -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

View File

@ -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,