MCPcopy Create free account
hub / github.com/ElementsProject/lightning / maybe_create_range_response

Function maybe_create_range_response

connectd/queries.c:672–753  ·  view source on GitHub ↗

~ When we need to send an array of channels, it might go over our 64k packet * size. But because we use compression, we can't actually tell how much * we'll use. We pack them into the maximum amount for uncompressed, then * compress afterwards. * * Like maybe_create_query_responses(), we're careful to avoid the peer * DoSing us with a huge query_channel_range: this sends a single chunk per

Source from the content-addressed store, hash-verified

670 * call (computing timestamps/checksums only for that chunk), and is called
671 * repeatedly by the write loop until the whole reply has trickled out. */
672static const u8 *maybe_create_range_response(const tal_t *ctx,
673 struct peer *peer,
674 struct gossmap *gossmap)
675{
676 size_t off, n, limit, num;
677 u32 this_num_blocks, out_limit_block;
678 bool final, split_block;
679
680 if (!peer->range_scids)
681 return NULL;
682
683 limit = max_entries(peer->range_query_option_flags);
684 off = peer->range_scid_off;
685 num = tal_count(peer->range_scids);
686 n = num - off;
687
688 /* In a range we may have the channels of several blocks and we
689 * try to fit the blocks in a single range. But if the last
690 * block doesn't fit the range limit we may split that block so
691 * that some channels come with this range and the next range
692 * starts at the same block. */
693 split_block = false;
694
695 if (n > limit) {
696 status_debug("reply_channel_range: splitting %zu-%zu of %zu",
697 off, off + limit, num);
698
699 n = limit;
700 out_limit_block =
701 short_channel_id_blocknum(peer->range_scids[off + limit]);
702
703 /* ... and reduce to a block boundary. */
704 while (n > 0 &&
705 short_channel_id_blocknum(
706 peer->range_scids[off + n - 1]) == out_limit_block) {
707 n--;
708 }
709 /* We assume one block doesn't have limit #
710 * channels. If it does, we have to send over multiple
711 * blocks. It doesn't violate the spec though, we are
712 * only required to send a monotinic sequence of
713 * first_blocknum, and not strickly increasing. */
714 if (n == 0) {
715 status_debug("reply_channel_range: "
716 "could not fit %zu scids for %u!",
717 limit, out_limit_block);
718 n = limit;
719 split_block = true;
720 }
721 /* Get *next* channel, add num blocks */
722 this_num_blocks =
723 short_channel_id_blocknum(peer->range_scids[off + n - 1]) -
724 peer->range_first_blocknum + 1;
725 final = false;
726 } else {
727 /* Last one must end with correct total */
728 this_num_blocks = peer->range_blocks_remaining;
729 final = true;

Callers 1

Calls 4

max_entriesFunction · 0.85
make_reply_channel_rangeFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected