From 67f17b319ad931a7d986485108a8f3bceec612d1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 2 Aug 2017 21:06:57 -0700 Subject: [PATCH] routing: invalidate routing cache on each new block This commit makes the routing cache invalidation a bit more aggressive. We now invalidate the cache on each new block as the routes in the cache are based on the current block height. Using the cached items may cause our routes to fail due to them having time locks which have already expired. --- routing/router.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/routing/router.go b/routing/router.go index e830edaa0..72b873b91 100644 --- a/routing/router.go +++ b/routing/router.go @@ -465,17 +465,22 @@ func (r *ChannelRouter) networkHandler() { log.Infof("Block %v (height=%v) closed %v channels", chainUpdate.Hash, blockHeight, len(chansClosed)) - if len(chansClosed) == 0 { - continue - } - - // Invalidate the route cache as channels within the - // graph have closed, which may affect our choice of - // the KSP's for a particular routeTuple. + // Invalidate the route cache as the block height has + // changed which will invalidate the HTLC timeouts we + // have crafted within each of the pre-computed routes. + // + // TODO(roasbeef): need to invalidate after each + // chan ann update? + // * can have map of chanID to routes involved, avoids + // full invalidation r.routeCacheMtx.Lock() r.routeCache = make(map[routeTuple][]*Route) r.routeCacheMtx.Unlock() + if len(chansClosed) == 0 { + continue + } + // Notify all currently registered clients of the newly // closed channels. closeSummaries := createCloseSummaries(blockHeight, chansClosed...)