MCPcopy Create free account
hub / github.com/ElementsProject/lightning / listforwards_done

Function listforwards_done

plugins/autoclean.c:296–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296static struct command_result *listforwards_done(struct command *cmd,
297 const char *buf,
298 const jsmntok_t *result,
299 struct clean_info *cinfo)
300{
301 const jsmntok_t *t, *fwds = json_get_member(buf, result, "forwards");
302 size_t i;
303 u64 now = time_now().ts.tv_sec;
304
305 json_for_each_arr(i, t, fwds) {
306 const jsmntok_t *status = json_get_member(buf, t, "status");
307 jsmntok_t time;
308 enum subsystem subsys;
309 u64 restime;
310
311 if (json_tok_streq(buf, status, "settled")) {
312 subsys = SUCCEEDEDFORWARDS;
313 } else if (json_tok_streq(buf, status, "failed")
314 || json_tok_streq(buf, status, "local_failed")) {
315 subsys = FAILEDFORWARDS;
316 } else {
317 cinfo->num_uncleaned++;
318 continue;
319 }
320
321 /* Continue if we don't care. */
322 if (cinfo->subsystem_age[subsys] == 0) {
323 cinfo->num_uncleaned++;
324 continue;
325 }
326
327 time = *json_get_member(buf, t, "resolved_time");
328 /* This is a float, so truncate at '.' */
329 for (int off = time.start; off < time.end; off++) {
330 if (buf[off] == '.')
331 time.end = off;
332 }
333 if (!json_to_u64(buf, &time, &restime)) {
334 plugin_err(plugin, "Bad time '%.*s'",
335 json_tok_full_len(&time),
336 json_tok_full(buf, &time));
337 }
338
339 if (restime <= now - cinfo->subsystem_age[subsys]) {
340 struct out_req *req;
341 const jsmntok_t *inchan, *inid;
342
343 inchan = json_get_member(buf, t, "in_channel");
344 inid = json_get_member(buf, t, "in_htlc_id");
345
346 req = del_request_start("delforward", cinfo, subsys);
347 json_add_tok(req->js, "in_channel", inchan, buf);
348 /* This can be missing if it was a forwards record from an old
349 * closed channel in version <= 0.12.1. This is a special value
350 * but we will delete them *all*, resulting in some failures! */
351#ifdef COMPAT_V0121
352 if (!inid)
353 json_add_u64(req->js, "in_htlc_id", -1ULL);

Callers

nothing calls this directly

Calls 13

time_nowFunction · 0.85
del_request_startFunction · 0.85
json_add_tokFunction · 0.85
clean_finishedFunction · 0.85
plugin_errFunction · 0.70
send_outreqFunction · 0.70
command_still_pendingFunction · 0.70
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50
json_to_u64Function · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected