Skip to content

Commit

Permalink
renepay: bugfix assertion htlc_total<=known_max
Browse files Browse the repository at this point in the history
Make knowledge update and removal of pending HTLCs atomic
to avoid race conditions.

Changelog-EXPERIMENTAL: renepay: fixed: make knowledge update and removal of pending HTLCs atomic to avoid race conditions.

Signed-off-by: Lagrang3 <[email protected]>
  • Loading branch information
Lagrang3 committed Aug 14, 2024
1 parent fb3579c commit d07117d
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions plugins/renepay/routetracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ static void routetracker_add_to_final(struct routetracker *routetracker,
}
}

static void route_success_register(struct routetracker *routetracker,
struct route *route)
static void route_success_update_knowledge(struct route *route,
struct uncertainty *uncertainty)
{
if(route->hops){
uncertainty_route_success(pay_plugin->uncertainty, route);
}
routetracker_add_to_final(routetracker, route);
if (route->hops)
uncertainty_route_success(uncertainty, route);
}
void route_failure_register(struct routetracker *routetracker,
struct route *route)

static void route_failure_update_knowledge(struct route *route,
struct uncertainty *uncertainty)
{
struct payment_result *result = route->result;
assert(result);
Expand Down Expand Up @@ -135,6 +134,24 @@ void route_failure_register(struct routetracker *routetracker,
route->hops[last_good_channel + 1].direction);
}
}
}

static void route_success_register(struct routetracker *routetracker,
struct route *route)
{
/* Delay the knowledge update to destruction so that updating the
* knowledge and htlc removal happens atomically. */
tal_add_destructor2(route, route_success_update_knowledge,
pay_plugin->uncertainty);
routetracker_add_to_final(routetracker, route);
}
void route_failure_register(struct routetracker *routetracker,
struct route *route)
{
/* Delay the knowledge update to destruction so that updating the
* knowledge and htlc removal happens atomically. */
tal_add_destructor2(route, route_failure_update_knowledge,
pay_plugin->uncertainty);
routetracker_add_to_final(routetracker, route);
}

Expand Down

0 comments on commit d07117d

Please sign in to comment.