From 10f231bcb5bc86276312fafad6864b17092bc5fb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 22 May 2020 17:40:18 +0200 Subject: [PATCH] paymod: Include excludes resulting from channel_hints for getrotue --- plugins/libplugin-pay.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 8f25bdce6..92793a912 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -237,6 +237,28 @@ static struct command_result *payment_getroute_error(struct command *cmd, return command_still_pending(cmd); } +/* Iterate through the channel_hints and exclude any channel that we are + * confident will not be able to handle this payment. */ +static void payment_getroute_add_excludes(struct payment *p, + struct json_stream *js) +{ + struct payment *root = payment_root(p); + struct channel_hint *hint; + + json_array_start(js, "exclude"); + for (size_t i = 0; i < tal_count(root->channel_hints); i++) { + hint = &root->channel_hints[i]; + + if (!hint->enabled) + json_add_short_channel_id_dir(js, NULL, &hint->scid); + + else if (amount_msat_greater_eq(p->amount, + hint->estimated_capacity)) + json_add_short_channel_id_dir(js, NULL, &hint->scid); + } + json_array_end(js); +} + static void payment_getroute(struct payment *p) { struct out_req *req; @@ -247,6 +269,7 @@ static void payment_getroute(struct payment *p) 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); + payment_getroute_add_excludes(p, req->js); send_outreq(p->plugin, req); }