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:
Joost Jager
2020-03-17 11:32:07 +01:00
parent cb4cd49dc8
commit 47f9c1c3fd
9 changed files with 155 additions and 146 deletions

View File

@@ -26,9 +26,6 @@ type SessionSource struct {
// the available bandwidth of the link should be returned.
QueryBandwidth func(*channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi
// SelfNode is our own node.
SelfNode *channeldb.LightningNode
// MissionControl is a shared memory of sorts that executions of payment
// path finding use in order to remember which vertexes/edges were
// pruned from prior attempts. During payment execution, errors sent by
@@ -43,6 +40,21 @@ type SessionSource struct {
PathFindingConfig PathFindingConfig
}
// getRoutingGraph returns a routing graph and a clean-up function for
// pathfinding.
func (m *SessionSource) getRoutingGraph() (routingGraph, func(), error) {
routingTx, err := newDbRoutingTx(m.Graph)
if err != nil {
return nil, nil, err
}
return routingTx, func() {
err := routingTx.close()
if err != nil {
log.Errorf("Error closing db tx: %v", err)
}
}, nil
}
// NewPaymentSession creates a new payment session backed by the latest prune
// view from Mission Control. An optional set of routing hints can be provided
// in order to populate additional edges to explore when finding a path to the
@@ -69,9 +81,11 @@ func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
return &paymentSession{
additionalEdges: edges,
getBandwidthHints: getBandwidthHints,
sessionSource: m,
payment: p,
pathFinder: findPath,
getRoutingGraph: m.getRoutingGraph,
pathFindingConfig: m.PathFindingConfig,
missionControl: m.MissionControl,
}, nil
}
@@ -80,8 +94,7 @@ func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
// missioncontrol for resumed payment we don't want to make more attempts for.
func (m *SessionSource) NewPaymentSessionEmpty() PaymentSession {
return &paymentSession{
sessionSource: m,
empty: true,
empty: true,
}
}