| 810 | } |
| 811 | |
| 812 | static struct command_result *payment_getroute(struct payment *p) |
| 813 | { |
| 814 | const struct gossmap_node *dst, *src; |
| 815 | struct amount_msat fee; |
| 816 | const char *errstr; |
| 817 | struct gossmap *gossmap; |
| 818 | |
| 819 | /* If we retry the getroute call we might already have a route, so |
| 820 | * free an eventual stale route. */ |
| 821 | p->route = tal_free(p->route); |
| 822 | |
| 823 | gossmap = get_gossmap(p->plugin); |
| 824 | |
| 825 | dst = gossmap_find_node(gossmap, p->getroute->destination); |
| 826 | if (!dst) { |
| 827 | payment_fail( |
| 828 | p, "Unknown destination %s", |
| 829 | type_to_string(tmpctx, struct node_id, |
| 830 | p->getroute->destination)); |
| 831 | |
| 832 | /* Let payment_finished_ handle this, so we mark it as pending */ |
| 833 | return command_still_pending(p->cmd); |
| 834 | } |
| 835 | |
| 836 | /* If we don't exist in gossip, routing can't happen. */ |
| 837 | src = gossmap_find_node(gossmap, p->local_id); |
| 838 | if (!src) { |
| 839 | payment_fail(p, "We don't have any channels"); |
| 840 | |
| 841 | /* Let payment_finished_ handle this, so we mark it as pending */ |
| 842 | return command_still_pending(p->cmd); |
| 843 | } |
| 844 | |
| 845 | p->route = route(p, gossmap, src, dst, p->getroute->amount, p->getroute->cltv, |
| 846 | p->getroute->riskfactorppm / 1000000.0, p->getroute->max_hops, |
| 847 | p, &errstr); |
| 848 | if (!p->route) { |
| 849 | payment_fail(p, "%s", errstr); |
| 850 | /* Let payment_finished_ handle this, so we mark it as pending */ |
| 851 | return command_still_pending(p->cmd); |
| 852 | } |
| 853 | |
| 854 | /* OK, now we *have* a route */ |
| 855 | p->step = PAYMENT_STEP_GOT_ROUTE; |
| 856 | |
| 857 | if (tal_count(p->route) == 0) { |
| 858 | payment_root(p)->abort = true; |
| 859 | payment_fail(p, "Empty route returned by getroute, are you " |
| 860 | "trying to pay yourself?"); |
| 861 | } |
| 862 | |
| 863 | fee = payment_route_fee(p); |
| 864 | |
| 865 | /* Ensure that our fee and CLTV budgets are respected. */ |
| 866 | if (amount_msat_greater(fee, p->constraints.fee_budget)) { |
| 867 | payment_exclude_most_expensive(p); |
| 868 | p->route = tal_free(p->route); |
| 869 | payment_fail( |
no test coverage detected