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

Function add_channel

common/gossmap.c:454–522  ·  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

452 * * [`point`:`node_id_2`]
453 */
454static struct gossmap_chan *add_channel(struct gossmap *map,
455 u64 cannounce_off,
456 size_t msglen,
457 bool *redundant)
458{
459 /* Note that first two bytes are message type */
460 const u64 feature_len_off = 2 + (64 + 64 + 64 + 64);
461 size_t feature_len;
462 u64 plus_scid_off;
463 struct short_channel_id scid;
464 struct node_id node_id[2];
465 struct gossmap_node *n[2];
466 struct gossmap_chan *chan;
467 u32 nidx[2];
468
469 feature_len = map_be16(map, cannounce_off + feature_len_off);
470 plus_scid_off = feature_len_off + 2 + feature_len + 32;
471
472 map_nodeid(map, cannounce_off + plus_scid_off + 8, &node_id[0]);
473 map_nodeid(map, cannounce_off + plus_scid_off + 8 + PUBKEY_CMPR_LEN, &node_id[1]);
474
475 if (redundant)
476 *redundant = false;
477
478 /* We should not get duplicates. */
479 scid.u64 = map_be64(map, cannounce_off + plus_scid_off);
480 chan = gossmap_find_chan(map, &scid);
481 if (chan) {
482 map->logcb(map->cbarg, LOG_BROKEN,
483 "gossmap: redundant channel_announce for %s, offsets %"PRIu64" and %"PRIu64"!",
484 fmt_short_channel_id(tmpctx, scid),
485 chan->cann_off, cannounce_off);
486 if (redundant)
487 *redundant = true;
488 return chan;
489 }
490
491 /* gossipd writes WIRE_GOSSIP_STORE_CHANNEL_AMOUNT after this,
492 * so ignore channel_announcement until that appears */
493 if (msglen
494 && (map->map_size < cannounce_off + msglen + sizeof(struct gossip_hdr) + sizeof(u16) + sizeof(u64)))
495 return NULL;
496
497 /* We carefully map pointers to indexes, since new_node can move them! */
498 n[0] = gossmap_find_node(map, &node_id[0]);
499 if (n[0])
500 nidx[0] = gossmap_node_idx(map, n[0]);
501 else
502 nidx[0] = new_node(map);
503
504 n[1] = gossmap_find_node(map, &node_id[1]);
505 if (n[1])
506 nidx[1] = gossmap_node_idx(map, n[1]);
507 else
508 nidx[1] = new_node(map);
509
510 chan = new_channel(map, cannounce_off, plus_scid_off,
511 nidx[0], nidx[1]);

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
fmt_short_channel_idFunction · 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