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