renepay: don't re-parse bolt11 to get routehints.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-08-10 09:31:17 +09:30
parent 2ceac6c11d
commit 135180c1a0
3 changed files with 15 additions and 21 deletions

View File

@@ -853,6 +853,7 @@ static struct command_result *json_pay(struct command *cmd,
u64 *min_prob_success_millionths; u64 *min_prob_success_millionths;
bool *use_shadow; bool *use_shadow;
u16 final_cltv; u16 final_cltv;
const struct route_info **routes = NULL;
if (!param(cmd, buf, params, if (!param(cmd, buf, params,
p_req("invstring", param_invstring, &invstr), p_req("invstring", param_invstring, &invstr),
@@ -882,7 +883,6 @@ static struct command_result *json_pay(struct command *cmd,
return command_param_failed(); return command_param_failed();
/* We might need to parse invstring to get amount */ /* We might need to parse invstring to get amount */
bool invstr_is_b11=false;
if (!bolt12_has_prefix(invstr)) { if (!bolt12_has_prefix(invstr)) {
struct bolt11 *b11; struct bolt11 *b11;
char *fail; char *fail;
@@ -893,7 +893,6 @@ static struct command_result *json_pay(struct command *cmd,
if (b11 == NULL) if (b11 == NULL)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid bolt11: %s", fail); "Invalid bolt11: %s", fail);
invstr_is_b11=true;
invmsat = b11->msat; invmsat = b11->msat;
invexpiry = b11->timestamp + b11->expiry; invexpiry = b11->timestamp + b11->expiry;
@@ -933,6 +932,9 @@ static struct command_result *json_pay(struct command *cmd,
JSONRPC2_INVALID_PARAMS, JSONRPC2_INVALID_PARAMS,
"bolt11 uses description_hash, but you did not provide description parameter"); "bolt11 uses description_hash, but you did not provide description parameter");
} }
routes = cast_const2(const struct route_info **,
b11->routes);
} else { } else {
// TODO(eduardo): check this, compare with `pay` // TODO(eduardo): check this, compare with `pay`
const struct tlv_invoice *b12; 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? // TODO(eduardo): are there route hints for B12?
// Add any extra hidden channel revealed by the routehints to the uncertainty network. // 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, routes, payment);
uncertainty_network_add_routehints(pay_plugin->chan_extra_map, payment);
if(!uncertainty_network_check_invariants(pay_plugin->chan_extra_map)) if(!uncertainty_network_check_invariants(pay_plugin->chan_extra_map))
plugin_log(pay_plugin->plugin, plugin_log(pay_plugin->plugin,

View File

@@ -41,7 +41,7 @@ bool uncertainty_network_check_invariants(struct chan_extra_map *chan_extra_map)
static void add_hintchan( static void add_hintchan(
struct chan_extra_map *chan_extra_map, struct chan_extra_map *chan_extra_map,
struct payment *payment, struct gossmap_localmods *local_gossmods,
const struct node_id *src, const struct node_id *src,
const struct node_id *dst, const struct node_id *dst,
u16 cltv_expiry_delta, u16 cltv_expiry_delta,
@@ -63,9 +63,9 @@ static void add_hintchan(
scid, scid,
MAX_CAP); MAX_CAP);
/* FIXME: features? */ /* FIXME: features? */
gossmap_local_addchan(payment->local_gossmods, gossmap_local_addchan(local_gossmods,
src, dst, &scid, NULL); src, dst, &scid, NULL);
gossmap_local_updatechan(payment->local_gossmods, gossmap_local_updatechan(local_gossmods,
&scid, &scid,
/* We assume any HTLC is allowed */ /* We assume any HTLC is allowed */
AMOUNT_MSAT(0), MAX_CAP, AMOUNT_MSAT(0), MAX_CAP,
@@ -84,26 +84,18 @@ static void add_hintchan(
/* Add routehints provided by bolt11 */ /* Add routehints provided by bolt11 */
void uncertainty_network_add_routehints( void uncertainty_network_add_routehints(
struct chan_extra_map *chan_extra_map, struct chan_extra_map *chan_extra_map,
const struct route_info **routes,
struct payment *p) struct payment *p)
{ {
struct bolt11 *b11; for (size_t i = 0; i < tal_count(routes); i++) {
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++) {
/* Each one, presumably, leads to the destination */ /* 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; const struct node_id *end = & p->destination;
for (int j = tal_count(r)-1; j >= 0; j--) { for (int j = tal_count(r)-1; j >= 0; j--) {
add_hintchan( add_hintchan(
chan_extra_map, chan_extra_map,
p, &r[j].pubkey, end, p->local_gossmods,
&r[j].pubkey, end,
r[j].cltv_expiry_delta, r[j].cltv_expiry_delta,
r[j].short_channel_id, r[j].short_channel_id,
r[j].fee_base_msat, r[j].fee_base_msat,

View File

@@ -14,7 +14,8 @@ bool uncertainty_network_check_invariants(struct chan_extra_map *chan_extra_map)
/* Add routehints provided by bolt11 */ /* Add routehints provided by bolt11 */
void uncertainty_network_add_routehints( void uncertainty_network_add_routehints(
struct chan_extra_map *chan_extra_map, 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. /* Mirror the gossmap in the public uncertainty network.
* result: Every channel in gossmap must have associated data in chan_extra_map, * result: Every channel in gossmap must have associated data in chan_extra_map,