From 2e88249a7b070348d59926349a8189f6870db7c7 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 29 May 2020 15:16:40 +0200 Subject: [PATCH] paymod: Make the transition to FAILED a function call We need to set some variables as well, and the transition to FAILED is a bit special in that quite some modifiers will skip into FAILED. --- plugins/libplugin-pay.c | 24 ++++++++++++++---------- plugins/libplugin-pay.h | 3 +++ plugins/pay.c | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 741bf4ba8..9c1c096a8 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -76,8 +76,7 @@ static struct command_result *payment_rpc_failure(struct command *cmd, "Failing a partial payment due to a failed RPC call: %.*s", toks->end - toks->start, buffer + toks->start); - p->step = PAYMENT_STEP_FAILED; - payment_continue(p); + payment_fail(p); return command_still_pending(cmd); } @@ -226,9 +225,8 @@ static struct command_result *payment_getroute_error(struct command *cmd, const jsmntok_t *toks, struct payment *p) { - p->step = PAYMENT_STEP_FAILED; p->route = NULL; - payment_continue(p); + payment_fail(p); /* Let payment_finished_ handle this, so we mark it as pending */ return command_still_pending(cmd); @@ -492,10 +490,10 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer, if (p->result->state == PAYMENT_COMPLETE) { p->step = PAYMENT_STEP_SUCCESS; - goto cont; + payment_continue(p); + return command_still_pending(cmd); } - p->step = PAYMENT_STEP_FAILED; root = payment_root(p); switch (p->result->failcode) { @@ -567,8 +565,7 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer, break; } -cont: - payment_continue(p); + payment_fail(p); return command_still_pending(cmd); } @@ -820,8 +817,6 @@ static void payment_finished(struct payment *p) struct json_stream *ret; struct command *cmd = p->cmd; - p->end_time = time_now(); - /* Either none of the leaf attempts succeeded yet, or we have a * preimage. */ assert((result.leafstates & PAYMENT_STEP_SUCCESS) == 0 || @@ -996,6 +991,15 @@ void payment_continue(struct payment *p) abort(); } +void payment_fail(struct payment *p) +{ + va_list ap; + + p->end_time = time_now(); + p->step = PAYMENT_STEP_FAILED; + payment_continue(p); +} + void *payment_mod_get_data(const struct payment *p, const struct payment_modifier *mod) { diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index f925fe82d..bb3a7093f 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -276,6 +276,9 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd, void payment_start(struct payment *p); void payment_continue(struct payment *p); + +/* Fails a partial payment and continues with the core flow. */ +void payment_fail(struct payment *p); struct payment *payment_root(struct payment *p); struct payment_tree_result payment_collect_result(struct payment *p); diff --git a/plugins/pay.c b/plugins/pay.c index a62d6cd2d..e34a63325 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1726,7 +1726,7 @@ static void init(struct plugin *p, maxdelay_default = atoi(field); } -struct payment_modifier *paymod_mods[3] = { +struct payment_modifier *paymod_mods[] = { &local_channel_hints_pay_mod, &retry_pay_mod, NULL,