From 3424f70585e61103eaaae3bf5f443c57407abf97 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Tue, 21 Mar 2023 14:17:20 +0100 Subject: [PATCH] plugin: autoclean: cleanup the forwards with localfailed While we are cleaning up the list forwards with the autoclean plugin we are not taking into count the forward's payments with the status set to `local_failed`. In this case, the forwards have no resolved time because it was not resolved by us due to some local error. So, this commit is fixing the auto clean plugin by allowing to delete of the forwards with status set to local_failed by taking into count the received_time, with the assumption that the received_time, in this case, is equal to the resolved time (?) Reported-by: @denis2342 Link: https://github.com/ElementsProject/lightning/issues/6058 Signed-off-by: Vincenzo Palazzo Changelog-Fixed: plugin: autoclean: considerer the forwards with status set to `local_failed`. --- plugins/autoclean.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/autoclean.c b/plugins/autoclean.c index 8276bdda6..cb123c04d 100644 --- a/plugins/autoclean.c +++ b/plugins/autoclean.c @@ -301,6 +301,7 @@ static struct command_result *listforwards_done(struct command *cmd, json_for_each_arr(i, t, fwds) { const jsmntok_t *status = json_get_member(buf, t, "status"); + const char *timefield = "resolved_time"; jsmntok_t time; enum subsystem subsys; u64 restime; @@ -310,6 +311,8 @@ static struct command_result *listforwards_done(struct command *cmd, } else if (json_tok_streq(buf, status, "failed") || json_tok_streq(buf, status, "local_failed")) { subsys = FAILEDFORWARDS; + /* There's no resolved_time for these, so use received */ + timefield = "received_time"; } else { cinfo->num_uncleaned++; continue; @@ -324,12 +327,13 @@ static struct command_result *listforwards_done(struct command *cmd, /* Check if we have a resolved_time, before making a * decision on it. This is possible in older nodes * that predate our annotations for forwards.*/ - if (json_get_member(buf, t, "resolved_time") == NULL) { + if (json_get_member(buf, t, timefield) == NULL) { cinfo->num_uncleaned++; continue; } - time = *json_get_member(buf, t, "resolved_time"); + + time = *json_get_member(buf, t, timefield); /* This is a float, so truncate at '.' */ for (int off = time.start; off < time.end; off++) { if (buf[off] == '.')