| 1902 | } |
| 1903 | |
| 1904 | void route_prune(struct routing_state *rstate) |
| 1905 | { |
| 1906 | u64 now = gossip_time_now(rstate).ts.tv_sec; |
| 1907 | /* Anything below this highwater mark ought to be pruned */ |
| 1908 | const s64 highwater = now - GOSSIP_PRUNE_INTERVAL(rstate->dev_fast_gossip_prune); |
| 1909 | struct chan **pruned = tal_arr(tmpctx, struct chan *, 0); |
| 1910 | u64 idx; |
| 1911 | |
| 1912 | /* Now iterate through all channels and see if it is still alive */ |
| 1913 | for (struct chan *chan = uintmap_first(&rstate->chanmap, &idx); |
| 1914 | chan; |
| 1915 | chan = uintmap_after(&rstate->chanmap, &idx)) { |
| 1916 | /* Local-only? Don't prune. */ |
| 1917 | if (!is_chan_public(chan)) |
| 1918 | continue; |
| 1919 | |
| 1920 | /* BOLT #7: |
| 1921 | * - if the `timestamp` of the latest `channel_update` in |
| 1922 | * either direction is older than two weeks (1209600 seconds): |
| 1923 | * - MAY prune the channel. |
| 1924 | */ |
| 1925 | /* This is a fancy way of saying "both ends must refresh!" */ |
| 1926 | if (!is_halfchan_defined(&chan->half[0]) |
| 1927 | || chan->half[0].bcast.timestamp < highwater |
| 1928 | || !is_halfchan_defined(&chan->half[1]) |
| 1929 | || chan->half[1].bcast.timestamp < highwater) { |
| 1930 | status_debug( |
| 1931 | "Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)", |
| 1932 | type_to_string(tmpctx, struct short_channel_id, |
| 1933 | &chan->scid), |
| 1934 | is_halfchan_defined(&chan->half[0]) |
| 1935 | ? now - chan->half[0].bcast.timestamp : 0, |
| 1936 | is_halfchan_defined(&chan->half[1]) |
| 1937 | ? now - chan->half[1].bcast.timestamp : 0); |
| 1938 | |
| 1939 | /* This may perturb iteration so do outside loop. */ |
| 1940 | tal_arr_expand(&pruned, chan); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | /* Look for channels we had an announcement for, but no update. */ |
| 1945 | for (struct unupdated_channel *uc |
| 1946 | = uintmap_first(&rstate->unupdated_chanmap, &idx); |
| 1947 | uc; |
| 1948 | uc = uintmap_after(&rstate->unupdated_chanmap, &idx)) { |
| 1949 | if (uc->added.ts.tv_sec < highwater) { |
| 1950 | tal_free(uc); |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | /* Now free all the chans and maybe even nodes. */ |
| 1955 | for (size_t i = 0; i < tal_count(pruned); i++) { |
| 1956 | remove_channel_from_store(rstate, pruned[i]); |
| 1957 | free_chan(rstate, pruned[i]); |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | bool routing_add_private_channel(struct routing_state *rstate, |
no test coverage detected