Browse Source

feat: adds timestamp to state_change notification

ppa-prep
Michael Schmoock 4 years ago
committed by neil saitug
parent
commit
68ce25c92d
  1. 3
      lightningd/channel.c
  2. 6
      lightningd/notification.c
  3. 1
      lightningd/notification.h
  4. 5
      tests/test_plugin.py
  5. 2
      wallet/db_postgres_sqlgen.c
  6. 2
      wallet/db_sqlite3_sqlgen.c
  7. 4
      wallet/statements_gettextgen.po
  8. 1
      wallet/test/run-wallet.c

3
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,
&timestamp,
old_state,
state,
reason,

6
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));
}

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

5
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)

2
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

2
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

4
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

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

Loading…
Cancel
Save