routing: return cached route response in FindRoutes if enough routes

In this commit, we modify the caching structure to return a set of
cached routes for a request if the number of routes requested is less
than or equal to the number of cached of routes.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-12 16:22:22 -08:00
parent 8a29c01354
commit ad0f5b31f6
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 4 additions and 3 deletions

View File

@ -1255,9 +1255,10 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
routes, ok := r.routeCache[rt]
r.routeCacheMtx.RUnlock()
// If we already have a cached route, then we'll return it directly as
// there's no need to repeat the computation.
if ok {
// If we already have a cached route, and it contains at least the
// number of paths requested, then we'll return it directly as there's
// no need to repeat the computation.
if ok && uint32(len(routes)) >= numPaths {
return routes, nil
}