diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 282699711..13457e91c 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -1771,15 +1771,13 @@ static struct route_info *next_routehint(struct routehints_data *d, struct payment *p) { size_t numhints = tal_count(d->routehints); - size_t offset; struct route_info *curr; if (d->routehints == NULL || numhints == 0) return NULL; - offset = pseudorand(numhints); - for (size_t i=0; iroutehints); i++) { - curr = d->routehints[(offset + i) % numhints]; + for (; d->offset offset++) { + curr = d->routehints[d->offset]; if (curr == NULL || !routehint_excluded(p, curr)) return curr; } @@ -1971,10 +1969,17 @@ static struct routehints_data *routehint_data_init(struct payment *p) pd = payment_mod_routehints_get_data(payment_root(p)); d->destination_reachable = pd->destination_reachable; d->routehints = pd->routehints; + if (p->parent->step == PAYMENT_STEP_RETRY) + d->offset = pd->offset + 1; + else + d->offset = 0; + return d; } else { /* We defer the actual initialization of the routehints array to * the step callback when we have the invoice attached. */ d->routehints = NULL; + d->offset = 0; + return d; } return d; } diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index a97cfd573..c48c61f1e 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -296,6 +296,11 @@ struct routehints_data { /* Current routehint, if any. */ struct route_info *current_routehint; + /* Position of the current routehint in the routehints + * array. Inherited and incremented on child payments and reset on + * split. */ + int offset; + /* We modify the CLTV in the getroute call, so we need to remember * what the final cltv delta was so we re-apply it correctly. */ u32 final_cltv;