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