Skip to content

Commit 56dd18e

Browse files
committed
paymod: Iterate through the routehints in order
We store an offset of the current routehint in the modifier data. It gets incremented on retry, and it gets reset to 0 on split. This is because once we split we have a different amount and a previously unusable routehint becomes usable again.
1 parent 1e28d66 commit 56dd18e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

plugins/libplugin-pay.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,15 +1771,13 @@ static struct route_info *next_routehint(struct routehints_data *d,
17711771
struct payment *p)
17721772
{
17731773
size_t numhints = tal_count(d->routehints);
1774-
size_t offset;
17751774
struct route_info *curr;
17761775

17771776
if (d->routehints == NULL || numhints == 0)
17781777
return NULL;
17791778

1780-
offset = pseudorand(numhints);
1781-
for (size_t i=0; i<tal_count(d->routehints); i++) {
1782-
curr = d->routehints[(offset + i) % numhints];
1779+
for (; d->offset <numhints; d->offset++) {
1780+
curr = d->routehints[d->offset];
17831781
if (curr == NULL || !routehint_excluded(p, curr))
17841782
return curr;
17851783
}
@@ -1971,10 +1969,17 @@ static struct routehints_data *routehint_data_init(struct payment *p)
19711969
pd = payment_mod_routehints_get_data(payment_root(p));
19721970
d->destination_reachable = pd->destination_reachable;
19731971
d->routehints = pd->routehints;
1972+
if (p->parent->step == PAYMENT_STEP_RETRY)
1973+
d->offset = pd->offset + 1;
1974+
else
1975+
d->offset = 0;
1976+
return d;
19741977
} else {
19751978
/* We defer the actual initialization of the routehints array to
19761979
* the step callback when we have the invoice attached. */
19771980
d->routehints = NULL;
1981+
d->offset = 0;
1982+
return d;
19781983
}
19791984
return d;
19801985
}

plugins/libplugin-pay.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ struct routehints_data {
296296
/* Current routehint, if any. */
297297
struct route_info *current_routehint;
298298

299+
/* Position of the current routehint in the routehints
300+
* array. Inherited and incremented on child payments and reset on
301+
* split. */
302+
int offset;
303+
299304
/* We modify the CLTV in the getroute call, so we need to remember
300305
* what the final cltv delta was so we re-apply it correctly. */
301306
u32 final_cltv;

0 commit comments

Comments
 (0)