| 2787 | const struct route_info *route, size_t num_route); |
| 2788 | |
| 2789 | static bool routehint_excluded(struct payment *p, |
| 2790 | const struct route_info *routehint) |
| 2791 | { |
| 2792 | const struct node_id *nodes = payment_get_excluded_nodes(tmpctx, p); |
| 2793 | const struct short_channel_id_dir *chans = |
| 2794 | payment_get_excluded_channels(tmpctx, p); |
| 2795 | const struct channel_hint_set *hints = payment_root(p)->hints; |
| 2796 | struct short_channel_id_dir scidd; |
| 2797 | struct channel_hint *hint; |
| 2798 | |
| 2799 | /* Note that we ignore direction here: in theory, we could have |
| 2800 | * found that one direction of a channel is unavailable, but they |
| 2801 | * are suggesting we use it the other way. Very unlikely though! */ |
| 2802 | for (size_t i = 0; i < tal_count(routehint); i++) { |
| 2803 | const struct route_info *r = &routehint[i]; |
| 2804 | for (size_t j = 0; j < tal_count(nodes); j++) |
| 2805 | if (node_id_eq(&r->pubkey, &nodes[j])) |
| 2806 | return true; |
| 2807 | |
| 2808 | for (size_t j = 0; j < tal_count(chans); j++) |
| 2809 | if (short_channel_id_eq(chans[j].scid, r->short_channel_id)) |
| 2810 | return true; |
| 2811 | |
| 2812 | /* Skip the capacity check if this is the last hop |
| 2813 | * in the routehint. |
| 2814 | * The last hop in the routehint delivers the exact |
| 2815 | * final amount to the destination, which |
| 2816 | * payment_get_excluded_channels uses for excluding |
| 2817 | * already. |
| 2818 | * Thus, the capacity check below only really matters |
| 2819 | * for multi-hop routehints. |
| 2820 | */ |
| 2821 | if (i == tal_count(routehint) - 1) |
| 2822 | continue; |
| 2823 | |
| 2824 | /* Check our capacity fits. */ |
| 2825 | struct amount_msat needed_capacity; |
| 2826 | if (!route_msatoshi(&needed_capacity, p->our_amount, |
| 2827 | r + 1, tal_count(routehint) - i - 1)) |
| 2828 | return true; |
| 2829 | /* Why do we scan the hints again if |
| 2830 | * payment_get_excluded_channels already does? |
| 2831 | * Because payment_get_excluded_channels checks the |
| 2832 | * amount at destination, but we know that we are |
| 2833 | * a specific distance from the destination and we |
| 2834 | * know the exact capacity we need to send via this |
| 2835 | * channel, which is greater than the destination. |
| 2836 | */ |
| 2837 | scidd.scid = r->short_channel_id; |
| 2838 | scidd.dir = node_id_idx(&r->pubkey, p->pay_destination); |
| 2839 | hint = channel_hint_set_find(hints, &scidd); |
| 2840 | if (hint && amount_msat_greater_eq(needed_capacity, |
| 2841 | hint->estimated_capacity)) |
| 2842 | return true; |
| 2843 | } |
| 2844 | return false; |
| 2845 | } |
| 2846 |
no test coverage detected