To actually remove a channel: * - Suppress future lookups in case we receive another channel_update. * - Put deleted tombstone in gossip_store. * - Mark records deleted in gossip_store. * - See if node_announcement(s) need to be removed, marked dying, or moved. */
| 304 | * - See if node_announcement(s) need to be removed, marked dying, or moved. |
| 305 | */ |
| 306 | static void remove_channel(struct gossmap_manage *gm, |
| 307 | struct gossmap *gossmap, |
| 308 | struct gossmap_chan *chan, |
| 309 | struct short_channel_id scid) |
| 310 | { |
| 311 | /* Suppress any now-obsolete updates/announcements */ |
| 312 | txout_failures_add(gm->txf, scid); |
| 313 | |
| 314 | /* Cover race where we were looking up this UTXO as it was spent. */ |
| 315 | tal_free(map_del(&gm->pending_ann_map, scid)); |
| 316 | tal_free(map_del(&gm->early_ann_map, scid)); |
| 317 | |
| 318 | /* Put in tombstone marker. */ |
| 319 | gossip_store_add(gm->gs, |
| 320 | towire_gossip_store_delete_chan(tmpctx, scid), |
| 321 | 0); |
| 322 | |
| 323 | /* Delete from store */ |
| 324 | gossip_store_del(gm->gs, chan->cann_off, WIRE_CHANNEL_ANNOUNCEMENT); |
| 325 | for (int dir = 0; dir < 2; dir++) { |
| 326 | if (gossmap_chan_set(chan, dir)) |
| 327 | gossip_store_del(gm->gs, chan->cupdate_off[dir], WIRE_CHANNEL_UPDATE); |
| 328 | } |
| 329 | |
| 330 | /* Check for node_announcements which should no longer be there */ |
| 331 | for (int dir = 0; dir < 2; dir++) { |
| 332 | struct gossmap_node *node; |
| 333 | u64 offset; |
| 334 | |
| 335 | node = gossmap_nth_node(gossmap, chan, dir); |
| 336 | |
| 337 | /* Don't get confused if a node has a channel with self! */ |
| 338 | if (dir == 1 && node == gossmap_nth_node(gossmap, chan, 0)) |
| 339 | continue; |
| 340 | |
| 341 | /* If there was a node announcement, we might need to fix things up. */ |
| 342 | if (!gossmap_node_announced(node)) |
| 343 | continue; |
| 344 | |
| 345 | /* Last channel? Delete node announce */ |
| 346 | if (node->num_chans == 1) { |
| 347 | gossip_store_del(gm->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT); |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | /* Maybe this was the last channel_announcement which preceeded node_announcement? */ |
| 352 | if (chan->cann_off < node->nann_off |
| 353 | && !any_cannounce_preceeds_offset(gossmap, node, chan, node->nann_off)) { |
| 354 | const u8 *nannounce; |
| 355 | u32 timestamp; |
| 356 | |
| 357 | /* To maintain order, delete and re-add node_announcement */ |
| 358 | nannounce = gossmap_node_get_announce(tmpctx, gossmap, node); |
| 359 | timestamp = gossip_store_get_timestamp(gm->gs, node->nann_off); |
| 360 | |
| 361 | gossip_store_del(gm->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT); |
| 362 | offset = gossip_store_add(gm->gs, nannounce, timestamp); |
| 363 | } else { |
no test coverage detected