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

Function gossmap_local_addchan

common/gossmap.c:762–829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

760}
761
762bool gossmap_local_addchan(struct gossmap_localmods *localmods,
763 const struct node_id *n1,
764 const struct node_id *n2,
765 const struct short_channel_id *scid,
766 const u8 *features)
767{
768 be16 be16;
769 be64 be64;
770 size_t off;
771 struct localmod mod;
772
773 /* Don't create duplicate channels. */
774 if (find_localmod(localmods, scid))
775 return false;
776
777 /* BOLT #7:
778 *
779 * - MUST set `node_id_1` and `node_id_2` to the public keys
780 * of the two nodes operating the channel, such that
781 * `node_id_1` is the lexicographically-lesser of the two
782 * compressed keys sorted in ascending lexicographic order.
783 */
784 if (node_id_cmp(n1, n2) > 0)
785 return gossmap_local_addchan(localmods, n2, n1, scid, features);
786
787 mod.scid = *scid;
788 mod.updates_set[0] = mod.updates_set[1] = false;
789
790 /* We create fake local channel_announcement. */
791 off = insert_local_space(localmods,
792 2 + 64 * 4 + 2 + tal_bytelen(features)
793 + 32 + 8 + 33 + 33);
794 mod.local_off = off;
795
796 /* Set type to be kosher. */
797 be16 = CPU_TO_BE16(WIRE_CHANNEL_ANNOUNCEMENT);
798 memcpy(localmods->local + off, &be16, sizeof(be16));
799 off += sizeof(be16);
800
801 /* Skip sigs */
802 off += 64 * 4;
803
804 /* Set length and features */
805 be16 = cpu_to_be16(tal_bytelen(features));
806 memcpy(localmods->local + off, &be16, sizeof(be16));
807 off += sizeof(be16);
808 memcpy(localmods->local + off, features, tal_bytelen(features));
809 off += tal_bytelen(features);
810
811 /* Skip chain_hash */
812 off += 32;
813
814 /* Set scid */
815 be64 = be64_to_cpu(scid->u64);
816 memcpy(localmods->local + off, &be64, sizeof(be64));
817 off += sizeof(be64);
818
819 /* set node_ids */

Callers 1

mainFunction · 0.85

Calls 6

find_localmodFunction · 0.85
insert_local_spaceFunction · 0.85
tal_bytelenFunction · 0.85
cpu_to_be16Function · 0.85
be64_to_cpuFunction · 0.85
node_id_cmpFunction · 0.70

Tested by 1

mainFunction · 0.68