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

Function select_inchan_mpp

lightningd/invoice.c:649–687  ·  view source on GitHub ↗

select_inchan_mpp * * @brief fallback in case select_inchan cannot find a *single* * channel capable of accepting the payment as a whole. * Also the main routehint-selector if we are completely unpublished * (i.e. all our channels are unpublished), since if we are completely * unpublished then the payer cannot fall back to just directly routing * to us. */

Source from the content-addressed store, hash-verified

647 * to us.
648 */
649static struct route_info **select_inchan_mpp(const tal_t *ctx,
650 struct lightningd *ld,
651 struct amount_msat amount_needed,
652 struct routehint_candidate
653 *candidates)
654{
655 /* The total amount we have gathered for incoming channels. */
656 struct amount_msat gathered;
657 /* Routehint array. */
658 struct route_info **routehints;
659
660 gathered = AMOUNT_MSAT(0);
661 routehints = tal_arr(ctx, struct route_info *, 0);
662
663 /* Sort by rr_number, so we get fresh channels. */
664 asort(candidates, tal_count(candidates), cmp_rr_number, ld);
665 for (size_t i = 0; i < tal_count(candidates); i++) {
666 if (amount_msat_greater_eq(gathered, amount_needed))
667 break;
668
669 /* Add to current routehints set. */
670 if (!amount_msat_add(&gathered, gathered, candidates[i].capacity)) {
671 log_broken(ld->log,
672 "Gathered channel capacity overflow: "
673 "%s + %s",
674 type_to_string(tmpctx, struct amount_msat, &gathered),
675 type_to_string(tmpctx, struct amount_msat,
676 &candidates[i].capacity));
677 continue;
678 }
679 tal_arr_expand(&routehints,
680 tal_dup(routehints, struct route_info,
681 candidates[i].r));
682 /* Put to the back of the round-robin list */
683 candidates[i].c->rr_number = ld->rr_counter++;
684 }
685
686 return routehints;
687}
688
689/* Encapsulating struct while we wait for gossipd to give us incoming channels */
690struct chanhints {

Callers 1

add_routehintsFunction · 0.85

Calls 3

amount_msat_greater_eqFunction · 0.85
amount_msat_addFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected