Skip to content

Commit

Permalink
pay: Factor out execution of getroute from starting of payment atte…
Browse files Browse the repository at this point in the history
…mpt.
  • Loading branch information
ZmnSCPxj authored and cdecker committed Jan 21, 2020
1 parent 54cc735 commit e9aa690
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,35 +724,18 @@ static const char **dup_excludes(const tal_t *ctx, const char **excludes)
return ret;
}

static struct command_result *start_pay_attempt(struct command *cmd,
struct pay_command *pc,
const char *fmt, ...)
/* Get a route from the lightningd. */
static struct command_result *execute_getroute(struct command *cmd,
struct pay_command *pc)
{
struct pay_attempt *attempt = current_attempt(pc);

u32 max_hops = ROUTING_MAX_HOPS;
struct amount_msat msat;
const char *dest;
u32 max_hops = ROUTING_MAX_HOPS;
u32 cltv;
struct pay_attempt *attempt;
va_list ap;
size_t n;
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. */

/* If we have a routehint, try that first; we need to do extra
Expand Down Expand Up @@ -804,6 +787,33 @@ static struct command_result *start_pay_attempt(struct command *cmd,
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:
*
* If a route is computed by simply routing to the intended recipient and
Expand Down

0 comments on commit e9aa690

Please sign in to comment.