routing: abstract path finding behind mission control
In this commit, from the PoV of the SendPayment method we now delegate all path finding+verification to missionControl. This change doesn’t materially affect anything, it simply expands the abstraction to make way for future features that more heavily utilize mission control.
This commit is contained in:
2 files changed
+57
-25
No files matched your search
+7
-24
@@ -234,7 +234,7 @@ func New(cfg Config) (*ChannelRouter, error) {
|
||||
networkUpdates: make(chan *routingMsg),
|
||||
topologyClients: make(map[uint64]*topologyClient),
|
||||
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
||||
missionControl: newMissionControl(),
|
||||
missionControl: newMissionControl(cfg.Graph, selfNode),
|
||||
routeCache: make(map[routeTuple][]*Route),
|
||||
quit: make(chan struct{}),
|
||||
}, nil
|
||||
@@ -1189,19 +1189,13 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
||||
|
||||
// We'll continue until either our payment succeeds, or we encounter a
|
||||
// critical error during path finding.
|
||||
sourceVertex := newVertex(r.selfNode.PubKey)
|
||||
for {
|
||||
// First, we'll query mission control for it's current
|
||||
// recommendation on the edges/vertexes to ignore during path
|
||||
// finding.
|
||||
pruneView := r.missionControl.GraphPruneView()
|
||||
|
||||
// Taking into account this prune view, we'll attempt to locate
|
||||
// a path to our destination, respecting the recommendations
|
||||
// from missionControl.
|
||||
path, err := findPath(nil, r.cfg.Graph, r.selfNode,
|
||||
payment.Target, pruneView.vertexes, pruneView.edges,
|
||||
payment.Amount)
|
||||
// We'll kick things off by requesting a new route from mission
|
||||
// control, which will incoroporate the current best known
|
||||
// state of the channel graph and our past HTLC routing
|
||||
// successes/failures.
|
||||
route, err := r.missionControl.RequestRoute(payment,
|
||||
uint32(currentHeight))
|
||||
if err != nil {
|
||||
// If we're unable to successfully make a payment using
|
||||
// any of the routes we've found, then return an error.
|
||||
@@ -1214,17 +1208,6 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
||||
return preImage, nil, err
|
||||
}
|
||||
|
||||
// With the next candiate path found, we'll attempt to turn
|
||||
// this into a route by applying the time-lock and fee
|
||||
// requirements.
|
||||
route, err := newRoute(payment.Amount, sourceVertex, path,
|
||||
uint32(currentHeight))
|
||||
if err != nil {
|
||||
// TODO(roasbeef): return which edge/vertex didn't work
|
||||
// out
|
||||
return preImage, nil, err
|
||||
}
|
||||
|
||||
log.Tracef("Attempting to send payment %x, using route: %v",
|
||||
payment.PaymentHash, newLogClosure(func() string {
|
||||
return spew.Sdump(route)
|
||||
|
||||
Reference in new issue
Block a user