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

Function add_routehints

lightningd/invoice.c:699–835  ·  view source on GitHub ↗

Add routehints based on listincoming results: NULL means success. */

Source from the content-addressed store, hash-verified

697
698/* Add routehints based on listincoming results: NULL means success. */
699static struct command_result *
700add_routehints(struct invoice_info *info,
701 const char *buffer,
702 const jsmntok_t *toks,
703 bool *warning_mpp,
704 bool *warning_capacity,
705 bool *warning_deadends,
706 bool *warning_offline,
707 bool *warning_private_unused)
708{
709 const struct chanhints *chanhints = info->chanhints;
710 bool node_unpublished;
711 struct amount_msat avail_capacity, deadend_capacity, offline_capacity,
712 private_capacity;
713 struct routehint_candidate *candidates;
714 struct amount_msat total, needed;
715
716 /* Dev code can force routes. */
717 if (info->b11->routes) {
718 *warning_mpp = *warning_capacity = *warning_deadends
719 = *warning_offline = *warning_private_unused
720 = false;
721 return NULL;
722 }
723
724 candidates = routehint_candidates(tmpctx, info->cmd->ld,
725 buffer, toks,
726 chanhints ? &chanhints->expose_all_private : NULL,
727 chanhints ? chanhints->hints : NULL,
728 &node_unpublished,
729 &avail_capacity,
730 &private_capacity,
731 &deadend_capacity,
732 &offline_capacity);
733
734 /* If they told us to use scids and we couldn't, fail. */
735 if (tal_count(candidates) == 0
736 && chanhints && tal_count(chanhints->hints) != 0) {
737 return command_fail(info->cmd,
738 INVOICE_HINTS_GAVE_NO_ROUTES,
739 "None of those hints were suitable local channels");
740 }
741
742 needed = info->b11->msat ? *info->b11->msat : AMOUNT_MSAT(1);
743
744 /* --payment-fronting-node means use all candidates. */
745 if (tal_count(info->cmd->ld->fronting_nodes))
746 info->b11->routes = select_inchan_all(info->b11, info->cmd->ld, candidates);
747
748 /* If we are not completely unpublished, try with reservoir
749 * sampling first.
750 *
751 * Why do we not do this if we are completely unpublished?
752 * Because it is possible that multiple invoices will, by
753 * chance, select the same channel as routehint.
754 * This single channel might not be able to accept all the
755 * incoming payments on all the invoices generated.
756 * If we were published, that is fine because the payer can

Callers 1

listincoming_doneFunction · 0.85

Calls 12

routehint_candidatesFunction · 0.85
select_inchan_allFunction · 0.85
select_inchanFunction · 0.85
select_inchan_mppFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_accumulateFunction · 0.85
amount_msat_greater_eqFunction · 0.85
amount_msat_greaterFunction · 0.85
abortFunction · 0.85
command_failFunction · 0.70
fatalFunction · 0.70
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected