From ca72a230f39b9f2246bbd93c80694709a794c2e9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 9 Aug 2023 11:46:58 +0930 Subject: [PATCH] renepay: fix localmods. You cannot refresh the gossmap with localmods applied, nor apply localmods when others have applied localmods in the same process. There are optimizations we could do, but for now always apply/unapply before querying gossmap. Signed-off-by: Rusty Russell --- plugins/renepay/pay.c | 6 ++---- plugins/renepay/payment.c | 12 ------------ plugins/renepay/payment.h | 1 - 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index 2c634b331..9af3e6c6f 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -546,6 +546,7 @@ static struct command_result *try_paying(struct command *cmd, /* We let this return an unlikely path, as it's better to try once * than simply refuse. Plus, models are not truth! */ + gossmap_apply_localmods(pay_plugin->gossmap, renepay->local_gossmods); struct pay_flow **pay_flows = get_payflows( renepay, remaining, feebudget, @@ -558,6 +559,7 @@ static struct command_result *try_paying(struct command *cmd, amount_msat_eq(p->total_delivering, AMOUNT_MSAT(0)), &err_msg); + gossmap_remove_localmods(pay_plugin->gossmap, renepay->local_gossmods); // plugin_log(pay_plugin->plugin,LOG_DBG,"get_payflows produced %s",fmt_payflows(tmpctx,pay_flows)); @@ -590,13 +592,9 @@ static struct command_result *listpeerchannels_done( "listpeerchannels malformed: %.*s", json_tok_full_len(result), json_tok_full(buf, result)); - // So we have all localmods data, now we apply it. Only once per - // payment. // TODO(eduardo): check that there won't be a prob. cost associated with // any gossmap local chan. The same way there aren't fees to pay for my // local channels. - gossmap_apply_localmods(pay_plugin->gossmap,renepay->local_gossmods); - renepay->localmods_applied=true; return try_paying(cmd, renepay, true); } diff --git a/plugins/renepay/payment.c b/plugins/renepay/payment.c index de3a48af2..8eb070b80 100644 --- a/plugins/renepay/payment.c +++ b/plugins/renepay/payment.c @@ -49,7 +49,6 @@ struct renepay * renepay_new(struct command *cmd) renepay->cmd = cmd; renepay->payment = payment_new(renepay); - renepay->localmods_applied=false; renepay->local_gossmods = gossmap_localmods_new(renepay); renepay->disabled = tal_arr(renepay,struct short_channel_id,0); renepay->rexmit_timer = NULL; @@ -190,21 +189,10 @@ void renepay_cleanup( struct gossmap * gossmap) { debug_info("calling %s",__PRETTY_FUNCTION__); - /* Always remove our local mods (routehints) so others can use - * gossmap. We do this only after the payment completes. */ // TODO(eduardo): it can happen that local_gossmods removed below // contained a set of channels for which there is information in the // uncertainty network (chan_extra_map) and that are part of some pending // payflow (payflow_map). Handle this situation. - if(renepay->localmods_applied) - gossmap_remove_localmods(gossmap, - renepay->local_gossmods); - // TODO(eduardo): I wonder if it is possible to have two instances of - // renepay at the same time. - // 1st problem: dijkstra datastructure is global, this can be fixed, - // 2nd problem: we don't know if gossmap_apply_localmods and gossmap_remove_localmods, - // can handle different local_gossmods applied to the same gossmap. - renepay->localmods_applied=false; tal_free(renepay->local_gossmods); renepay->rexmit_timer = tal_free(renepay->rexmit_timer); diff --git a/plugins/renepay/payment.h b/plugins/renepay/payment.h index 74ccabe3a..471fda906 100644 --- a/plugins/renepay/payment.h +++ b/plugins/renepay/payment.h @@ -111,7 +111,6 @@ struct renepay struct payment * payment; /* Localmods to apply to gossip_map for our own use. */ - bool localmods_applied; struct gossmap_localmods *local_gossmods; /* Channels we decided to disable for various reasons. */