From 4017844d0c4bd78381313e1028b0ab9e0c70836d Mon Sep 17 00:00:00 2001 From: Se7enZ Date: Wed, 16 Oct 2024 14:25:17 +0200 Subject: [PATCH] lightningd: `listforwards` returns 0 for missing `received_time`. ([#7157]) Removes the `COMPAT_V070` functionality for `listfowards`. Changelog-Changed: The `listforwards` command will now return a value of 0 for `received_time` for very old forward attempts. --- contrib/msggen/msggen/schema.json | 2 +- doc/schemas/lightning-listforwards.json | 2 +- lightningd/forwards.c | 12 ++---------- tests/test_misc.py | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index e53455103e2f..ade53098bfc1 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -19748,7 +19748,7 @@ "received_time": { "type": "number", "description": [ - "The UNIX timestamp when this was received." + "The UNIX timestamp when this was received (may be zero for old forwards)." ] }, "out_channel": { diff --git a/doc/schemas/lightning-listforwards.json b/doc/schemas/lightning-listforwards.json index f1e0115c3afd..2ac134967613 100644 --- a/doc/schemas/lightning-listforwards.json +++ b/doc/schemas/lightning-listforwards.json @@ -129,7 +129,7 @@ "received_time": { "type": "number", "description": [ - "The UNIX timestamp when this was received." + "The UNIX timestamp when this was received (may be zero for old forwards)." ] }, "out_channel": { diff --git a/lightningd/forwards.c b/lightningd/forwards.c index 0b9ef51efc43..2c001e59e36a 100644 --- a/lightningd/forwards.c +++ b/lightningd/forwards.c @@ -134,19 +134,11 @@ void json_add_forwarding_fields(struct json_stream *response, json_add_string(response, "style", forward_style_name(cur->forward_style)); -#ifdef COMPAT_V070 - /* If a forwarding doesn't have received_time it was created - * before we added the tracking, do not include it here. */ - if (cur->received_time.ts.tv_sec) { - json_add_timeabs(response, "received_time", cur->received_time); - if (cur->resolved_time) - json_add_timeabs(response, "resolved_time", *cur->resolved_time); - } -#else + /* Forwards didn't originally have received_time. They should be 0 + in the database due to a previous migration. */ json_add_timeabs(response, "received_time", cur->received_time); if (cur->resolved_time) json_add_timeabs(response, "resolved_time", *cur->resolved_time); -#endif } static void listforwardings_add_forwardings(struct json_stream *response, diff --git a/tests/test_misc.py b/tests/test_misc.py index 283ed119a713..100bfa7a1fd3 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3313,6 +3313,29 @@ def test_listforwards_wait(node_factory, executor): 'status': 'failed'}} +@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "modifies database, which is assumed sqlite3") +def test_listforwards_ancient(node_factory, bitcoind): + """Test listforwards command with old records.""" + l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True) + + amt1 = 1000 + inv1 = l3.rpc.invoice(amt1, 'inv1', 'desc') + l1.rpc.pay(inv1['bolt11']) + + forwards = l2.rpc.listforwards()['forwards'] + assert len(forwards) == 1 + assert forwards[0]['received_time'] + + # Make this forward look like an older record, with received_time default 0. + l2.stop() + l2.db_manip("UPDATE forwards SET received_time=0;") + l2.start() + + forwards = l2.rpc.listforwards()['forwards'] + assert len(forwards) == 1 + assert forwards[0]['received_time'] == 0 + + @pytest.mark.openchannel('v1') def test_version_reexec(node_factory, bitcoind): badopeningd = os.path.join(os.path.dirname(__file__), "plugins", "badopeningd.sh")