From b1e9f4923b89c728ebb311fbb97d4777853eb70e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 21 May 2020 23:24:30 +0200 Subject: [PATCH] paymod: Add the final cltv delta to the getroute call --- plugins/libplugin-pay.c | 5 +++++ plugins/libplugin-pay.h | 4 ++++ plugins/pay.c | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 48b443e41..852e35a4d 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -7,6 +7,8 @@ #include #include +#define DEFAULT_FINAL_CLTV_DELTA 9 + /* Just a container to collect a subtree result so we can summarize all * sub-payments and return a reasonable result to the caller of `pay` */ struct payment_tree_result { @@ -35,12 +37,14 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd, p->cmd = cmd; p->start_time = time_now(); p->result = NULL; + p->getroute_cltv = DEFAULT_FINAL_CLTV_DELTA; /* Copy over the relevant pieces of information. */ if (parent != NULL) { assert(cmd == NULL); tal_arr_expand(&parent->children, p); p->destination = p->getroute_destination = parent->destination; + p->getroute_cltv = parent->getroute_cltv; p->amount = parent->amount; p->payment_hash = parent->payment_hash; p->partid = payment_root(p->parent)->next_partid++; @@ -241,6 +245,7 @@ static void payment_getroute(struct payment *p) json_add_node_id(req->js, "id", p->getroute_destination); json_add_amount_msat_only(req->js, "msatoshi", p->amount); json_add_num(req->js, "riskfactor", 1); + json_add_num(req->js, "cltv", p->getroute_cltv); send_outreq(p->plugin, req); } diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index c6c518f66..f175d7988 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -2,6 +2,7 @@ #define LIGHTNING_PLUGINS_LIBPLUGIN_PAY_H #include "config.h" +#include #include #include @@ -129,6 +130,7 @@ struct payment { * the above destination if we use rendez-vous routing of blinded * paths to amend the route later in a mixin. */ struct node_id *getroute_destination; + u32 getroute_cltv; struct createonion_request *createonion_request; struct createonion_response *createonion_response; @@ -164,6 +166,8 @@ struct payment { void **modifier_data; int current_modifier; + struct bolt11 *invoice; + struct payment_result *result; }; diff --git a/plugins/pay.c b/plugins/pay.c index d5ca0ffba..f8fbf83e8 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1769,7 +1769,10 @@ static struct command_result *json_paymod(struct command *cmd, p->json_toks = params; p->destination = p->getroute_destination = &b11->receiver_id; p->payment_hash = tal_dup(p, struct sha256, &b11->payment_hash); - p->payment_secret = tal_dup(p, struct secret, b11->payment_secret); + p->payment_secret = b11->payment_secret + ? tal_dup(p, struct secret, b11->payment_secret) + : NULL; + p->invoice = tal_steal(p, b11); payment_start(p); list_add_tail(&payments, &p->list);