Browse Source

pay: Factor out execution of `getroute` from starting of payment attempt.

travis-debug
ZmnSCPxj 5 years ago
committed by Christian Decker
parent
commit
e9aa690d44
  1. 56
      plugins/pay.c

56
plugins/pay.c

@ -724,35 +724,18 @@ static const char **dup_excludes(const tal_t *ctx, const char **excludes)
return ret; return ret;
} }
static struct command_result *start_pay_attempt(struct command *cmd, /* Get a route from the lightningd. */
struct pay_command *pc, static struct command_result *execute_getroute(struct command *cmd,
const char *fmt, ...) struct pay_command *pc)
{ {
struct pay_attempt *attempt = current_attempt(pc);
u32 max_hops = ROUTING_MAX_HOPS;
struct amount_msat msat; struct amount_msat msat;
const char *dest; const char *dest;
u32 max_hops = ROUTING_MAX_HOPS;
u32 cltv; u32 cltv;
struct pay_attempt *attempt;
va_list ap;
size_t n;
struct json_out *params; struct json_out *params;
n = tal_count(pc->ps->attempts);
tal_resize(&pc->ps->attempts, n+1);
attempt = &pc->ps->attempts[n];
va_start(ap, fmt);
attempt->start = time_now();
/* Mark it unfinished */
attempt->end.ts.tv_sec = -1;
attempt->excludes = dup_excludes(pc->ps, pc->excludes);
attempt->route = NULL;
attempt->failure = NULL;
attempt->result = NULL;
attempt->sendpay = false;
attempt->why = tal_vfmt(pc->ps, fmt, ap);
va_end(ap);
/* routehint set below. */ /* routehint set below. */
/* If we have a routehint, try that first; we need to do extra /* If we have a routehint, try that first; we need to do extra
@ -804,6 +787,33 @@ static struct command_result *start_pay_attempt(struct command *cmd,
take(params)); take(params));
} }
static struct command_result *start_pay_attempt(struct command *cmd,
struct pay_command *pc,
const char *fmt, ...)
{
struct pay_attempt *attempt;
va_list ap;
size_t n;
n = tal_count(pc->ps->attempts);
tal_resize(&pc->ps->attempts, n+1);
attempt = &pc->ps->attempts[n];
va_start(ap, fmt);
attempt->start = time_now();
/* Mark it unfinished */
attempt->end.ts.tv_sec = -1;
attempt->excludes = dup_excludes(pc->ps, pc->excludes);
attempt->route = NULL;
attempt->failure = NULL;
attempt->result = NULL;
attempt->sendpay = false;
attempt->why = tal_vfmt(pc->ps, fmt, ap);
va_end(ap);
return execute_getroute(cmd, pc);
}
/* BOLT #7: /* BOLT #7:
* *
* If a route is computed by simply routing to the intended recipient and * If a route is computed by simply routing to the intended recipient and

Loading…
Cancel
Save