Skip to content

Commit 98e8fa0

Browse files
committed
renepay: unreserve completed routes
Use askrene-unreserve to remove reserved liquidity associated with routes that have completed, either by success or failure. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
1 parent a797e00 commit 98e8fa0

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

plugins/renepay/mods.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,54 @@ static struct command_result *sendroutes_done(struct command *cmd,
601601
return payment_continue(payment);
602602
}
603603

604+
static struct command_result *unreserve_done(struct command *aux_cmd,
605+
const char *method UNUSED,
606+
const char *buf UNUSED,
607+
const jsmntok_t *result UNUSED,
608+
struct route *route UNUSED)
609+
{
610+
return aux_command_done(aux_cmd);
611+
}
612+
613+
static struct command_result *
614+
unreserve_fail(struct command *aux_cmd, const char *method, const char *buf,
615+
const jsmntok_t *result, struct route *route UNUSED)
616+
{
617+
plugin_log(aux_cmd->plugin, LOG_UNUSUAL, "%s failed: %.*s", method,
618+
json_tok_full_len(result), json_tok_full(buf, result));
619+
return aux_command_done(aux_cmd);
620+
}
621+
622+
static void unreserve_route(struct route *route, struct command *aux_cmd)
623+
{
624+
struct out_req *req =
625+
jsonrpc_request_start(aux_cmd, "askrene-unreserve", unreserve_done,
626+
unreserve_fail, route);
627+
json_array_start(req->js, "path");
628+
for (size_t i = 0; i < tal_count(route->hops); i++) {
629+
const struct route_hop *hop = &route->hops[i];
630+
struct short_channel_id_dir scidd = {.scid = hop->scid,
631+
.dir = hop->direction};
632+
json_object_start(req->js, NULL);
633+
json_add_short_channel_id_dir(req->js, "short_channel_id_dir",
634+
scidd);
635+
json_add_amount_msat(req->js, "amount_msat", hop->amount);
636+
json_object_end(req->js);
637+
}
638+
json_array_end(req->js);
639+
send_outreq(req);
640+
}
641+
604642
static struct command_result *reserve_done(struct command *cmd,
605643
const char *method UNUSED,
606644
const char *buf UNUSED,
607645
const jsmntok_t *result UNUSED,
608-
struct route *route UNUSED)
646+
struct route *route)
609647
{
648+
/* A new command is issued to handle the destruction of this route.
649+
* I hope aux_cmd outlives the current payment session cmd. */
650+
struct command *aux_cmd = aux_command(cmd);
651+
tal_add_destructor2(route, unreserve_route, aux_cmd);
610652
return command_still_pending(cmd);
611653
}
612654

0 commit comments

Comments
 (0)