router: Optimize pruneZombieChannels.

The current approach iterates all channels in the graph in order to
filter those in need. This approach is time consuming, several seconds
on my mobile device for ~40,000 channels, while during this time the
db is locked in a transaction.

The proposed change is to use an existing functionality that utilize the
fact that channel update are saved indexed by date. This method enables
us to go over only a small subset of the channels, only those that
were updated before the "channel expiry" time and further filter
them for our need.
The same graph that took several seconds to prune was pruned, after
the change, in several milliseconds.

In addition for testing purposes I added Initiator field to the
testChannel structure to reflect the channeldEdgePolicy direction.
This commit is contained in:
Roei Erez
2019-07-10 15:20:42 +03:00
parent 7300f33fe2
commit 9781ea0082
3 changed files with 47 additions and 10 deletions

View File

@@ -1899,7 +1899,7 @@ func TestPruneChannelGraphStaleEdges(t *testing.T) {
t.Parallel()
freshTimestamp := time.Now()
staleTimestamp := time.Time{}
staleTimestamp := time.Unix(0, 0)
// We'll create the following test graph so that only the last channel
// is pruned.