~ The peer can ask for all channels in a series of blocks. We reply with one * or more messages containing the short_channel_ids. */
| 755 | /*~ The peer can ask for all channels in a series of blocks. We reply with one |
| 756 | * or more messages containing the short_channel_ids. */ |
| 757 | void handle_query_channel_range(struct peer *peer, const u8 *msg) |
| 758 | { |
| 759 | struct bitcoin_blkid chain_hash; |
| 760 | u32 first_blocknum, number_of_blocks; |
| 761 | enum query_option_flags query_option_flags; |
| 762 | struct tlv_query_channel_range_tlvs *tlvs; |
| 763 | |
| 764 | if (!fromwire_query_channel_range(msg, msg, &chain_hash, |
| 765 | &first_blocknum, &number_of_blocks, |
| 766 | &tlvs)) { |
| 767 | warning_to_peer(peer, |
| 768 | "Bad query_channel_range w/tlvs %s", |
| 769 | tal_hex(tmpctx, msg)); |
| 770 | return; |
| 771 | } |
| 772 | if (tlvs->query_option) |
| 773 | query_option_flags = *tlvs->query_option; |
| 774 | else |
| 775 | query_option_flags = 0; |
| 776 | |
| 777 | /* Unknown chain_hash: reply with sync_complete=false. */ |
| 778 | if (!bitcoin_blkid_eq(&chainparams->genesis_blockhash, &chain_hash)) { |
| 779 | status_peer_debug(&peer->id, |
| 780 | "query_channel_range with chainhash %s", |
| 781 | fmt_bitcoin_blkid(tmpctx, &chain_hash)); |
| 782 | u8 *end = towire_reply_channel_range(NULL, &chain_hash, first_blocknum, |
| 783 | number_of_blocks, false, NULL, NULL); |
| 784 | inject_peer_msg(peer, take(end)); |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | /* We only answer one query_channel_range at a time (like |
| 789 | * query_short_channel_ids), so we don't have to juggle multiple |
| 790 | * in-flight trickled replies per peer. */ |
| 791 | if (peer->range_scids) { |
| 792 | warning_to_peer(peer, "Bad concurrent query_channel_range"); |
| 793 | return; |
| 794 | } |
| 795 | |
| 796 | /* Fix up number_of_blocks to avoid overflow. */ |
| 797 | if (first_blocknum + number_of_blocks < first_blocknum) |
| 798 | number_of_blocks = UINT_MAX - first_blocknum; |
| 799 | |
| 800 | /* Gathering the scids is cheap; we work out timestamps/checksums |
| 801 | * (and actually send the replies) lazily, as we trickle them out |
| 802 | * via maybe_create_query_responses(). */ |
| 803 | peer->range_scids = gather_range_scids(peer, get_gossmap(peer->daemon), |
| 804 | first_blocknum, number_of_blocks); |
| 805 | peer->range_scid_off = 0; |
| 806 | peer->range_first_blocknum = first_blocknum; |
| 807 | peer->range_blocks_remaining = number_of_blocks; |
| 808 | peer->range_query_option_flags = query_option_flags; |
| 809 | |
| 810 | /* Notify the write loop to invoke maybe_create_query_responses */ |
| 811 | io_wake(peer->peer_outq); |
| 812 | } |
| 813 | |
| 814 | /* This is a testing hack to allow us to artificially lower the maximum bytes |
no test coverage detected