Skip to content

Commit 4d6b4a0

Browse files
cdeckerrustyrussell
authored andcommitted
pay: Retry the route computation if we could not apply the chanhints
This adds a new state `PAYMENT_STEP_RETRY_GETROUTE` which is used to retry just that one step, without spawning a completely new attempt. It's a new state so that modifiers do not act on it twice. Changelog-Fixed: pay: Improved the performance of the `pay` command considerably by avoiding conflicting changes to our local network view.
1 parent 544e110 commit 4d6b4a0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

plugins/libplugin-pay.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,18 @@ static void payment_compute_onion_payloads(struct payment *p)
15251525
p->step = PAYMENT_STEP_ONION_PAYLOAD;
15261526
hopcount = tal_count(p->route);
15271527

1528-
payment_chanhints_apply_route(p, false);
1528+
/* Now that we are about to fix the route parameters by
1529+
* encoding them in an onion is the right time to update the
1530+
* channel hints. */
1531+
if (!payment_chanhints_apply_route(p, false)) {
1532+
/* We can still end up with a failed channel_hints
1533+
* update, either because a plugin changed the route,
1534+
* or because a modifier was not synchronous, allowing
1535+
* for multiple concurrent routes being built. If that
1536+
* is the case, discard this route and retry. */
1537+
payment_set_step(p, PAYMENT_STEP_RETRY_GETROUTE);
1538+
return payment_continue(p);
1539+
}
15291540

15301541
/* Now compute the payload we're about to pass to `createonion` */
15311542
cr = p->createonion_request = tal(p, struct createonion_request);
@@ -1873,6 +1884,7 @@ void payment_continue(struct payment *p)
18731884
p->current_modifier = -1;
18741885
switch (p->step) {
18751886
case PAYMENT_STEP_INITIALIZED:
1887+
case PAYMENT_STEP_RETRY_GETROUTE:
18761888
payment_getroute(p);
18771889
return;
18781890

plugins/libplugin-pay.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ enum payment_step {
9494
* to amend the route. */
9595
PAYMENT_STEP_GOT_ROUTE = 2,
9696

97+
/* Something went wrong with the route returned by the
98+
previous step, so retry, but do not rerun the INITIALIZED
99+
modifiers. */
100+
PAYMENT_STEP_RETRY_GETROUTE = 3,
101+
97102
/* We just computed the onion payload, allow modifiers to amend,
98103
* before constructing the onion packet. */
99104
PAYMENT_STEP_ONION_PAYLOAD = 4,

0 commit comments

Comments
 (0)