Browse Source

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.
keysend
Christian Decker 5 years ago
parent
commit
2e88249a7b
  1. 24
      plugins/libplugin-pay.c
  2. 3
      plugins/libplugin-pay.h
  3. 2
      plugins/pay.c

24
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", "Failing a partial payment due to a failed RPC call: %.*s",
toks->end - toks->start, buffer + toks->start); toks->end - toks->start, buffer + toks->start);
p->step = PAYMENT_STEP_FAILED; payment_fail(p);
payment_continue(p);
return command_still_pending(cmd); return command_still_pending(cmd);
} }
@ -226,9 +225,8 @@ static struct command_result *payment_getroute_error(struct command *cmd,
const jsmntok_t *toks, const jsmntok_t *toks,
struct payment *p) struct payment *p)
{ {
p->step = PAYMENT_STEP_FAILED;
p->route = NULL; p->route = NULL;
payment_continue(p); payment_fail(p);
/* Let payment_finished_ handle this, so we mark it as pending */ /* Let payment_finished_ handle this, so we mark it as pending */
return command_still_pending(cmd); return command_still_pending(cmd);
@ -492,10 +490,10 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer,
if (p->result->state == PAYMENT_COMPLETE) { if (p->result->state == PAYMENT_COMPLETE) {
p->step = PAYMENT_STEP_SUCCESS; p->step = PAYMENT_STEP_SUCCESS;
goto cont; payment_continue(p);
return command_still_pending(cmd);
} }
p->step = PAYMENT_STEP_FAILED;
root = payment_root(p); root = payment_root(p);
switch (p->result->failcode) { switch (p->result->failcode) {
@ -567,8 +565,7 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer,
break; break;
} }
cont: payment_fail(p);
payment_continue(p);
return command_still_pending(cmd); return command_still_pending(cmd);
} }
@ -820,8 +817,6 @@ static void payment_finished(struct payment *p)
struct json_stream *ret; struct json_stream *ret;
struct command *cmd = p->cmd; struct command *cmd = p->cmd;
p->end_time = time_now();
/* Either none of the leaf attempts succeeded yet, or we have a /* Either none of the leaf attempts succeeded yet, or we have a
* preimage. */ * preimage. */
assert((result.leafstates & PAYMENT_STEP_SUCCESS) == 0 || assert((result.leafstates & PAYMENT_STEP_SUCCESS) == 0 ||
@ -996,6 +991,15 @@ void payment_continue(struct payment *p)
abort(); 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, void *payment_mod_get_data(const struct payment *p,
const struct payment_modifier *mod) const struct payment_modifier *mod)
{ {

3
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_start(struct payment *p);
void payment_continue(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 *payment_root(struct payment *p);
struct payment_tree_result payment_collect_result(struct payment *p); struct payment_tree_result payment_collect_result(struct payment *p);

2
plugins/pay.c

@ -1726,7 +1726,7 @@ static void init(struct plugin *p,
maxdelay_default = atoi(field); maxdelay_default = atoi(field);
} }
struct payment_modifier *paymod_mods[3] = { struct payment_modifier *paymod_mods[] = {
&local_channel_hints_pay_mod, &local_channel_hints_pay_mod,
&retry_pay_mod, &retry_pay_mod,
NULL, NULL,

Loading…
Cancel
Save