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.
This commit is contained in:
Se7enZ 2024-10-16 14:25:17 +02:00 committed by Vincenzo Palazzo
parent 3a363df5fb
commit 4017844d0c
4 changed files with 27 additions and 12 deletions

View File

@ -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": {

View File

@ -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": {

View File

@ -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,

View File

@ -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")