| 1045 | } |
| 1046 | |
| 1047 | bool gossmap_local_addchan(struct gossmap_localmods *localmods, |
| 1048 | const struct node_id *n1, |
| 1049 | const struct node_id *n2, |
| 1050 | struct short_channel_id scid, |
| 1051 | struct amount_msat capacity, |
| 1052 | const u8 *features) |
| 1053 | { |
| 1054 | be16 be16; |
| 1055 | be64 be64; |
| 1056 | u64 off; |
| 1057 | struct localmod mod; |
| 1058 | |
| 1059 | assert(!node_id_eq(n1, n2)); |
| 1060 | |
| 1061 | /* Don't create duplicate channels. */ |
| 1062 | if (find_localmod(localmods, scid)) |
| 1063 | return false; |
| 1064 | |
| 1065 | /* BOLT #7: |
| 1066 | * |
| 1067 | * - MUST set `node_id_1` and `node_id_2` to the public keys |
| 1068 | * of the two nodes operating the channel, such that |
| 1069 | * `node_id_1` is the lexicographically-lesser of the two |
| 1070 | * compressed keys sorted in ascending lexicographic order. |
| 1071 | */ |
| 1072 | if (node_id_cmp(n1, n2) > 0) |
| 1073 | return gossmap_local_addchan(localmods, n2, n1, scid, capacity, |
| 1074 | features); |
| 1075 | |
| 1076 | mod.scid = scid; |
| 1077 | memset(&mod.changes, 0, sizeof(mod.changes)); |
| 1078 | |
| 1079 | /* We create amount, then fake local channel_announcement */ |
| 1080 | off = insert_local_space(&localmods->local_announces, |
| 1081 | 8 + 2 + 64 * 4 + 2 + tal_bytelen(features) |
| 1082 | + 32 + 8 + 33 + 33); |
| 1083 | |
| 1084 | /* Write amount */ |
| 1085 | be64 = be64_to_cpu(capacity.millisatoshis / 1000 /* Raw: gossmap */); |
| 1086 | memcpy(localmods->local_announces + off, &be64, sizeof(be64)); |
| 1087 | off += sizeof(be64); |
| 1088 | |
| 1089 | /* From here is a channel-announcment, with only the fields we use */ |
| 1090 | mod.local_off = off; |
| 1091 | |
| 1092 | /* Set type to be kosher. */ |
| 1093 | be16 = CPU_TO_BE16(WIRE_CHANNEL_ANNOUNCEMENT); |
| 1094 | memcpy(localmods->local_announces + off, &be16, sizeof(be16)); |
| 1095 | off += sizeof(be16); |
| 1096 | |
| 1097 | /* Skip sigs */ |
| 1098 | off += 64 * 4; |
| 1099 | |
| 1100 | /* Set length and features */ |
| 1101 | be16 = cpu_to_be16(tal_bytelen(features)); |
| 1102 | memcpy(localmods->local_announces + off, &be16, sizeof(be16)); |
| 1103 | off += sizeof(be16); |
| 1104 | /* Damn you, C committee! */ |