diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 630f7d3b2..f07ffd9a0 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -174,3 +174,39 @@ static inline void dummy_step_cb(struct dummy_data *dd, REGISTER_PAYMENT_MODIFIER(dummy, struct dummy_data *, dummy_data_init, dummy_step_cb); + +static struct retry_mod_data *retry_data_init(struct payment *p); + +static inline void retry_step_cb(struct retry_mod_data *rd, + struct payment *p); + +REGISTER_PAYMENT_MODIFIER(retry, struct retry_mod_data *, retry_data_init, + retry_step_cb); + +static struct retry_mod_data * +retry_data_init(struct payment *p) +{ + struct retry_mod_data *rdata = tal(p, struct retry_mod_data); + struct retry_mod_data *parent_rdata; + if (p->parent != NULL) { + parent_rdata = payment_mod_retry_get_data(p->parent); + rdata->retries = parent_rdata->retries - 1; + } else { + rdata->retries = 10; + } + return rdata; +} + +static inline void retry_step_cb(struct retry_mod_data *rd, + struct payment *p) +{ + struct payment *subpayment; + struct retry_mod_data *rdata = payment_mod_retry_get_data(p); + if (p->step == PAYMENT_STEP_FAILED && rdata->retries > 0) { + subpayment = payment_new(p, p->cmd, p, p->modifiers); + payment_start(subpayment); + p->step = PAYMENT_STEP_RETRY; + } + + payment_continue(p); +} diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index 783e088fa..2bd474f91 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -145,6 +145,10 @@ struct dummy_data { unsigned int *dummy_param; }; +struct retry_mod_data { + int retries; +}; + /* List of globally available payment modifiers. */ extern struct payment_modifier dummy_pay_mod; REGISTER_PAYMENT_MODIFIER_HEADER(retry, struct retry_mod_data); diff --git a/plugins/pay.c b/plugins/pay.c index dc9461fe1..499919f5d 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1704,8 +1704,9 @@ static void init(struct plugin *p, } #if DEVELOPER -struct payment_modifier *paymod_mods[2] = { +struct payment_modifier *paymod_mods[3] = { &dummy_pay_mod, + &retry_pay_mod, NULL, };