Browse Source

paymod: Randomly select a routehint, or none at random

The adaptive MPP test was showing an issue with always using a routehint, even
when it wasn't necessary: we would insist on routhing to the entrypoint of the
routehint, even through the actual destination. If a channel on that loop
would result being over capacity we'd slam below 0, and then increase again by
unapplying the route. The solution really is not to insist on routing through
a routehint, so we implement random skipping of routehints, and we rotate them
if we have multiples.
route-mem-overrun
Christian Decker 4 years ago
committed by Rusty Russell
parent
commit
899a2e64b0
  1. 15
      plugins/libplugin-pay.c
  2. 8
      tests/test_pay.py

15
plugins/libplugin-pay.c

@ -1769,12 +1769,19 @@ static bool routehint_excluded(struct payment *p,
static struct route_info *next_routehint(struct routehints_data *d,
struct payment *p)
{
/* FIXME: Add a pseudorandom offset to rotate between the routehints
* we use, similar to what we'd do by randomizing the routes. */
/* Implements a random selection of a routehint, or none in 1/numhints
* cases, by starting the iteration of the routehints in a random
* order, and adding a virtual NULL result at the end. */
size_t numhints = tal_count(d->routehints);
size_t offset = pseudorand(numhints + 1);
for (size_t i=0; i<tal_count(d->routehints); i++) {
if (!routehint_excluded(p, d->routehints[i])) {
size_t curr = (offset + i) % (numhints + 1);
if (curr == numhints)
return NULL;
if (!routehint_excluded(p, d->routehints[curr]))
return d->routehints[i];
}
}
return NULL;
}

8
tests/test_pay.py

@ -3103,10 +3103,10 @@ def test_mpp_adaptive(node_factory, bitcoind):
```dot
digraph {
l1 -> l2;
l2 -> l4;
l1 -> l3;
l3 -> l4;
l1 -> l2 [label="scid=103x1x1, cap=amt-1"];
l2 -> l4 [label="scid=105x1x1, cap=max"];
l1 -> l3 [label="scid=107x1x1, cap=max"];
l3 -> l4 [label="scid=109x1x1, cap=amt-1"];
}
"""
amt = 10**7 - 1

Loading…
Cancel
Save