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

Function compute_routes_cb

plugins/renepay/mods.c:655–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

653 */
654
655static struct command_result *compute_routes_cb(struct payment *payment)
656{
657 assert(payment->status == PAYMENT_PENDING);
658 struct routetracker *routetracker = payment->routetracker;
659 assert(routetracker);
660
661 if (routetracker->computed_routes &&
662 tal_count(routetracker->computed_routes))
663 plugin_err(pay_plugin->plugin,
664 "%s: no previously computed routes expected.",
665 __func__);
666
667 struct amount_msat feebudget, fees_spent, remaining;
668
669 /* Total feebudget */
670 if (!amount_msat_sub(&feebudget, payment->payment_info.maxspend,
671 payment->payment_info.amount))
672 plugin_err(pay_plugin->plugin, "%s: fee budget is negative?",
673 __func__);
674
675 /* Fees spent so far */
676 if (!amount_msat_sub(&fees_spent, payment->total_sent,
677 payment->total_delivering))
678 plugin_err(pay_plugin->plugin,
679 "%s: total_delivering is greater than total_sent?",
680 __func__);
681
682 /* Remaining fee budget. */
683 if (!amount_msat_deduct(&feebudget, fees_spent))
684 feebudget = AMOUNT_MSAT(0);
685
686 /* How much are we still trying to send? */
687 if (!amount_msat_sub(&remaining, payment->payment_info.amount,
688 payment->total_delivering) ||
689 amount_msat_is_zero(remaining)) {
690 plugin_log(pay_plugin->plugin, LOG_UNUSUAL,
691 "%s: Payment is pending with full amount already "
692 "committed. We skip the computation of new routes.",
693 __func__);
694 return payment_continue(payment);
695 }
696
697 enum jsonrpc_errcode errcode;
698 const char *err_msg = NULL;
699
700 gossmap_apply_localmods(pay_plugin->gossmap, payment->local_gossmods);
701
702 /* get_routes returns the answer, we assign it to the computed_routes,
703 * that's why we need to tal_free the older array. Maybe it would be
704 * better to pass computed_routes as a reference? */
705 routetracker->computed_routes = tal_free(routetracker->computed_routes);
706
707 /* Send get_routes a note that it should discard the last hop because we
708 * are actually solving a multiple destinations problem. */
709 bool blinded_destination = true;
710
711 // TODO: add an algorithm selector here
712 /* We let this return an unlikely path, as it's better to try once than

Callers

nothing calls this directly

Calls 11

amount_msat_subFunction · 0.85
amount_msat_deductFunction · 0.85
amount_msat_is_zeroFunction · 0.85
gossmap_apply_localmodsFunction · 0.85
tal_freeFunction · 0.85
get_routesFunction · 0.85
gossmap_remove_localmodsFunction · 0.85
payment_continueFunction · 0.70
payment_failFunction · 0.70
plugin_errFunction · 0.50
plugin_logFunction · 0.50

Tested by

no test coverage detected