Skip to content

Commit 4017844

Browse files
s373nZvincenzopalazzo
authored andcommitted
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.
1 parent 3a363df commit 4017844

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19748,7 +19748,7 @@
1974819748
"received_time": {
1974919749
"type": "number",
1975019750
"description": [
19751-
"The UNIX timestamp when this was received."
19751+
"The UNIX timestamp when this was received (may be zero for old forwards)."
1975219752
]
1975319753
},
1975419754
"out_channel": {

doc/schemas/lightning-listforwards.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"received_time": {
130130
"type": "number",
131131
"description": [
132-
"The UNIX timestamp when this was received."
132+
"The UNIX timestamp when this was received (may be zero for old forwards)."
133133
]
134134
},
135135
"out_channel": {

lightningd/forwards.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,11 @@ void json_add_forwarding_fields(struct json_stream *response,
134134
json_add_string(response, "style",
135135
forward_style_name(cur->forward_style));
136136

137-
#ifdef COMPAT_V070
138-
/* If a forwarding doesn't have received_time it was created
139-
* before we added the tracking, do not include it here. */
140-
if (cur->received_time.ts.tv_sec) {
141-
json_add_timeabs(response, "received_time", cur->received_time);
142-
if (cur->resolved_time)
143-
json_add_timeabs(response, "resolved_time", *cur->resolved_time);
144-
}
145-
#else
137+
/* Forwards didn't originally have received_time. They should be 0
138+
in the database due to a previous migration. */
146139
json_add_timeabs(response, "received_time", cur->received_time);
147140
if (cur->resolved_time)
148141
json_add_timeabs(response, "resolved_time", *cur->resolved_time);
149-
#endif
150142
}
151143

152144
static void listforwardings_add_forwardings(struct json_stream *response,

tests/test_misc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,29 @@ def test_listforwards_wait(node_factory, executor):
33133313
'status': 'failed'}}
33143314

33153315

3316+
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "modifies database, which is assumed sqlite3")
3317+
def test_listforwards_ancient(node_factory, bitcoind):
3318+
"""Test listforwards command with old records."""
3319+
l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
3320+
3321+
amt1 = 1000
3322+
inv1 = l3.rpc.invoice(amt1, 'inv1', 'desc')
3323+
l1.rpc.pay(inv1['bolt11'])
3324+
3325+
forwards = l2.rpc.listforwards()['forwards']
3326+
assert len(forwards) == 1
3327+
assert forwards[0]['received_time']
3328+
3329+
# Make this forward look like an older record, with received_time default 0.
3330+
l2.stop()
3331+
l2.db_manip("UPDATE forwards SET received_time=0;")
3332+
l2.start()
3333+
3334+
forwards = l2.rpc.listforwards()['forwards']
3335+
assert len(forwards) == 1
3336+
assert forwards[0]['received_time'] == 0
3337+
3338+
33163339
@pytest.mark.openchannel('v1')
33173340
def test_version_reexec(node_factory, bitcoind):
33183341
badopeningd = os.path.join(os.path.dirname(__file__), "plugins", "badopeningd.sh")

0 commit comments

Comments
 (0)