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