From 135180c1a07a01617c811f774ea007d263d9c76f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 10 Aug 2023 09:31:17 +0930 Subject: [PATCH] renepay: don't re-parse bolt11 to get routehints. Signed-off-by: Rusty Russell --- plugins/renepay/pay.c | 9 +++++---- plugins/renepay/uncertainty_network.c | 24 ++++++++---------------- plugins/renepay/uncertainty_network.h | 3 ++- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index 9eaaa3117..46c5d9aa5 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -853,6 +853,7 @@ static struct command_result *json_pay(struct command *cmd, u64 *min_prob_success_millionths; bool *use_shadow; u16 final_cltv; + const struct route_info **routes = NULL; if (!param(cmd, buf, params, p_req("invstring", param_invstring, &invstr), @@ -882,7 +883,6 @@ static struct command_result *json_pay(struct command *cmd, return command_param_failed(); /* We might need to parse invstring to get amount */ - bool invstr_is_b11=false; if (!bolt12_has_prefix(invstr)) { struct bolt11 *b11; char *fail; @@ -893,7 +893,6 @@ static struct command_result *json_pay(struct command *cmd, if (b11 == NULL) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Invalid bolt11: %s", fail); - invstr_is_b11=true; invmsat = b11->msat; invexpiry = b11->timestamp + b11->expiry; @@ -933,6 +932,9 @@ static struct command_result *json_pay(struct command *cmd, JSONRPC2_INVALID_PARAMS, "bolt11 uses description_hash, but you did not provide description parameter"); } + + routes = cast_const2(const struct route_info **, + b11->routes); } else { // TODO(eduardo): check this, compare with `pay` const struct tlv_invoice *b12; @@ -1116,8 +1118,7 @@ static struct command_result *json_pay(struct command *cmd, // TODO(eduardo): are there route hints for B12? // Add any extra hidden channel revealed by the routehints to the uncertainty network. - if(invstr_is_b11) - uncertainty_network_add_routehints(pay_plugin->chan_extra_map, payment); + uncertainty_network_add_routehints(pay_plugin->chan_extra_map, routes, payment); if(!uncertainty_network_check_invariants(pay_plugin->chan_extra_map)) plugin_log(pay_plugin->plugin, diff --git a/plugins/renepay/uncertainty_network.c b/plugins/renepay/uncertainty_network.c index 0d5db6e7a..832d7fb7f 100644 --- a/plugins/renepay/uncertainty_network.c +++ b/plugins/renepay/uncertainty_network.c @@ -41,7 +41,7 @@ bool uncertainty_network_check_invariants(struct chan_extra_map *chan_extra_map) static void add_hintchan( struct chan_extra_map *chan_extra_map, - struct payment *payment, + struct gossmap_localmods *local_gossmods, const struct node_id *src, const struct node_id *dst, u16 cltv_expiry_delta, @@ -63,9 +63,9 @@ static void add_hintchan( scid, MAX_CAP); /* FIXME: features? */ - gossmap_local_addchan(payment->local_gossmods, + gossmap_local_addchan(local_gossmods, src, dst, &scid, NULL); - gossmap_local_updatechan(payment->local_gossmods, + gossmap_local_updatechan(local_gossmods, &scid, /* We assume any HTLC is allowed */ AMOUNT_MSAT(0), MAX_CAP, @@ -84,26 +84,18 @@ static void add_hintchan( /* Add routehints provided by bolt11 */ void uncertainty_network_add_routehints( struct chan_extra_map *chan_extra_map, + const struct route_info **routes, struct payment *p) { - struct bolt11 *b11; - char *fail; - - b11 = - bolt11_decode(tmpctx, p->invstr, - plugin_feature_set(p->cmd->plugin), - p->description, chainparams, &fail); - if (b11 == NULL) - debug_err("add_routehints: Invalid bolt11: %s", fail); - - for (size_t i = 0; i < tal_count(b11->routes); i++) { + for (size_t i = 0; i < tal_count(routes); i++) { /* Each one, presumably, leads to the destination */ - const struct route_info *r = b11->routes[i]; + const struct route_info *r = routes[i]; const struct node_id *end = & p->destination; for (int j = tal_count(r)-1; j >= 0; j--) { add_hintchan( chan_extra_map, - p, &r[j].pubkey, end, + p->local_gossmods, + &r[j].pubkey, end, r[j].cltv_expiry_delta, r[j].short_channel_id, r[j].fee_base_msat, diff --git a/plugins/renepay/uncertainty_network.h b/plugins/renepay/uncertainty_network.h index d07c627a3..fda20e024 100644 --- a/plugins/renepay/uncertainty_network.h +++ b/plugins/renepay/uncertainty_network.h @@ -14,7 +14,8 @@ bool uncertainty_network_check_invariants(struct chan_extra_map *chan_extra_map) /* Add routehints provided by bolt11 */ void uncertainty_network_add_routehints( struct chan_extra_map *chan_extra_map, - struct payment *payment); + const struct route_info **routes, + struct payment *p); /* Mirror the gossmap in the public uncertainty network. * result: Every channel in gossmap must have associated data in chan_extra_map,