From 6a1776d31246e159b3be31403e6c86b496c5f12a Mon Sep 17 00:00:00 2001 From: Lagrang3 Date: Tue, 4 Jun 2024 08:51:42 +0100 Subject: [PATCH] renepay: rm HTLCs from uncertainty on route free Add remove_htlc in the route destructor. Signed-off-by: Lagrang3 --- plugins/renepay/payplugin.h | 4 +++- plugins/renepay/routebuilder.c | 7 ------- plugins/renepay/routetracker.c | 15 +++++++-------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/plugins/renepay/payplugin.h b/plugins/renepay/payplugin.h index 7c647ad56..8e3f50b90 100644 --- a/plugins/renepay/payplugin.h +++ b/plugins/renepay/payplugin.h @@ -63,7 +63,9 @@ struct pay_plugin { /* Per-channel metadata: some persists between payments */ struct uncertainty *uncertainty; - /* Pending sendpays (to match notifications to). */ + /* Pending sendpays. Each pending route has an associated HTLC data in + * the uncertainty network. Pending routes are matched against sendpay + * notifications. */ struct route_map *pending_routes; bool debug_mcf; diff --git a/plugins/renepay/routebuilder.c b/plugins/renepay/routebuilder.c index 43d97e400..b85a4379a 100644 --- a/plugins/renepay/routebuilder.c +++ b/plugins/renepay/routebuilder.c @@ -5,13 +5,6 @@ #include -// static void uncertainty_commit_routes(struct uncertainty *uncertainty, -// struct route **routes) -// { -// const size_t N = tal_count(routes); -// for (size_t i = 0; i < N; i++) -// uncertainty_commit_htlcs(uncertainty, routes[i]); -// } static void uncertainty_remove_routes(struct uncertainty *uncertainty, struct route **routes) { diff --git a/plugins/renepay/routetracker.c b/plugins/renepay/routetracker.c index 9029d80ef..8f0f0d9dc 100644 --- a/plugins/renepay/routetracker.c +++ b/plugins/renepay/routetracker.c @@ -56,7 +56,6 @@ static void route_success_register(struct routetracker *routetracker, { if(route->hops){ uncertainty_route_success(pay_plugin->uncertainty, route); - uncertainty_remove_htlcs(pay_plugin->uncertainty, route); } routetracker_add_to_final(routetracker, route); } @@ -99,7 +98,6 @@ void route_failure_register(struct routetracker *routetracker, route->hops[last_good_channel + 1].scid, route->hops[last_good_channel + 1].direction); } - uncertainty_remove_htlcs(pay_plugin->uncertainty, route); } routetracker_add_to_final(routetracker, route); } @@ -107,6 +105,7 @@ void route_failure_register(struct routetracker *routetracker, static void remove_route(struct route *route, struct route_map *map) { route_map_del(map, route); + uncertainty_remove_htlcs(pay_plugin->uncertainty, route); } /* This route is pending, ie. locked in HTLCs. @@ -139,7 +138,7 @@ static void route_pending_register(struct routetracker *routetracker, uncertainty_commit_htlcs(pay_plugin->uncertainty, route); - if (!tal_steal(pay_plugin, route) || + if (!tal_steal(pay_plugin->pending_routes, route) || !route_map_add(pay_plugin->pending_routes, route) || !tal_add_destructor2(route, remove_route, pay_plugin->pending_routes)) @@ -243,8 +242,7 @@ void payment_collect_results(struct payment *payment, *payment_preimage = tal_dup(tmpctx, struct preimage, r->result->payment_preimage); - tal_free(r); - continue; + break; } /* We should never start a new groupid while there are pending @@ -258,7 +256,6 @@ void payment_collect_results(struct payment *payment, "groupid=%" PRIu64, __PRETTY_FUNCTION__, payment->groupid, r->key.groupid); - tal_free(r); continue; } @@ -283,8 +280,9 @@ void payment_collect_results(struct payment *payment, "payment total amount.", __PRETTY_FUNCTION__); } - tal_free(r); } + for (size_t i = 0; i < ncompleted; i++) + tal_free(routetracker->finalized_routes[i]); tal_resize(&routetracker->finalized_routes, 0); } @@ -401,6 +399,8 @@ struct command_result *notification_sendpay_success(struct command *cmd, struct route *route = route_map_get(pay_plugin->pending_routes, key); if (!route) { + /* This route was not created by us, make a basic route + * information dummy without hop details to pass onward. */ route = tal_route_from_json(tmpctx, buf, sub); if(!route) plugin_err(pay_plugin->plugin, @@ -416,7 +416,6 @@ struct command_result *notification_sendpay_success(struct command *cmd, json_tok_full_len(sub), json_tok_full(buf, sub)); assert(route->result->status == SENDPAY_COMPLETE); - // TODO: knowledge update here route_success_register(payment->routetracker, route); return notification_handled(cmd); }