From 6ba1144528c337bd4bf715d40c3e030b8f73a756 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 24 Oct 2018 09:59:38 +0200 Subject: [PATCH] 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. --- routing/missioncontrol.go | 24 ++++++++++++++++-------- routing/router.go | 12 +++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index b722b942f..115f1cbed 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -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, } } diff --git a/routing/router.go b/routing/router.go index 0d3cdc288..508e1aa33 100644 --- a/routing/router.go +++ b/routing/router.go @@ -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