From 1259bacd49350888b141b7c818fc7aebcf3c6e91 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 13 Feb 2019 12:13:55 +0100 Subject: [PATCH] routing: remove unused code, nodeIndex and chanIndex --- routing/pathfind.go | 34 ---------------------------------- routing/router.go | 39 --------------------------------------- 2 files changed, 73 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index a46d2437..21906b7c 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -154,15 +154,6 @@ type Route struct { // Hops contains details concerning the specific forwarding details at // each hop. Hops []*Hop - - // nodeIndex is a map that allows callers to quickly look up if a node - // is present in this computed route or not. - nodeIndex map[Vertex]struct{} - - // chanIndex is an index that allows callers to determine if a channel - // is present in this route or not. Channels are identified by the - // uint64 version of the short channel ID. - chanIndex map[uint64]struct{} } // HopFee returns the fee charged by the route hop indicated by hopIndex. @@ -178,21 +169,6 @@ func (r *Route) HopFee(hopIndex int) lnwire.MilliSatoshi { return incomingAmt - r.Hops[hopIndex].AmtToForward } -// containsNode returns true if a node is present in the target route, and -// false otherwise. -func (r *Route) containsNode(v Vertex) bool { - _, ok := r.nodeIndex[v] - return ok -} - -// containsChannel returns true if a channel is present in the target route, -// and false otherwise. The passed chanID should be the converted uint64 form -// of lnwire.ShortChannelID. -func (r *Route) containsChannel(chanID uint64) bool { - _, ok := r.chanIndex[chanID] - return ok -} - // ToHopPayloads converts a complete route into the series of per-hop payloads // that is to be encoded within each HTLC using an opaque Sphinx packet. func (r *Route) ToHopPayloads() []sphinx.HopData { @@ -365,16 +341,6 @@ func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32, TotalTimeLock: timeLock, TotalAmount: amtToSend, TotalFees: amtToSend - hops[len(hops)-1].AmtToForward, - nodeIndex: make(map[Vertex]struct{}), - chanIndex: make(map[uint64]struct{}), - } - - // Then we'll update the node and channel index, to indicate that this - // Vertex and incoming channel link are present within this route. - for _, hop := range hops { - v := Vertex(hop.PubKeyBytes) - route.nodeIndex[v] = struct{}{} - route.chanIndex[hop.ChannelID] = struct{}{} } return route, nil diff --git a/routing/router.go b/routing/router.go index 7ffe7727..c33f3ff1 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1283,45 +1283,6 @@ type routingMsg struct { err chan error } -// pruneNodeFromRoutes accepts set of routes, and returns a new set of routes -// with the target node filtered out. -func pruneNodeFromRoutes(routes []*Route, skipNode Vertex) []*Route { - - // TODO(roasbeef): pass in slice index? - - prunedRoutes := make([]*Route, 0, len(routes)) - for _, route := range routes { - if route.containsNode(skipNode) { - continue - } - - prunedRoutes = append(prunedRoutes, route) - } - - log.Tracef("Filtered out %v routes with node %x", - len(routes)-len(prunedRoutes), skipNode[:]) - - return prunedRoutes -} - -// pruneChannelFromRoutes accepts a set of routes, and returns a new set of -// routes with the target channel filtered out. -func pruneChannelFromRoutes(routes []*Route, skipChan uint64) []*Route { - prunedRoutes := make([]*Route, 0, len(routes)) - for _, route := range routes { - if route.containsChannel(skipChan) { - continue - } - - prunedRoutes = append(prunedRoutes, route) - } - - log.Tracef("Filtered out %v routes with channel %v", - len(routes)-len(prunedRoutes), skipChan) - - return prunedRoutes -} - // pathsToFeeSortedRoutes takes a set of paths, and returns a corresponding set // of routes. A route differs from a path in that it has full time-lock and // fee information attached. The set of routes returned may be less than the