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

Function add_channel

common/gossmap.c:418–470  ·  view source on GitHub ↗

BOLT #7: * 1. type: 256 (`channel_announcement`) * 2. data: * * [`signature`:`node_signature_1`] * * [`signature`:`node_signature_2`] * * [`signature`:`bitcoin_signature_1`] * * [`signature`:`bitcoin_signature_2`] * * [`u16`:`len`] * * [`len*byte`:`features`] * * [`chain_hash`:`chain_hash`] * * [`short_channel_id`:`short_channel_id`] * * [`point`:`nod

Source from the content-addressed store, hash-verified

416 * * [`point`:`node_id_2`]
417 */
418static struct gossmap_chan *add_channel(struct gossmap *map,
419 size_t cannounce_off,
420 bool private)
421{
422 /* Note that first two bytes are message type */
423 const size_t feature_len_off = 2 + (64 + 64 + 64 + 64);
424 size_t feature_len;
425 size_t plus_scid_off;
426 struct short_channel_id scid;
427 struct node_id node_id[2];
428 struct gossmap_node *n[2];
429 struct gossmap_chan *chan;
430 u32 nidx[2];
431
432 feature_len = map_be16(map, cannounce_off + feature_len_off);
433 plus_scid_off = feature_len_off + 2 + feature_len + 32;
434
435 map_nodeid(map, cannounce_off + plus_scid_off + 8, &node_id[0]);
436 map_nodeid(map, cannounce_off + plus_scid_off + 8 + PUBKEY_CMPR_LEN, &node_id[1]);
437
438 /* We can have a channel upgrade from private->public, but
439 * that's the only time we get duplicates */
440 scid.u64 = map_be64(map, cannounce_off + plus_scid_off);
441 chan = gossmap_find_chan(map, &scid);
442 if (chan)
443 gossmap_remove_chan(map, chan);
444
445 /* We carefully map pointers to indexes, since new_node can move them! */
446 n[0] = gossmap_find_node(map, &node_id[0]);
447 if (n[0])
448 nidx[0] = gossmap_node_idx(map, n[0]);
449 else
450 nidx[0] = new_node(map);
451
452 n[1] = gossmap_find_node(map, &node_id[1]);
453 if (n[1])
454 nidx[1] = gossmap_node_idx(map, n[1]);
455 else
456 nidx[1] = new_node(map);
457
458 chan = new_channel(map, cannounce_off, plus_scid_off, private,
459 nidx[0], nidx[1]);
460
461 /* Now we have a channel, we can add nodes to htable */
462 if (!n[0])
463 nodeidx_htable_add(&map->nodes,
464 node2ptrint(map->node_arr + nidx[0]));
465 if (!n[1])
466 nodeidx_htable_add(&map->nodes,
467 node2ptrint(map->node_arr + nidx[1]));
468
469 return chan;
470}
471
472/* BOLT #7:
473 * 1. type: 258 (`channel_update`)

Callers 2

map_catchupFunction · 0.85
gossmap_apply_localmodsFunction · 0.85

Calls 10

map_be16Function · 0.85
map_nodeidFunction · 0.85
map_be64Function · 0.85
gossmap_find_chanFunction · 0.85
gossmap_remove_chanFunction · 0.85
gossmap_find_nodeFunction · 0.85
gossmap_node_idxFunction · 0.85
node2ptrintFunction · 0.85
new_nodeFunction · 0.70
new_channelFunction · 0.70

Tested by

no test coverage detected