mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
feat: adds timestamp to state_change notification
This commit is contained in:
parent
4d765003dd
commit
68ce25c92d
@ -430,6 +430,7 @@ void channel_set_state(struct channel *channel,
|
|||||||
char *why)
|
char *why)
|
||||||
{
|
{
|
||||||
struct channel_id cid;
|
struct channel_id cid;
|
||||||
|
struct timeabs timestamp;
|
||||||
|
|
||||||
/* set closer, if known */
|
/* set closer, if known */
|
||||||
if (state > CHANNELD_NORMAL && channel->closer == NUM_SIDES) {
|
if (state > CHANNELD_NORMAL && channel->closer == NUM_SIDES) {
|
||||||
@ -457,11 +458,13 @@ void channel_set_state(struct channel *channel,
|
|||||||
|
|
||||||
/* plugin notification channel_state_changed */
|
/* plugin notification channel_state_changed */
|
||||||
if (state != old_state) { /* see issue #4029 */
|
if (state != old_state) { /* see issue #4029 */
|
||||||
|
timestamp = time_now();
|
||||||
derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum);
|
derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum);
|
||||||
notify_channel_state_changed(channel->peer->ld,
|
notify_channel_state_changed(channel->peer->ld,
|
||||||
&channel->peer->id,
|
&channel->peer->id,
|
||||||
&cid,
|
&cid,
|
||||||
channel->scid,
|
channel->scid,
|
||||||
|
×tamp,
|
||||||
old_state,
|
old_state,
|
||||||
state,
|
state,
|
||||||
reason,
|
reason,
|
||||||
|
@ -214,6 +214,7 @@ static void channel_state_changed_notification_serialize(struct json_stream *str
|
|||||||
struct node_id *peer_id,
|
struct node_id *peer_id,
|
||||||
struct channel_id *cid,
|
struct channel_id *cid,
|
||||||
struct short_channel_id *scid,
|
struct short_channel_id *scid,
|
||||||
|
struct timeabs *timestamp,
|
||||||
enum channel_state old_state,
|
enum channel_state old_state,
|
||||||
enum channel_state new_state,
|
enum channel_state new_state,
|
||||||
enum state_change cause,
|
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);
|
json_add_short_channel_id(stream, "short_channel_id", scid);
|
||||||
else
|
else
|
||||||
json_add_null(stream, "short_channel_id");
|
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, "old_state", channel_state_str(old_state));
|
||||||
json_add_string(stream, "new_state", channel_state_str(new_state));
|
json_add_string(stream, "new_state", channel_state_str(new_state));
|
||||||
json_add_string(stream, "cause", channel_change_state_reason_str(cause));
|
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 node_id *peer_id,
|
||||||
struct channel_id *cid,
|
struct channel_id *cid,
|
||||||
struct short_channel_id *scid,
|
struct short_channel_id *scid,
|
||||||
|
struct timeabs *timestamp,
|
||||||
enum channel_state old_state,
|
enum channel_state old_state,
|
||||||
enum channel_state new_state,
|
enum channel_state new_state,
|
||||||
enum state_change cause,
|
enum state_change cause,
|
||||||
@ -253,6 +256,7 @@ void notify_channel_state_changed(struct lightningd *ld,
|
|||||||
struct node_id *,
|
struct node_id *,
|
||||||
struct channel_id *,
|
struct channel_id *,
|
||||||
struct short_channel_id *,
|
struct short_channel_id *,
|
||||||
|
struct timeabs *timestamp,
|
||||||
enum channel_state,
|
enum channel_state,
|
||||||
enum channel_state,
|
enum channel_state,
|
||||||
enum state_change,
|
enum state_change,
|
||||||
@ -260,7 +264,7 @@ void notify_channel_state_changed(struct lightningd *ld,
|
|||||||
|
|
||||||
struct jsonrpc_notification *n
|
struct jsonrpc_notification *n
|
||||||
= jsonrpc_notification_start(NULL, channel_state_changed_notification_gen.topic);
|
= 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);
|
jsonrpc_notification_end(n);
|
||||||
plugins_notify(ld->plugins, take(n));
|
plugins_notify(ld->plugins, take(n));
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ void notify_channel_state_changed(struct lightningd *ld,
|
|||||||
struct node_id *peer_id,
|
struct node_id *peer_id,
|
||||||
struct channel_id *cid,
|
struct channel_id *cid,
|
||||||
struct short_channel_id *scid,
|
struct short_channel_id *scid,
|
||||||
|
struct timeabs *timestamp,
|
||||||
enum channel_state old_state,
|
enum channel_state old_state,
|
||||||
enum channel_state new_state,
|
enum channel_state new_state,
|
||||||
enum state_change cause,
|
enum state_change cause,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from datetime import datetime
|
||||||
from fixtures import * # noqa: F401,F403
|
from fixtures import * # noqa: F401,F403
|
||||||
from flaky import flaky # noqa: F401
|
from flaky import flaky # noqa: F401
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
@ -668,6 +669,10 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind):
|
|||||||
assert(event2['cause'] == "remote")
|
assert(event2['cause'] == "remote")
|
||||||
assert(event2['message'] == "Lockin complete")
|
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
|
# close channel and look for stateful events
|
||||||
l1.rpc.close(scid)
|
l1.rpc.close(scid)
|
||||||
|
|
||||||
|
2
wallet/db_postgres_sqlgen.c
generated
2
wallet/db_postgres_sqlgen.c
generated
@ -1672,4 +1672,4 @@ struct db_query db_postgres_queries[] = {
|
|||||||
|
|
||||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||||
|
|
||||||
// SHA256STAMP:e101a44fa0daaa4c1118759cc19d3b1b31dedfe85cf0cf3502bd41f939e55634
|
// SHA256STAMP:5f01b4eb0c1df3e18b6d3f7af23a509d584b12b8b0a637451576d2ef80bed04f
|
||||||
|
2
wallet/db_sqlite3_sqlgen.c
generated
2
wallet/db_sqlite3_sqlgen.c
generated
@ -1672,4 +1672,4 @@ struct db_query db_sqlite3_queries[] = {
|
|||||||
|
|
||||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||||
|
|
||||||
// SHA256STAMP:e101a44fa0daaa4c1118759cc19d3b1b31dedfe85cf0cf3502bd41f939e55634
|
// SHA256STAMP:5f01b4eb0c1df3e18b6d3f7af23a509d584b12b8b0a637451576d2ef80bed04f
|
||||||
|
4
wallet/statements_gettextgen.po
generated
4
wallet/statements_gettextgen.po
generated
@ -1098,7 +1098,7 @@ msgstr ""
|
|||||||
msgid "not a valid SQL statement"
|
msgid "not a valid SQL statement"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: wallet/test/run-wallet.c:1370
|
#: wallet/test/run-wallet.c:1371
|
||||||
msgid "INSERT INTO channels (id) VALUES (1);"
|
msgid "INSERT INTO channels (id) VALUES (1);"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
# SHA256STAMP:0c250c26e1bcb07604d3665155ac7b6edd68904f0cb536b8ccbd0191582d75d5
|
# SHA256STAMP:50d91c4404011657ae39cf1d961cee3c2c313af63ac8ef1cd915bbb7a9973c09
|
||||||
|
@ -442,6 +442,7 @@ void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
|
|||||||
struct node_id *peer_id UNNEEDED,
|
struct node_id *peer_id UNNEEDED,
|
||||||
struct channel_id *cid UNNEEDED,
|
struct channel_id *cid UNNEEDED,
|
||||||
struct short_channel_id *scid UNNEEDED,
|
struct short_channel_id *scid UNNEEDED,
|
||||||
|
struct timeabs *timestamp UNNEEDED,
|
||||||
enum channel_state old_state UNNEEDED,
|
enum channel_state old_state UNNEEDED,
|
||||||
enum channel_state new_state UNNEEDED,
|
enum channel_state new_state UNNEEDED,
|
||||||
enum state_change cause UNNEEDED,
|
enum state_change cause UNNEEDED,
|
||||||
|
Loading…
Reference in New Issue
Block a user