Skip to content

Commit 07d4451

Browse files
Lagrang3rustyrussell
authored andcommitted
renepay: bugfix reading pending sendpays
When renepay starts, one of the first operations it does is to check for pending sendpays for the same invoice. Those are added up to an internal database to keep track of. Also the amount they deliver to the destination is computed so that the current payment rpc call would try to complete the payment for whatever amount remains to pay. For an incomplete payment after calling the RPC renepay I found this in the logs: 2024-05-22T19:44:19.853Z DEBUG plugin-cln-renepay: There are pending sendpays to this invoice. groupid = 6 delivering = 0msat, last_partid = 10 Where delivering should be the sum of the amounts delivered by pending routes.
1 parent aa45e73 commit 07d4451

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

plugins/renepay/mods.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ static struct command_result *previous_sendpays_done(struct command *cmd,
253253
// max_partid for the pending_group_id
254254
payment->next_partid = max_pending_partid + 1;
255255

256+
for (size_t j = 0; j < tal_count(pending_routes); j++) {
257+
route_pending_register(payment->routetracker,
258+
pending_routes[j]);
259+
}
260+
if (!routetracker_get_amount(payment->routetracker,
261+
&payment->total_delivering,
262+
&payment->total_sent))
263+
plugin_err(pay_plugin->plugin,
264+
"(%s:%d) routetracker_get_amount failed "
265+
"probably due to an amount_msat overflow.",
266+
__PRETTY_FUNCTION__, __LINE__);
267+
256268
plugin_log(pay_plugin->plugin, LOG_DBG,
257269
"There are pending sendpays to this invoice. "
258270
"groupid = %" PRIu32 " "
@@ -271,12 +283,6 @@ static struct command_result *previous_sendpays_done(struct command *cmd,
271283
"Payment is pending with full amount "
272284
"already commited");
273285
}
274-
275-
for (size_t j = 0; j < tal_count(pending_routes); j++) {
276-
route_pending_register(payment->routetracker,
277-
pending_routes[j]);
278-
}
279-
280286
} else {
281287
/* There are no pending nor completed sendpays, get me the last
282288
* sendpay group. */

plugins/renepay/routetracker.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@ void route_pending_register(struct routetracker *routetracker,
134134
}
135135
}
136136

137+
bool routetracker_get_amount(struct routetracker *routetracker,
138+
struct amount_msat *amount,
139+
struct amount_msat *amount_sent)
140+
{
141+
assert(routetracker);
142+
assert(amount);
143+
assert(amount_sent);
144+
145+
*amount = AMOUNT_MSAT(0);
146+
*amount_sent = AMOUNT_MSAT(0);
147+
148+
struct route_map *rmap = routetracker->pending_routes;
149+
struct route_map_iter it;
150+
for (struct route *r = route_map_first(rmap, &it); r;
151+
r = route_map_next(rmap, &it)) {
152+
if (!amount_msat_add(amount, *amount, route_delivers(r)) ||
153+
!amount_msat_add(amount_sent, *amount_sent, route_sends(r)))
154+
return false;
155+
}
156+
return true;
157+
}
158+
137159
static void route_result_collected(struct routetracker *routetracker,
138160
struct route *route TAKES)
139161
{

plugins/renepay/routetracker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ struct command_result *notification_sendpay_success(struct command *cmd,
5050
void route_failure_register(struct routetracker *routetracker,
5151
struct route *route);
5252

53+
/* How much is the amount being tracked. */
54+
bool routetracker_get_amount(struct routetracker *routetracker,
55+
struct amount_msat *amount,
56+
struct amount_msat *amount_sent);
57+
5358
// FIXME: double-check that we actually get one notification for each sendpay,
5459
// ie. that after some time we don't have yet pending sendpays for old failed or
5560
// successful payments that we havent processed because we haven't received the

0 commit comments

Comments
 (0)