| 3068 | } |
| 3069 | |
| 3070 | static struct command_result *routehint_step_cb(struct routehints_data *d, struct payment *p) |
| 3071 | { |
| 3072 | struct route_hop hop; |
| 3073 | const struct payment *root = payment_root(p); |
| 3074 | struct gossmap *map; |
| 3075 | if (p->step == PAYMENT_STEP_INITIALIZED) { |
| 3076 | if (root->routes == NULL) |
| 3077 | return payment_continue(p); |
| 3078 | |
| 3079 | /* We filter out non-functional routehints once at the |
| 3080 | * beginning, and every other payment will filter out the |
| 3081 | * exluded ones on the fly. */ |
| 3082 | if (p->parent == NULL) { |
| 3083 | map = get_gossmap(p); |
| 3084 | d->routehints = filter_routehints( |
| 3085 | map, p, d, p->local_id, p->routes); |
| 3086 | /* filter_routehints modifies the array, but |
| 3087 | * this could trigger a resize and the resize |
| 3088 | * could trigger a realloc. |
| 3089 | * Keep the invoice pointer up-to-date. |
| 3090 | * FIXME: We should really consider that if we are |
| 3091 | * mutating p->routes, maybe we should |
| 3092 | * drop d->routehints and just use p->routes |
| 3093 | * directly. |
| 3094 | * It is probably not a good idea to *copy* the |
| 3095 | * routehints: other paymods are interested in |
| 3096 | * p->routes, and if the routehints system |
| 3097 | * itself adds or removes routehints from its |
| 3098 | * copy, the *actual* number of routehints that we |
| 3099 | * end up using is the one that the routehints paymod |
| 3100 | * is maintaining and traversing, and it is *that* |
| 3101 | * set of routehints that is the important one. |
| 3102 | * So rather than copying the array of routehints |
| 3103 | * in paymod, paymod should use (and mutate) the |
| 3104 | * p->routes array, and |
| 3105 | */ |
| 3106 | put_gossmap(p); |
| 3107 | p->routes = d->routehints; |
| 3108 | |
| 3109 | paymod_log(p, LOG_DBG, |
| 3110 | "After filtering routehints we're left with " |
| 3111 | "%zu usable hints", |
| 3112 | tal_count(d->routehints)); |
| 3113 | /* Do not continue normally, instead go and check if |
| 3114 | * we can reach the destination directly. */ |
| 3115 | return routehint_check_reachable(p); |
| 3116 | } |
| 3117 | |
| 3118 | routehint_pre_getroute(d, p); |
| 3119 | } else if (p->step == PAYMENT_STEP_GOT_ROUTE && d->current_routehint != NULL) { |
| 3120 | /* Now it's time to stitch the two partial routes together. */ |
| 3121 | struct amount_msat dest_amount, estimate; |
| 3122 | /* We do not have the exact final amount, however we |
| 3123 | * know that we should be able to use the channel in |
| 3124 | * the routehint, so let's fake it as being 2x the |
| 3125 | * amount we want to route. */ |
| 3126 | |
| 3127 | if(!amount_msat_mul(&estimate, p->final_amount, 2)) |
nothing calls this directly
no test coverage detected