Skip to content

Commit 85ec438

Browse files
committed
paymod: Routehintmod signals that we can retry if getroute fails
The shortcut in the retry_mod that we can skip retrying if getroute fails or we have no result is only valid if the parameters don't change. As we iterate through the routehints the parameters change, and so we must signal to the retry_mod that it can retry even in those cases.
1 parent 52a8b8f commit 85ec438

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

plugins/libplugin-pay.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
2727
p->abort = false;
2828
p->route = NULL;
2929
p->temp_exclusion = NULL;
30+
p->failroute_retry = false;
3031

3132
/* Copy over the relevant pieces of information. */
3233
if (parent != NULL) {
@@ -1527,7 +1528,7 @@ static bool payment_can_retry(struct payment *p)
15271528
bool is_final;
15281529

15291530
if (p->result == NULL)
1530-
return false;
1531+
return p->failroute_retry;
15311532

15321533
idx = res->erring_index != NULL ? *res->erring_index : 0;
15331534
is_final = (idx == tal_count(p->route));
@@ -1595,7 +1596,7 @@ static inline void retry_step_cb(struct retry_mod_data *rd,
15951596

15961597
/* If we failed to find a route, it's unlikely we can suddenly find a
15971598
* new one without any other changes, so it's time to give up. */
1598-
if (p->route == NULL)
1599+
if (p->route == NULL && !p->failroute_retry)
15991600
return payment_continue(p);
16001601

16011602
/* If the root is marked as abort, we do not retry anymore */
@@ -1839,7 +1840,14 @@ static u32 route_cltv(u32 cltv,
18391840
* routehint entry point. */
18401841
static void routehint_pre_getroute(struct routehints_data *d, struct payment *p)
18411842
{
1843+
bool have_more;
18421844
d->current_routehint = next_routehint(d, p);
1845+
1846+
/* Signal that we could retry with another routehint even if getroute
1847+
* fails. */
1848+
have_more = (d->offset < tal_count(d->routehints) - 1);
1849+
p->failroute_retry = have_more;
1850+
18431851
if (d->current_routehint != NULL) {
18441852
if (!route_msatoshi(&p->getroute->amount, p->amount,
18451853
d->current_routehint,

plugins/libplugin-pay.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ struct payment {
255255

256256
/* Human readable explanation of why this payment failed. */
257257
const char *failreason;
258+
259+
/* If a failed getroute call can be retried for this payment. Allows
260+
* us for example to signal to any retry modifier that we can retry
261+
* despite getroute not returning a usable route. This can be the case
262+
* if we switch any of the parameters such as destination or
263+
* amount. */
264+
bool failroute_retry;
258265
};
259266

260267
struct payment_modifier {

0 commit comments

Comments
 (0)