From 54d3b712c3b2e797c0e4ed42c3a274149ec40f7a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 23 Jul 2020 14:14:40 +0200 Subject: [PATCH] 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. --- plugins/libplugin-pay.c | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index bf103eb8e..282699711 100644 --- a/plugins/libplugin-pay.c +++ b/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;