Skip to content

Commit e7ad61c

Browse files
committed
renepay: timer to remove payment layer after 1h
Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent 8252f5b commit e7ad61c

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

plugins/renepay/mods.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <common/bolt11.h>
66
#include <common/gossmods_listpeerchannels.h>
77
#include <common/json_stream.h>
8+
#include <common/memleak.h>
89
#include <plugins/renepay/json.h>
910
#include <plugins/renepay/mcf.h>
1011
#include <plugins/renepay/mods.h>
@@ -1167,6 +1168,38 @@ static struct command_result *createlayer_fail(struct command *cmd,
11671168
return payment_continue(payment);
11681169
}
11691170

1171+
static struct command_result *remove_layer_done(struct command *cmd,
1172+
const char *method UNUSED,
1173+
const char *buf UNUSED,
1174+
const jsmntok_t *tok UNUSED,
1175+
struct payment *payment UNUSED)
1176+
{
1177+
return timer_complete(cmd);
1178+
}
1179+
static struct command_result *remove_layer_fail(struct command *cmd,
1180+
const char *method,
1181+
const char *buf,
1182+
const jsmntok_t *tok,
1183+
struct payment *payment)
1184+
{
1185+
plugin_log(cmd->plugin, LOG_UNUSUAL, "%s failed: '%.*s'", method,
1186+
json_tok_full_len(tok), json_tok_full(buf, tok));
1187+
return remove_layer_done(cmd, method, buf, tok, payment);
1188+
}
1189+
1190+
static struct command_result *remove_payment_layer(struct command *cmd,
1191+
struct payment *payment)
1192+
{
1193+
1194+
struct out_req *req = jsonrpc_request_start(cmd, "askrene-remove-layer",
1195+
remove_layer_done,
1196+
remove_layer_fail, payment);
1197+
json_add_string(req->js, "layer", payment->payment_layer);
1198+
plugin_log(cmd->plugin, LOG_DBG, "removing payment layer: %s",
1199+
payment->payment_layer);
1200+
return send_outreq(req);
1201+
}
1202+
11701203
static struct command_result *initpaymentlayer_cb(struct payment *payment)
11711204
{
11721205
struct command *cmd = payment_command(payment);
@@ -1175,8 +1208,12 @@ static struct command_result *initpaymentlayer_cb(struct payment *payment)
11751208
createlayer_done, createlayer_fail, payment);
11761209
json_add_string(req->js, "layer", payment->payment_layer);
11771210
json_add_bool(req->js, "persistent", false);
1178-
// FIXME: add automatic expiration? see PR 7963
1179-
// json_add_u64(req->js, "expiration", 24*60*60); // 24 hours
1211+
/* Remove this payment layer after one hour. If the plugin crashes
1212+
* unexpectedly, we might "leak" by forgetting to remove the layer, but
1213+
* the layer is not persistent anyways, therefore restarting CLN will
1214+
* remove it. */
1215+
notleak(global_timer(cmd->plugin, time_from_sec(3600),
1216+
remove_payment_layer, payment));
11801217
return send_outreq(req);
11811218
}
11821219

0 commit comments

Comments
 (0)