mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-29 23:47:13 +01:00
routing: replace sort.Sort with sort.Slice in router.go
Use sort.Slice in FindRoutes function in routing/router.go, as part of the move to use new language features. Remove sortableRoutes type wrapper for slice of Routes since it is no longer needed to sort routes.
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
8822bb11ce
commit
29687f49eb
@@ -869,7 +869,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
// each path. During this process, some paths may be discarded if they
|
||||
// aren't able to support the total satoshis flow once fees have been
|
||||
// factored in.
|
||||
validRoutes := make(sortableRoutes, 0, len(shortestPaths))
|
||||
validRoutes := make([]*Route, 0, len(shortestPaths))
|
||||
for _, path := range shortestPaths {
|
||||
// Attempt to make the path into a route. We snip off the first
|
||||
// hop in the path as it contains a "self-hop" that is inserted
|
||||
@@ -894,7 +894,19 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
// Finally, we'll sort the set of validate routes to optimize for
|
||||
// lowest total fees, using the required time-lock within the route as
|
||||
// a tie-breaker.
|
||||
sort.Sort(validRoutes)
|
||||
sort.Slice(validRoutes, func(i, j int) bool {
|
||||
// To make this decision we first check if the total fees
|
||||
// required for both routes are equal. If so, then we'll let the total time
|
||||
// lock be the tie breaker. Otherwise, we'll put the route with the lowest
|
||||
// total fees first.
|
||||
if validRoutes[i].TotalFees == validRoutes[j].TotalFees {
|
||||
timeLockI := validRoutes[i].TotalTimeLock
|
||||
timeLockJ := validRoutes[j].TotalTimeLock
|
||||
return timeLockI < timeLockJ
|
||||
}
|
||||
|
||||
return validRoutes[i].TotalFees < validRoutes[j].TotalFees
|
||||
})
|
||||
|
||||
log.Debugf("Obtained %v paths sending %v to %x: %v", len(validRoutes),
|
||||
amt, dest, newLogClosure(func() string {
|
||||
|
||||
Reference in New Issue
Block a user