Skip to content

Commit

Permalink
lightningd: listforwards returns 0 for missing received_time. ([#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
s373nZ authored and vincenzopalazzo committed Oct 26, 2024
1 parent 3a363df commit 4017844
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/lightning-listforwards.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 2 additions & 10 deletions lightningd/forwards.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4017844

Please sign in to comment.