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

Function max_entries

connectd/queries.c:519–561  ·  view source on GitHub ↗

How many entries can I fit in a reply? */

Source from the content-addressed store, hash-verified

517
518/* How many entries can I fit in a reply? */
519static size_t max_entries(enum query_option_flags query_option_flags)
520{
521 /* BOLT #7:
522 *
523 * 1. type: 264 (`reply_channel_range`)
524 * 2. data:
525 * * [`chain_hash`:`chain_hash`]
526 * * [`u32`:`first_blocknum`]
527 * * [`u32`:`number_of_blocks`]
528 * * [`byte`:`sync_complete`]
529 * * [`u16`:`len`]
530 * * [`len*byte`:`encoded_short_ids`]
531 */
532 const size_t reply_overhead = 32 + 4 + 4 + 1 + 2;
533 size_t max_encoded_bytes = 65535 - 2 - reply_overhead;
534 size_t per_entry_size, max_num;
535
536 per_entry_size = sizeof(struct short_channel_id);
537
538 /* Upper bound to start. */
539 max_num = max_encoded_bytes / per_entry_size;
540
541 /* If we add timestamps, we need to encode tlv */
542 if (query_option_flags & QUERY_ADD_TIMESTAMPS) {
543 max_encoded_bytes -= tlv_overhead(max_num,
544 sizeof(struct channel_update_timestamps));
545 per_entry_size += sizeof(struct channel_update_timestamps);
546 }
547
548 if (query_option_flags & QUERY_ADD_CHECKSUMS) {
549 max_encoded_bytes -= tlv_overhead(max_num,
550 sizeof(struct channel_update_checksums));
551 per_entry_size += sizeof(struct channel_update_checksums);
552 }
553
554 if (max_encoded_bytes > dev_max_encoding_bytes)
555 max_encoded_bytes = dev_max_encoding_bytes;
556 /* Always let one through! */
557 if (max_encoded_bytes < per_entry_size)
558 max_encoded_bytes = per_entry_size;
559
560 return max_encoded_bytes / per_entry_size;
561}
562
563/* This gets all the scids they asked for, and optionally the timestamps and checksums */
564static struct short_channel_id *gather_range(const tal_t *ctx,

Callers 1

queue_channel_rangesFunction · 0.85

Calls 1

tlv_overheadFunction · 0.85

Tested by

no test coverage detected