mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
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.
This commit is contained in:
@@ -1771,15 +1771,13 @@ static struct route_info *next_routehint(struct routehints_data *d,
|
|||||||
struct payment *p)
|
struct payment *p)
|
||||||
{
|
{
|
||||||
size_t numhints = tal_count(d->routehints);
|
size_t numhints = tal_count(d->routehints);
|
||||||
size_t offset;
|
|
||||||
struct route_info *curr;
|
struct route_info *curr;
|
||||||
|
|
||||||
if (d->routehints == NULL || numhints == 0)
|
if (d->routehints == NULL || numhints == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
offset = pseudorand(numhints);
|
for (; d->offset <numhints; d->offset++) {
|
||||||
for (size_t i=0; i<tal_count(d->routehints); i++) {
|
curr = d->routehints[d->offset];
|
||||||
curr = d->routehints[(offset + i) % numhints];
|
|
||||||
if (curr == NULL || !routehint_excluded(p, curr))
|
if (curr == NULL || !routehint_excluded(p, curr))
|
||||||
return 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));
|
pd = payment_mod_routehints_get_data(payment_root(p));
|
||||||
d->destination_reachable = pd->destination_reachable;
|
d->destination_reachable = pd->destination_reachable;
|
||||||
d->routehints = pd->routehints;
|
d->routehints = pd->routehints;
|
||||||
|
if (p->parent->step == PAYMENT_STEP_RETRY)
|
||||||
|
d->offset = pd->offset + 1;
|
||||||
|
else
|
||||||
|
d->offset = 0;
|
||||||
|
return d;
|
||||||
} else {
|
} else {
|
||||||
/* We defer the actual initialization of the routehints array to
|
/* We defer the actual initialization of the routehints array to
|
||||||
* the step callback when we have the invoice attached. */
|
* the step callback when we have the invoice attached. */
|
||||||
d->routehints = NULL;
|
d->routehints = NULL;
|
||||||
|
d->offset = 0;
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,6 +296,11 @@ struct routehints_data {
|
|||||||
/* Current routehint, if any. */
|
/* Current routehint, if any. */
|
||||||
struct route_info *current_routehint;
|
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
|
/* 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. */
|
* what the final cltv delta was so we re-apply it correctly. */
|
||||||
u32 final_cltv;
|
u32 final_cltv;
|
||||||
|
|||||||
Reference in New Issue
Block a user