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>
@@ -1165,6 +1166,38 @@ static struct command_result *createlayer_fail(struct command *cmd,
11651166 return payment_continue (payment );
11661167}
11671168
1169+ static struct command_result * remove_layer_done (struct command * cmd ,
1170+ const char * method UNUSED ,
1171+ const char * buf UNUSED ,
1172+ const jsmntok_t * tok UNUSED ,
1173+ struct payment * payment UNUSED )
1174+ {
1175+ return timer_complete (cmd );
1176+ }
1177+ static struct command_result * remove_layer_fail (struct command * cmd ,
1178+ const char * method ,
1179+ const char * buf ,
1180+ const jsmntok_t * tok ,
1181+ struct payment * payment )
1182+ {
1183+ plugin_log (cmd -> plugin , LOG_UNUSUAL , "%s failed: '%.*s'" , method ,
1184+ json_tok_full_len (tok ), json_tok_full (buf , tok ));
1185+ return remove_layer_done (cmd , method , buf , tok , payment );
1186+ }
1187+
1188+ static struct command_result * remove_payment_layer (struct command * cmd ,
1189+ struct payment * payment )
1190+ {
1191+
1192+ struct out_req * req = jsonrpc_request_start (cmd , "askrene-remove-layer" ,
1193+ remove_layer_done ,
1194+ remove_layer_fail , payment );
1195+ json_add_string (req -> js , "layer" , payment -> payment_layer );
1196+ plugin_log (cmd -> plugin , LOG_DBG , "removing payment layer: %s" ,
1197+ payment -> payment_layer );
1198+ return send_outreq (req );
1199+ }
1200+
11681201static struct command_result * initpaymentlayer_cb (struct payment * payment )
11691202{
11701203 struct command * cmd = payment_command (payment );
@@ -1173,8 +1206,12 @@ static struct command_result *initpaymentlayer_cb(struct payment *payment)
11731206 createlayer_done , createlayer_fail , payment );
11741207 json_add_string (req -> js , "layer" , payment -> payment_layer );
11751208 json_add_bool (req -> js , "persistent" , false);
1176- // FIXME: add automatic expiration? see PR 7963
1177- // json_add_u64(req->js, "expiration", 24*60*60); // 24 hours
1209+ /* Remove this payment layer after one hour. If the plugin crashes
1210+ * unexpectedly, we might "leak" by forgetting to remove the layer, but
1211+ * the layer is not persistent anyways, therefore restarting CLN will
1212+ * remove it. */
1213+ notleak (global_timer (cmd -> plugin , time_from_sec (3600 ),
1214+ remove_payment_layer , payment ));
11781215 return send_outreq (req );
11791216}
11801217
0 commit comments