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

Function new_chan

gossipd/routing.c:575–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575struct chan *new_chan(struct routing_state *rstate,
576 const struct short_channel_id *scid,
577 const struct node_id *id1,
578 const struct node_id *id2,
579 struct amount_sat satoshis)
580{
581 struct chan *chan = tal(rstate, struct chan);
582 int n1idx = node_id_idx(id1, id2);
583 struct node *n1, *n2;
584
585#if DEVELOPER
586 tal_add_destructor(chan, destroy_chan_check);
587#endif
588 /* We should never add a channel twice */
589 assert(!uintmap_get(&rstate->chanmap, scid->u64));
590
591 /* Create nodes on demand */
592 n1 = get_node(rstate, id1);
593 if (!n1)
594 n1 = new_node(rstate, id1);
595 n2 = get_node(rstate, id2);
596 if (!n2)
597 n2 = new_node(rstate, id2);
598
599 chan->scid = *scid;
600 chan->nodes[n1idx] = n1;
601 chan->nodes[!n1idx] = n2;
602 broadcastable_init(&chan->bcast);
603 /* This is how we indicate it's not public yet. */
604 chan->bcast.timestamp = 0;
605 chan->sat = satoshis;
606
607 add_chan(n2, chan);
608 add_chan(n1, chan);
609
610 /* Populate with (inactive) connections */
611 init_half_chan(rstate, chan, n1idx);
612 init_half_chan(rstate, chan, !n1idx);
613
614 uintmap_add(&rstate->chanmap, scid->u64, chan);
615
616 return chan;
617}
618
619/* Checks that key is valid, and signed this hash */
620static bool check_signed_hash_nodeid(const struct sha256_double *hash,

Callers 2

Calls 6

node_id_idxFunction · 0.85
broadcastable_initFunction · 0.85
add_chanFunction · 0.85
init_half_chanFunction · 0.85
get_nodeFunction · 0.70
new_nodeFunction · 0.70

Tested by

no test coverage detected