diff --git a/lightningd/channel.c b/lightningd/channel.c index baddbe20c..7d0d93175 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -430,6 +430,7 @@ void channel_set_state(struct channel *channel, char *why) { struct channel_id cid; + struct timeabs timestamp; /* set closer, if known */ if (state > CHANNELD_NORMAL && channel->closer == NUM_SIDES) { @@ -457,11 +458,13 @@ void channel_set_state(struct channel *channel, /* plugin notification channel_state_changed */ if (state != old_state) { /* see issue #4029 */ + timestamp = time_now(); derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum); notify_channel_state_changed(channel->peer->ld, &channel->peer->id, &cid, channel->scid, + ×tamp, old_state, state, reason, diff --git a/lightningd/notification.c b/lightningd/notification.c index d0a22f3cd..afb4dd2b1 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -214,6 +214,7 @@ static void channel_state_changed_notification_serialize(struct json_stream *str struct node_id *peer_id, struct channel_id *cid, struct short_channel_id *scid, + struct timeabs *timestamp, enum channel_state old_state, enum channel_state new_state, enum state_change cause, @@ -226,6 +227,7 @@ static void channel_state_changed_notification_serialize(struct json_stream *str json_add_short_channel_id(stream, "short_channel_id", scid); else json_add_null(stream, "short_channel_id"); + json_add_timeiso(stream, "timestamp", timestamp); json_add_string(stream, "old_state", channel_state_str(old_state)); json_add_string(stream, "new_state", channel_state_str(new_state)); json_add_string(stream, "cause", channel_change_state_reason_str(cause)); @@ -244,6 +246,7 @@ void notify_channel_state_changed(struct lightningd *ld, struct node_id *peer_id, struct channel_id *cid, struct short_channel_id *scid, + struct timeabs *timestamp, enum channel_state old_state, enum channel_state new_state, enum state_change cause, @@ -253,6 +256,7 @@ void notify_channel_state_changed(struct lightningd *ld, struct node_id *, struct channel_id *, struct short_channel_id *, + struct timeabs *timestamp, enum channel_state, enum channel_state, enum state_change, @@ -260,7 +264,7 @@ void notify_channel_state_changed(struct lightningd *ld, struct jsonrpc_notification *n = jsonrpc_notification_start(NULL, channel_state_changed_notification_gen.topic); - serialize(n->stream, peer_id, cid, scid, old_state, new_state, cause, message); + serialize(n->stream, peer_id, cid, scid, timestamp, old_state, new_state, cause, message); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } diff --git a/lightningd/notification.h b/lightningd/notification.h index 44a62a0a4..1b423bf3f 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -63,6 +63,7 @@ void notify_channel_state_changed(struct lightningd *ld, struct node_id *peer_id, struct channel_id *cid, struct short_channel_id *scid, + struct timeabs *timestamp, enum channel_state old_state, enum channel_state new_state, enum state_change cause, diff --git a/tests/test_plugin.py b/tests/test_plugin.py index b8897dccc..16a977805 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,4 +1,5 @@ from collections import OrderedDict +from datetime import datetime from fixtures import * # noqa: F401,F403 from flaky import flaky # noqa: F401 from hashlib import sha256 @@ -668,6 +669,10 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind): assert(event2['cause'] == "remote") assert(event2['message'] == "Lockin complete") + # also test the correctness of timestamps once + assert(datetime.fromisoformat(event1['timestamp'].replace('Z', '+00:00'))) + assert(datetime.fromisoformat(event2['timestamp'].replace('Z', '+00:00'))) + # close channel and look for stateful events l1.rpc.close(scid) diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 51a972333..d29fb6104 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1672,4 +1672,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:e101a44fa0daaa4c1118759cc19d3b1b31dedfe85cf0cf3502bd41f939e55634 +// SHA256STAMP:5f01b4eb0c1df3e18b6d3f7af23a509d584b12b8b0a637451576d2ef80bed04f diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 5ff1b040d..c82e81b81 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1672,4 +1672,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:e101a44fa0daaa4c1118759cc19d3b1b31dedfe85cf0cf3502bd41f939e55634 +// SHA256STAMP:5f01b4eb0c1df3e18b6d3f7af23a509d584b12b8b0a637451576d2ef80bed04f diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 737544f75..6dc65f699 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1098,7 +1098,7 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1370 +#: wallet/test/run-wallet.c:1371 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:0c250c26e1bcb07604d3665155ac7b6edd68904f0cb536b8ccbd0191582d75d5 +# SHA256STAMP:50d91c4404011657ae39cf1d961cee3c2c313af63ac8ef1cd915bbb7a9973c09 diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 309275429..0dbffb093 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -442,6 +442,7 @@ void notify_channel_state_changed(struct lightningd *ld UNNEEDED, struct node_id *peer_id UNNEEDED, struct channel_id *cid UNNEEDED, struct short_channel_id *scid UNNEEDED, + struct timeabs *timestamp UNNEEDED, enum channel_state old_state UNNEEDED, enum channel_state new_state UNNEEDED, enum state_change cause UNNEEDED,