Skip to content

Commit

Permalink
paymod: Randomly select a routehint, or none at random
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed Jul 22, 2020
1 parent e5b36b6 commit ec89b6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec89b6e

Please sign in to comment.