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

Function gather_range

gossipd/queries.c:422–500  ·  view source on GitHub ↗

This gets all the scids they asked for, and optionally the timestamps and checksums */

Source from the content-addressed store, hash-verified

420
421/* This gets all the scids they asked for, and optionally the timestamps and checksums */
422static struct short_channel_id *gather_range(const tal_t *ctx,
423 struct routing_state *rstate,
424 u32 first_blocknum, u32 number_of_blocks,
425 enum query_option_flags query_option_flags,
426 struct channel_update_timestamps **tstamps,
427 struct channel_update_checksums **csums)
428{
429 struct short_channel_id scid, *scids;
430 u32 end_block;
431 bool scid_ok;
432
433 scids = tal_arr(ctx, struct short_channel_id, 0);
434 if (query_option_flags & QUERY_ADD_TIMESTAMPS)
435 *tstamps = tal_arr(ctx, struct channel_update_timestamps, 0);
436 else
437 *tstamps = NULL;
438 if (query_option_flags & QUERY_ADD_CHECKSUMS)
439 *csums = tal_arr(ctx, struct channel_update_checksums, 0);
440 else
441 *csums = NULL;
442
443 /* Avoid underflow: we don't use block 0 anyway */
444 if (first_blocknum == 0)
445 scid_ok = mk_short_channel_id(&scid, 1, 0, 0);
446 else
447 scid_ok = mk_short_channel_id(&scid, first_blocknum, 0, 0);
448 scid.u64--;
449 /* Out of range? No blocks then. */
450 if (!scid_ok)
451 return NULL;
452
453 if (number_of_blocks == 0)
454 return NULL;
455
456 /* Fix up number_of_blocks to avoid overflow. */
457 end_block = first_blocknum + number_of_blocks - 1;
458 if (end_block < first_blocknum)
459 end_block = UINT_MAX;
460
461 /* We keep a `uintmap` of `short_channel_id` to `struct chan *`.
462 * Unlike a htable, it's efficient to iterate through, but it only
463 * works because each short_channel_id is basically a 64-bit unsigned
464 * integer.
465 *
466 * First we iterate and gather all the short channel ids. */
467 while (uintmap_after(&rstate->chanmap, &scid.u64)) {
468 struct chan *chan;
469 struct channel_update_timestamps ts;
470 struct channel_update_checksums cs;
471
472 if (short_channel_id_blocknum(&scid) > end_block)
473 break;
474
475 /* FIXME: Store csum in header. */
476 chan = get_channel(rstate, &scid);
477 if (!is_chan_public(chan))
478 continue;
479

Callers 1

queue_channel_rangesFunction · 0.85

Calls 5

mk_short_channel_idFunction · 0.85
get_channelFunction · 0.85
is_chan_publicFunction · 0.85

Tested by

no test coverage detected