routing: move failed channels map into payment session

This is a small preparatory step towards moving mission control logic
out of router and reusing the acquired routing result data.
This commit is contained in:
Joost Jager 2018-10-24 09:59:38 +02:00
parent ac04729cff
commit 6ba1144528
No known key found for this signature in database
GPG Key ID: AE6B0D042C8E38D9
2 changed files with 19 additions and 17 deletions

@ -164,6 +164,12 @@ type paymentSession struct {
bandwidthHints map[uint64]lnwire.MilliSatoshi
// errFailedFeeChans is a map of the short channel ID's that were the
// source of policy related routing failures during this payment attempt.
// We'll use this map to prune out channels when the first error may not
// require pruning, but any subsequent ones do.
errFailedPolicyChans map[uint64]struct{}
mc *missionControl
haveRoutes bool
@ -236,10 +242,11 @@ func (m *missionControl) NewPaymentSession(routeHints [][]HopHint,
}
return &paymentSession{
pruneViewSnapshot: viewSnapshot,
additionalEdges: edges,
bandwidthHints: bandwidthHints,
mc: m,
pruneViewSnapshot: viewSnapshot,
additionalEdges: edges,
bandwidthHints: bandwidthHints,
errFailedPolicyChans: make(map[uint64]struct{}),
mc: m,
}, nil
}
@ -249,10 +256,11 @@ func (m *missionControl) NewPaymentSession(routeHints [][]HopHint,
// used for things like channel rebalancing, and swaps.
func (m *missionControl) NewPaymentSessionFromRoutes(routes []*Route) *paymentSession {
return &paymentSession{
pruneViewSnapshot: m.GraphPruneView(),
haveRoutes: true,
preBuiltRoutes: routes,
mc: m,
pruneViewSnapshot: m.GraphPruneView(),
haveRoutes: true,
preBuiltRoutes: routes,
errFailedPolicyChans: make(map[uint64]struct{}),
mc: m,
}
}

@ -1641,12 +1641,6 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
sendError error
)
// errFailedFeeChans is a map of the short channel ID's that were the
// source of fee related routing failures during this payment attempt.
// We'll use this map to prune out channels when the first error may
// not require pruning, but any subsequent ones do.
errFailedFeeChans := make(map[lnwire.ShortChannelID]struct{})
// We'll also fetch the current block height so we can properly
// calculate the required HTLC time locks within the route.
_, currentHeight, err := r.cfg.Chain.GetBestBlock()
@ -1845,8 +1839,8 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
// reported a fee related failure for this
// node. If so, then we'll actually prune out
// the vertex for now.
chanID := update.ShortChannelID
_, ok := errFailedFeeChans[chanID]
chanID := update.ShortChannelID.ToUint64()
_, ok := paySession.errFailedPolicyChans[chanID]
if ok {
paySession.ReportVertexFailure(errVertex)
continue
@ -1854,7 +1848,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
// Finally, we'll record a fee failure from
// this node and move on.
errFailedFeeChans[chanID] = struct{}{}
paySession.errFailedPolicyChans[chanID] = struct{}{}
continue
// If we get the failure for an intermediate node that