~ We can send multiple replies when the peer queries for all channels in * a given range of blocks; each one indicates the range of blocks it covers. */
| 370 | /*~ We can send multiple replies when the peer queries for all channels in |
| 371 | * a given range of blocks; each one indicates the range of blocks it covers. */ |
| 372 | static void send_reply_channel_range(struct peer *peer, |
| 373 | u32 first_blocknum, u32 number_of_blocks, |
| 374 | const struct short_channel_id *scids, |
| 375 | const struct channel_update_timestamps *tstamps, |
| 376 | const struct channel_update_checksums *csums, |
| 377 | size_t num_scids, |
| 378 | bool final) |
| 379 | { |
| 380 | /* BOLT #7: |
| 381 | * |
| 382 | * - MUST respond with one or more `reply_channel_range`: |
| 383 | * - MUST set with `chain_hash` equal to that of `query_channel_range`, |
| 384 | * - MUST limit `number_of_blocks` to the maximum number of blocks |
| 385 | * whose results could fit in `encoded_short_ids` |
| 386 | */ |
| 387 | u8 *encoded_scids = encoding_start(tmpctx, true); |
| 388 | u8 *encoded_timestamps = encoding_start(tmpctx, false); |
| 389 | struct tlv_reply_channel_range_tlvs *tlvs |
| 390 | = tlv_reply_channel_range_tlvs_new(tmpctx); |
| 391 | |
| 392 | /* Encode them all */ |
| 393 | for (size_t i = 0; i < num_scids; i++) |
| 394 | encoding_add_short_channel_id(&encoded_scids, scids[i]); |
| 395 | encoding_end(encoded_scids, tal_bytelen(encoded_scids)); |
| 396 | |
| 397 | if (tstamps) { |
| 398 | for (size_t i = 0; i < num_scids; i++) |
| 399 | encoding_add_timestamps(&encoded_timestamps, &tstamps[i]); |
| 400 | |
| 401 | tlvs->timestamps_tlv = tal(tlvs, struct tlv_reply_channel_range_tlvs_timestamps_tlv); |
| 402 | tlvs->timestamps_tlv->encoding_type = ARR_UNCOMPRESSED; |
| 403 | encoding_end(encoded_timestamps, |
| 404 | tal_bytelen(encoded_timestamps)); |
| 405 | tlvs->timestamps_tlv->encoded_timestamps |
| 406 | = tal_steal(tlvs, encoded_timestamps); |
| 407 | } |
| 408 | |
| 409 | /* Must be a tal object! */ |
| 410 | if (csums) |
| 411 | tlvs->checksums_tlv = tal_dup_arr(tlvs, |
| 412 | struct channel_update_checksums, |
| 413 | csums, num_scids, 0); |
| 414 | |
| 415 | /* BOLT #7: |
| 416 | * |
| 417 | * - MUST set `sync_complete` to `false` if this is not the final |
| 418 | * `reply_channel_range`. |
| 419 | */ |
| 420 | u8 *msg = towire_reply_channel_range(NULL, |
| 421 | &chainparams->genesis_blockhash, |
| 422 | first_blocknum, |
| 423 | number_of_blocks, |
| 424 | final, encoded_scids, tlvs); |
| 425 | inject_peer_msg(peer, take(msg)); |
| 426 | } |
| 427 | |
| 428 | /* Helper to get non-signature, non-timestamp parts of (valid!) channel_update */ |
| 429 | static void get_cupdate_parts(const u8 *channel_update, |
no test coverage detected