Skip to content

Commit 4ae1b5a

Browse files
committed
renepay: reserve liquidity for routes
Use askrene-reserve API to lock-in the liquidity of the channels in use for pending payment route. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
1 parent e7bf796 commit 4ae1b5a

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

plugins/renepay/mods.c

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

604+
static struct command_result *reserve_done(struct command *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 command_still_pending(cmd);
611+
}
612+
613+
static struct command_result *reserve_fail(struct command *cmd,
614+
const char *method UNUSED,
615+
const char *buf UNUSED,
616+
const jsmntok_t *result UNUSED,
617+
struct route *route)
618+
{
619+
plugin_log(cmd->plugin, LOG_UNUSUAL, "failed to reserve route (%s)",
620+
fmt_routekey(tmpctx, &route->key));
621+
return command_still_pending(cmd);
622+
}
623+
604624
/* Callback function for sendpay request success. */
605625
static struct command_result *
606626
renesendpay_done(struct command *cmd, const char *method UNUSED,
@@ -630,7 +650,22 @@ renesendpay_done(struct command *cmd, const char *method UNUSED,
630650
}
631651
} else
632652
route->shared_secrets = NULL;
633-
return command_still_pending(cmd);
653+
654+
struct out_req *req = jsonrpc_request_start(
655+
cmd, "askrene-reserve", reserve_done, reserve_fail, route);
656+
json_array_start(req->js, "path");
657+
for (i = 0; i < tal_count(route->hops); i++) {
658+
const struct route_hop *hop = &route->hops[i];
659+
struct short_channel_id_dir scidd = {.scid = hop->scid,
660+
.dir = hop->direction};
661+
json_object_start(req->js, NULL);
662+
json_add_short_channel_id_dir(req->js, "short_channel_id_dir",
663+
scidd);
664+
json_add_amount_msat(req->js, "amount_msat", hop->amount);
665+
json_object_end(req->js);
666+
}
667+
json_array_end(req->js);
668+
return send_outreq(req);
634669
}
635670

636671
/* FIXME: check when will renesendpay fail */

0 commit comments

Comments
 (0)