Browse Source

paymod: Move application of routehints into its own function

We have two places we need to do that now: in the root payment after we
checked if the destination is reachable, and in any other payment directly in
the initialization-step callback.
release-0.9.0rc3
Christian Decker 4 years ago
parent
commit
1e28d661fd
  1. 49
      plugins/libplugin-pay.c

49
plugins/libplugin-pay.c

@ -1820,6 +1820,33 @@ static u32 route_cltv(u32 cltv,
return cltv;
}
/* Change the destination and compute the final msatoshi amount to send to the
* routehint entry point. */
static void routehint_pre_getroute(struct routehints_data *d, struct payment *p)
{
d->current_routehint = next_routehint(d, p);
if (d->current_routehint != NULL) {
if (!route_msatoshi(&p->getroute->amount, p->amount,
d->current_routehint,
tal_count(d->current_routehint))) {
}
d->final_cltv = p->getroute->cltv;
p->getroute->destination = &d->current_routehint[0].pubkey;
p->getroute->cltv =
route_cltv(p->getroute->cltv, d->current_routehint,
tal_count(d->current_routehint));
plugin_log(
p->plugin, LOG_DBG, "Using routehint %s (%s) cltv_delta=%d",
type_to_string(tmpctx, struct node_id,
&d->current_routehint->pubkey),
type_to_string(tmpctx, struct short_channel_id,
&d->current_routehint->short_channel_id),
d->current_routehint->cltv_expiry_delta);
} else {
plugin_log(p->plugin, LOG_DBG, "Not using a routehint");
}
}
static struct command_result *routehint_getroute_result(struct command *cmd,
const char *buffer,
const jsmntok_t *toks,
@ -1836,7 +1863,7 @@ static struct command_result *routehint_getroute_result(struct command *cmd,
if (d->destination_reachable)
tal_arr_expand(&d->routehints, NULL);
d->current_routehint = next_routehint(d, p);
routehint_pre_getroute(d, p);
plugin_log(p->plugin, LOG_DBG,
"The destination is%s directly reachable %s attempts "
@ -1897,25 +1924,7 @@ static void routehint_step_cb(struct routehints_data *d, struct payment *p)
return routehint_check_reachable(p);
}
d->current_routehint = next_routehint(d, p);
if (d->current_routehint != NULL) {
/* Change the destination and compute the final msatoshi
* amount to send to the routehint entry point. */
if (!route_msatoshi(&p->getroute->amount, p->amount,
d->current_routehint,
tal_count(d->current_routehint))) {
}
d->final_cltv = p->getroute->cltv;
p->getroute->destination = &d->current_routehint[0].pubkey;
p->getroute->cltv =
route_cltv(p->getroute->cltv, d->current_routehint,
tal_count(d->current_routehint));
plugin_log(p->plugin, LOG_DBG, "Using routehint %s (%s) cltv_delta=%d",
type_to_string(tmpctx, struct node_id, &d->current_routehint->pubkey),
type_to_string(tmpctx, struct short_channel_id, &d->current_routehint->short_channel_id),
d->current_routehint->cltv_expiry_delta
);
}
routehint_pre_getroute(d, p);
} else if (p->step == PAYMENT_STEP_GOT_ROUTE && d->current_routehint != NULL) {
/* Now it's time to stitch the two partial routes together. */
struct amount_msat dest_amount;

Loading…
Cancel
Save