Apply localmods to this map */
| 1218 | |
| 1219 | /* Apply localmods to this map */ |
| 1220 | void gossmap_apply_localmods(struct gossmap *map, |
| 1221 | struct gossmap_localmods *localmods) |
| 1222 | { |
| 1223 | size_t n = tal_count(localmods->mods); |
| 1224 | |
| 1225 | assert(!map->local_announces); |
| 1226 | map->local_announces = localmods->local_announces; |
| 1227 | map->local_updates = tal_arr(map, u8, 0); |
| 1228 | |
| 1229 | for (size_t i = 0; i < n; i++) { |
| 1230 | struct localmod *mod = &localmods->mods[i]; |
| 1231 | struct gossmap_chan *chan; |
| 1232 | |
| 1233 | /* Find gossmap entry which this applies to. */ |
| 1234 | chan = gossmap_find_chan(map, &mod->scid); |
| 1235 | /* If it doesn't exist, are we supposed to create a local one? */ |
| 1236 | if (!chan) { |
| 1237 | if (!localmod_is_local_chan(mod)) |
| 1238 | continue; |
| 1239 | |
| 1240 | /* Create new channel, pointing into local. */ |
| 1241 | chan = add_channel(map, map->map_size + mod->local_off, 0, NULL); |
| 1242 | } |
| 1243 | |
| 1244 | /* Save old, update any fields they wanted to change */ |
| 1245 | for (size_t h = 0; h < 2; h++) { |
| 1246 | const struct localmod_changes *c = &mod->changes[h]; |
| 1247 | /* Default values all zero, disabled */ |
| 1248 | u32 timestamp = 0; |
| 1249 | u8 message_flags = ROUTING_OPT_HTLC_MAX_MSAT, channel_flags = h | ROUTING_FLAGS_DISABLED; |
| 1250 | u16 cltv_expiry_delta = 0; |
| 1251 | u32 fee_base_msat = 0, fee_proportional_millionths = 0; |
| 1252 | struct amount_msat htlc_minimum_msat = AMOUNT_MSAT(0), |
| 1253 | htlc_maximum_msat = AMOUNT_MSAT(0); |
| 1254 | const u8 *cupdatemsg; |
| 1255 | secp256k1_ecdsa_signature fake_signature; |
| 1256 | struct bitcoin_blkid fake_blkid; |
| 1257 | struct short_channel_id_dir scidd; |
| 1258 | u64 off; |
| 1259 | bool any_set = false; |
| 1260 | |
| 1261 | /* Save existing versions */ |
| 1262 | mod->orig[h] = chan->half[h]; |
| 1263 | mod->orig_cupdate_off[h] = chan->cupdate_off[h]; |
| 1264 | |
| 1265 | /* If we have a previous one, base it on that! */ |
| 1266 | if (gossmap_chan_set(chan, h)) { |
| 1267 | gossmap_chan_get_update_details(map, chan, h, |
| 1268 | ×tamp, |
| 1269 | &message_flags, |
| 1270 | &channel_flags, |
| 1271 | &cltv_expiry_delta, |
| 1272 | &fee_base_msat, |
| 1273 | &fee_proportional_millionths, |
| 1274 | &htlc_minimum_msat, |
| 1275 | &htlc_maximum_msat); |
| 1276 | any_set = true; |
| 1277 | } |