| 760 | } |
| 761 | |
| 762 | bool 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 */ |