diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 4c896d4e1..d2a058f1c 100644 --- a/plugins/libplugin-pay.c +++ b/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; iroutehints); 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; } diff --git a/tests/test_pay.py b/tests/test_pay.py index e41afdfff..e4b7c2df6 100644 --- a/tests/test_pay.py +++ b/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