From d31efddf1bd6e689a1b502aad045de5a6f49d50a Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 24 Jun 2019 09:08:04 +0200 Subject: [PATCH] routing: move generateBandwidthHints --- routing/missioncontrol.go | 34 ---------------------------------- routing/router.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 69a34b65..364a0e3a 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -133,40 +133,6 @@ func NewMissionControl(cfg *MissionControlConfig) *MissionControl { } } -// generateBandwidthHints is a helper function that's utilized the main -// findPath function in order to obtain hints from the lower layer w.r.t to the -// available bandwidth of edges on the network. Currently, we'll only obtain -// bandwidth hints for the edges we directly have open ourselves. Obtaining -// these hints allows us to reduce the number of extraneous attempts as we can -// skip channels that are inactive, or just don't have enough bandwidth to -// carry the payment. -func generateBandwidthHints(sourceNode *channeldb.LightningNode, - queryBandwidth func(*channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi) (map[uint64]lnwire.MilliSatoshi, error) { - - // First, we'll collect the set of outbound edges from the target - // source node. - var localChans []*channeldb.ChannelEdgeInfo - err := sourceNode.ForEachChannel(nil, func(tx *bbolt.Tx, - edgeInfo *channeldb.ChannelEdgeInfo, - _, _ *channeldb.ChannelEdgePolicy) error { - - localChans = append(localChans, edgeInfo) - return nil - }) - if err != nil { - return nil, err - } - - // Now that we have all of our outbound edges, we'll populate the set - // of bandwidth hints, querying the lower switch layer for the most up - // to date values. - bandwidthHints := make(map[uint64]lnwire.MilliSatoshi) - for _, localChan := range localChans { - bandwidthHints[localChan.ChannelID] = queryBandwidth(localChan) - } - - return bandwidthHints, nil -} // ResetHistory resets the history of MissionControl returning it to a state as // if no payment attempts have been made. diff --git a/routing/router.go b/routing/router.go index 80cf4753..d84d5875 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2430,3 +2430,38 @@ func (r *ChannelRouter) IsStaleEdgePolicy(chanID lnwire.ShortChannelID, func (r *ChannelRouter) MarkEdgeLive(chanID lnwire.ShortChannelID) error { return r.cfg.Graph.MarkEdgeLive(chanID.ToUint64()) } + +// generateBandwidthHints is a helper function that's utilized the main +// findPath function in order to obtain hints from the lower layer w.r.t to the +// available bandwidth of edges on the network. Currently, we'll only obtain +// bandwidth hints for the edges we directly have open ourselves. Obtaining +// these hints allows us to reduce the number of extraneous attempts as we can +// skip channels that are inactive, or just don't have enough bandwidth to +// carry the payment. +func generateBandwidthHints(sourceNode *channeldb.LightningNode, + queryBandwidth func(*channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi) (map[uint64]lnwire.MilliSatoshi, error) { + + // First, we'll collect the set of outbound edges from the target + // source node. + var localChans []*channeldb.ChannelEdgeInfo + err := sourceNode.ForEachChannel(nil, func(tx *bbolt.Tx, + edgeInfo *channeldb.ChannelEdgeInfo, + _, _ *channeldb.ChannelEdgePolicy) error { + + localChans = append(localChans, edgeInfo) + return nil + }) + if err != nil { + return nil, err + } + + // Now that we have all of our outbound edges, we'll populate the set + // of bandwidth hints, querying the lower switch layer for the most up + // to date values. + bandwidthHints := make(map[uint64]lnwire.MilliSatoshi) + for _, localChan := range localChans { + bandwidthHints[localChan.ChannelID] = queryBandwidth(localChan) + } + + return bandwidthHints, nil +}