This just gathers the scids they asked for: no channel_update lookups * (i.e. no timestamps or checksums), so it's cheap regardless of how large * a range they asked for. */
| 607 | * (i.e. no timestamps or checksums), so it's cheap regardless of how large |
| 608 | * a range they asked for. */ |
| 609 | static struct short_channel_id *gather_range_scids(const tal_t *ctx, |
| 610 | struct gossmap *gossmap, |
| 611 | u32 first_blocknum, |
| 612 | u32 number_of_blocks) |
| 613 | { |
| 614 | struct short_channel_id *scids = tal_arr(ctx, struct short_channel_id, 0); |
| 615 | u32 end_block; |
| 616 | |
| 617 | if (number_of_blocks == 0) |
| 618 | return scids; |
| 619 | |
| 620 | /* Fix up number_of_blocks to avoid overflow. */ |
| 621 | end_block = first_blocknum + number_of_blocks - 1; |
| 622 | if (end_block < first_blocknum) |
| 623 | end_block = UINT_MAX; |
| 624 | |
| 625 | /* We used to maintain a uintmap of channels by scid, but |
| 626 | * we no longer do, making this more expensive. But still |
| 627 | * not too bad, since it's usually in-mem */ |
| 628 | for (size_t i = 0; i < gossmap_max_chan_idx(gossmap); i++) { |
| 629 | struct gossmap_chan *chan = gossmap_chan_byidx(gossmap, i); |
| 630 | struct short_channel_id scid; |
| 631 | |
| 632 | if (!chan) |
| 633 | continue; |
| 634 | |
| 635 | /* By policy, we don't give announcements here with no |
| 636 | * channel_updates */ |
| 637 | if (!gossmap_chan_set(chan, 0) && !gossmap_chan_set(chan, 1)) { |
| 638 | continue; |
| 639 | } |
| 640 | |
| 641 | scid = gossmap_chan_scid(gossmap, chan); |
| 642 | if (short_channel_id_blocknum(scid) < first_blocknum |
| 643 | || short_channel_id_blocknum(scid) > end_block) { |
| 644 | continue; |
| 645 | } |
| 646 | |
| 647 | tal_arr_expand(&scids, scid); |
| 648 | } |
| 649 | |
| 650 | /* BOLT #7: |
| 651 | * The receiver of `query_channel_range`: |
| 652 | * ... |
| 653 | * - successive `reply_channel_range` message: |
| 654 | * - MUST have `first_blocknum` equal or greater than the previous `first_blocknum`. |
| 655 | * */ |
| 656 | /* Possibly a bucket sort here could be faster. But we are not dealing |
| 657 | * with millions of channels anyways. */ |
| 658 | asort(scids, tal_count(scids), scid_order, NULL); |
| 659 | |
| 660 | return scids; |
| 661 | } |
| 662 | |
| 663 | /*~ When we need to send an array of channels, it might go over our 64k packet |
| 664 | * size. But because we use compression, we can't actually tell how much |