Every half a week we look for dead channels (faster in dev) */
| 407 | |
| 408 | /* Every half a week we look for dead channels (faster in dev) */ |
| 409 | static void prune_network(struct gossmap_manage *gm) |
| 410 | { |
| 411 | u64 now = clock_time().ts.tv_sec; |
| 412 | /* Anything below this highwater mark ought to be pruned */ |
| 413 | const s64 highwater = now - GOSSIP_PRUNE_INTERVAL(gm->daemon->dev_fast_gossip_prune); |
| 414 | const struct gossmap_node *me; |
| 415 | struct gossmap *gossmap; |
| 416 | |
| 417 | /* We reload this every time we delete a channel: that way we can tell if it's |
| 418 | * time to remove a node! */ |
| 419 | gossmap = gossmap_manage_get_gossmap(gm); |
| 420 | me = gossmap_find_node(gossmap, &gm->daemon->id); |
| 421 | |
| 422 | /* Now iterate through all channels and see if it is still alive */ |
| 423 | for (size_t i = 0; i < gossmap_max_chan_idx(gossmap); i++) { |
| 424 | struct gossmap_chan *chan = gossmap_chan_byidx(gossmap, i); |
| 425 | u32 timestamp[2]; |
| 426 | struct short_channel_id scid; |
| 427 | |
| 428 | if (!chan) |
| 429 | continue; |
| 430 | |
| 431 | /* BOLT #7: |
| 432 | * - if the `timestamp` of the latest `channel_update` in |
| 433 | * either direction is older than two weeks (1209600 seconds): |
| 434 | * - MAY prune the channel. |
| 435 | */ |
| 436 | /* This is a fancy way of saying "both ends must refresh!" */ |
| 437 | timestamp[0] = get_timestamp(gossmap, chan, 0); |
| 438 | timestamp[1] = get_timestamp(gossmap, chan, 1); |
| 439 | |
| 440 | if (timestamp[0] >= highwater && timestamp[1] >= highwater) |
| 441 | continue; |
| 442 | |
| 443 | scid = gossmap_chan_scid(gossmap, chan); |
| 444 | |
| 445 | /* If it's dying anyway, don't bother pruning. */ |
| 446 | if (channel_already_dying(gm->dying_channels, scid)) |
| 447 | continue; |
| 448 | |
| 449 | /* Is it one of mine? */ |
| 450 | if (gossmap_nth_node(gossmap, chan, 0) == me |
| 451 | || gossmap_nth_node(gossmap, chan, 1) == me) { |
| 452 | int local = (gossmap_nth_node(gossmap, chan, 1) == me); |
| 453 | status_unusual("Pruning local channel %s from gossip_store: local channel_update time %u, remote %u", |
| 454 | fmt_short_channel_id(tmpctx, scid), |
| 455 | timestamp[local], timestamp[!local]); |
| 456 | } |
| 457 | |
| 458 | status_debug("Pruning channel %s from network view (ages %u and %u)", |
| 459 | fmt_short_channel_id(tmpctx, scid), |
| 460 | timestamp[0], timestamp[1]); |
| 461 | |
| 462 | remove_channel(gm, gossmap, chan, scid); |
| 463 | |
| 464 | gossmap = gossmap_manage_get_gossmap(gm); |
| 465 | me = gossmap_find_node(gossmap, &gm->daemon->id); |
| 466 | } |
nothing calls this directly
no test coverage detected