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.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-02 21:06:57 -07:00
parent f61d977176
commit 67f17b319a
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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...)