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

Function payment_getroute

plugins/libplugin-pay.c:856–932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

854}
855
856static struct command_result *payment_getroute(struct payment *p)
857{
858 const struct gossmap_node *dst, *src;
859 struct amount_msat fee;
860 const char *errstr;
861 struct gossmap *gossmap;
862
863 /* If we retry the getroute call we might already have a route, so
864 * free an eventual stale route. */
865 p->route = tal_free(p->route);
866
867 gossmap = get_gossmap(p);
868
869 dst = gossmap_find_node(gossmap, p->getroute->destination);
870 if (!dst) {
871 put_gossmap(p);
872 return payment_fail(
873 p, "Unknown destination %s",
874 fmt_node_id(tmpctx, p->getroute->destination));
875 }
876
877 /* If we don't exist in gossip, routing can't happen. */
878 src = gossmap_find_node(gossmap, p->local_id);
879 if (!src) {
880 put_gossmap(p);
881 return payment_fail(p, "We don't have any channels");
882 }
883
884 p->route = route(p, gossmap, src, dst, p->getroute->amount, p->getroute->cltv,
885 p->getroute->riskfactorppm / 1000000.0, p->getroute->max_hops,
886 p, &errstr);
887 put_gossmap(p);
888
889 if (!p->route) {
890 return payment_fail(p, "%s", errstr);
891 }
892
893 /* OK, now we *have* a route */
894 p->step = PAYMENT_STEP_GOT_ROUTE;
895
896 if (tal_count(p->route) == 0) {
897 payment_root(p)->abort = true;
898 return payment_fail(p, "Empty route returned by getroute, are you "
899 "trying to pay yourself?");
900 }
901
902 fee = payment_route_fee(p);
903
904 /* Ensure that our fee and CLTV budgets are respected. */
905 if (amount_msat_greater(fee, p->constraints.fee_budget)) {
906 p->route = tal_free(p->route);
907 return payment_fail(
908 p, "Fee exceeds our fee budget: %s > %s, discarding route",
909 fmt_amount_msat(tmpctx, fee),
910 fmt_amount_msat(tmpctx, p->constraints.fee_budget));
911 }
912
913 if (p->route[0].delay > p->constraints.cltv_budget) {

Callers 2

payment_getlocalmodsFunction · 0.85

Calls 15

tal_freeFunction · 0.85
gossmap_find_nodeFunction · 0.85
put_gossmapFunction · 0.85
fmt_node_idFunction · 0.85
payment_rootFunction · 0.85
payment_route_feeFunction · 0.85
amount_msat_greaterFunction · 0.85
paymod_logFunction · 0.85
abortFunction · 0.85
get_gossmapFunction · 0.70
payment_failFunction · 0.70

Tested by

no test coverage detected