MCPcopy Create free account
hub / github.com/ElementsProject/lightning / remove_chan_from_node

Function remove_chan_from_node

gossipd/routing.c:471–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471static void remove_chan_from_node(struct routing_state *rstate,
472 struct node *node, const struct chan *chan)
473{
474 size_t num_chans;
475
476 if (!node_uses_chan_map(node)) {
477 num_chans = 0;
478 for (size_t i = 0; i < NUM_IMMEDIATE_CHANS; i++) {
479 if (node->chans.arr[i] == chan)
480 node->chans.arr[i] = NULL;
481 else if (node->chans.arr[i] != NULL)
482 num_chans++;
483 }
484 } else {
485 if (!chan_map_del(&node->chans.map, chan))
486 abort();
487 num_chans = chan_map_count(&node->chans.map);
488 }
489
490 /* Last channel? Simply delete node (and associated announce) */
491 if (num_chans == 0) {
492 if(node->rgraph.index != node->bcast.index)
493 gossip_store_delete(rstate->gs,
494 &node->rgraph,
495 WIRE_NODE_ANNOUNCEMENT);
496 gossip_store_delete(rstate->gs,
497 &node->bcast,
498 WIRE_NODE_ANNOUNCEMENT);
499 tal_free(node);
500 return;
501 }
502
503 if (!node->bcast.index)
504 return;
505
506 /* Removed only public channel? Remove node announcement. */
507 if (!node_has_broadcastable_channels(node)) {
508 if(node->rgraph.index != node->bcast.index)
509 gossip_store_delete(rstate->gs,
510 &node->rgraph,
511 WIRE_NODE_ANNOUNCEMENT);
512 gossip_store_delete(rstate->gs,
513 &node->bcast,
514 WIRE_NODE_ANNOUNCEMENT);
515 node->rgraph.index = node->bcast.index = 0;
516 node->rgraph.timestamp = node->bcast.timestamp = 0;
517 } else if (node_announce_predates_channels(node)) {
518 /* node announcement predates all channel announcements?
519 * Move to end (we could, in theory, move to just past next
520 * channel_announce, but we don't care that much about spurious
521 * retransmissions in this corner case */
522 force_node_announce_rexmit(rstate, node);
523 }
524}
525
526#if DEVELOPER
527/* We make sure that free_chan is called on this chan! */

Callers 1

free_chans_from_nodeFunction · 0.70

Calls 7

node_uses_chan_mapFunction · 0.85
abortFunction · 0.85
tal_freeFunction · 0.85
gossip_store_deleteFunction · 0.70

Tested by

no test coverage detected