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

Function routehint_step_cb

plugins/libplugin-pay.c:2783–2864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2781}
2782
2783static void routehint_step_cb(struct routehints_data *d, struct payment *p)
2784{
2785 struct route_hop hop;
2786 const struct payment *root = payment_root(p);
2787 struct gossmap *map;
2788 if (p->step == PAYMENT_STEP_INITIALIZED) {
2789 if (root->routes == NULL)
2790 return payment_continue(p);
2791
2792 /* We filter out non-functional routehints once at the
2793 * beginning, and every other payment will filter out the
2794 * exluded ones on the fly. */
2795 if (p->parent == NULL) {
2796 map = get_gossmap(p->plugin);
2797 d->routehints = filter_routehints(
2798 map, p, d, p->local_id, p->routes);
2799 /* filter_routehints modifies the array, but
2800 * this could trigger a resize and the resize
2801 * could trigger a realloc.
2802 * Keep the invoice pointer up-to-date.
2803 * FIXME: We should really consider that if we are
2804 * mutating p->routes, maybe we should
2805 * drop d->routehints and just use p->routes
2806 * directly.
2807 * It is probably not a good idea to *copy* the
2808 * routehints: other paymods are interested in
2809 * p->routes, and if the routehints system
2810 * itself adds or removes routehints from its
2811 * copy, the *actual* number of routehints that we
2812 * end up using is the one that the routehints paymod
2813 * is maintaining and traversing, and it is *that*
2814 * set of routehints that is the important one.
2815 * So rather than copying the array of routehints
2816 * in paymod, paymod should use (and mutate) the
2817 * p->routes array, and
2818 */
2819 p->routes = d->routehints;
2820
2821 paymod_log(p, LOG_DBG,
2822 "After filtering routehints we're left with "
2823 "%zu usable hints",
2824 tal_count(d->routehints));
2825 /* Do not continue normally, instead go and check if
2826 * we can reach the destination directly. */
2827 return routehint_check_reachable(p);
2828 }
2829
2830 routehint_pre_getroute(d, p);
2831 } else if (p->step == PAYMENT_STEP_GOT_ROUTE && d->current_routehint != NULL) {
2832 /* Now it's time to stitch the two partial routes together. */
2833 struct amount_msat dest_amount;
2834 struct route_info *routehint = d->current_routehint;
2835 struct route_hop *prev_hop;
2836 for (ssize_t i = 0; i < tal_count(routehint); i++) {
2837 prev_hop = &p->route[tal_count(p->route)-1];
2838 if (!route_msatoshi(&dest_amount, p->amount,
2839 routehint + i + 1,
2840 tal_count(routehint) - i - 1)) {

Callers

nothing calls this directly

Calls 11

payment_rootFunction · 0.85
payment_continueFunction · 0.85
filter_routehintsFunction · 0.85
paymod_logFunction · 0.85
routehint_pre_getrouteFunction · 0.85
route_msatoshiFunction · 0.85
route_pubkeyFunction · 0.85
route_cltvFunction · 0.85
get_gossmapFunction · 0.70
node_id_cmpFunction · 0.50

Tested by

no test coverage detected