Skip to content

Commit 59ff4a9

Browse files
committed
lightningd: deprecate "message": null in channel_state_changed notifications.
Somehow I missed this when deprecating `short_channel_id` being null. Changelog-Deprecated: Plugins: `channel_state_changed` notification `message` field being `null`: it will be omitted instead. Signed-off-by: Rusty Russell <[email protected]>
1 parent ea54df0 commit 59ff4a9

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

common/json_stream.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,6 @@ void json_add_bool(struct json_stream *result, const char *fieldname, bool value
323323
json_add_primitive(result, fieldname, value ? "true" : "false");
324324
}
325325

326-
void json_add_null(struct json_stream *stream, const char *fieldname)
327-
{
328-
json_add_primitive(stream, fieldname, "null");
329-
}
330-
331326
void json_add_hex(struct json_stream *js, const char *fieldname,
332327
const void *data, size_t len)
333328
{

common/json_stream.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ void json_add_s32(struct json_stream *result, const char *fieldname,
242242
void json_add_bool(struct json_stream *result, const char *fieldname,
243243
bool value);
244244

245-
/* '"fieldname" : null' or 'null' if fieldname is NULL */
246-
void json_add_null(struct json_stream *stream, const char *fieldname);
245+
/* Looking for json_add_null? Don't do that: we omit fields, don't 'null' them! */
247246

248247
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
249248
void json_add_hex(struct json_stream *result, const char *fieldname,

doc/developers-guide/deprecated-features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ hidden: false
2424
| channel_state_changed.null_scid | Notification Field | v25.09 | v26.09 | In channel_state_changed notification, `short_channel_id` will be missing instead of `null` |
2525
| notification.payload | Notification Field | v25.09 | v26.09 | Notifications from plugins used to have fields in `payload` sub-object, now they are not (just like normal notifications) |
2626
| pay_notifications.raw_fields | Field | v25.09 | v26.09 | `channel_hint_update`, `pay_failure` and `pay_success` notifications now wrap members in an object of the same name |
27+
| channel_state_changed.null_message | Notification Field | v25.12 | v26.12 | In channel_state_changed notification, `message` will be missing instead of `null` |
2728

2829
Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported.
2930

lightningd/notification.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ void notify_channel_opened(struct lightningd *ld,
275275
notify_send(ld, n);
276276
}
277277

278+
/* Don't use this: omit fields instead! */
279+
static void json_add_null(struct json_stream *stream, const char *fieldname)
280+
{
281+
json_add_primitive(stream, fieldname, "null");
282+
}
283+
278284
static void channel_state_changed_notification_serialize(struct json_stream *stream,
279285
struct lightningd *ld,
280286
const struct node_id *peer_id,
@@ -304,8 +310,12 @@ static void channel_state_changed_notification_serialize(struct json_stream *str
304310
json_add_string(stream, "cause", channel_change_state_reason_str(cause));
305311
if (message != NULL)
306312
json_add_string(stream, "message", message);
307-
else
313+
else if (lightningd_deprecated_out_ok(ld, ld->deprecated_ok,
314+
"channel_state_changed",
315+
"null_message",
316+
"v25.12", "v26.12")) {
308317
json_add_null(stream, "message");
318+
}
309319
}
310320

311321
REGISTER_NOTIFICATION(channel_state_changed)

plugins/bcli.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ static struct command_result *command_err_bcli_badjson(struct bitcoin_cli *bcli,
396396
return command_done_err(bcli->cmd, BCLI_ERROR, err, NULL);
397397
}
398398

399+
/* Don't use this in general: it's better to omit fields. */
400+
static void json_add_null(struct json_stream *stream, const char *fieldname)
401+
{
402+
json_add_primitive(stream, fieldname, "null");
403+
}
404+
399405
static struct command_result *process_getutxout(struct bitcoin_cli *bcli)
400406
{
401407
const jsmntok_t *tokens;

tests/test_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,12 @@ def wait_for_event(node):
967967
assert(event1['old_state'] == "ONCHAIN")
968968
assert(event1['new_state'] == "CLOSED")
969969
assert(event1['cause'] == "onchain")
970-
assert(event1['message'] == None)
970+
assert('message' not in event1)
971971
event2 = wait_for_event(l2)
972972
assert(event2['old_state'] == "ONCHAIN")
973973
assert(event2['new_state'] == "CLOSED")
974974
assert(event2['cause'] == "onchain")
975-
assert(event2['message'] == None)
975+
assert('message' not in event2)
976976

977977

978978
@pytest.mark.openchannel('v1')
@@ -1102,13 +1102,13 @@ def wait_for_event(node):
11021102
assert(event1['old_state'] == "ONCHAIN")
11031103
assert(event1['new_state'] == "CLOSED")
11041104
assert(event1['cause'] == "onchain")
1105-
assert(event1['message'] == None)
1105+
assert('message' not in event1)
11061106

11071107
event2 = wait_for_event(l2)
11081108
assert(event2['old_state'] == "ONCHAIN")
11091109
assert(event2['new_state'] == "CLOSED")
11101110
assert(event2['cause'] == "onchain")
1111-
assert(event2['message'] == None)
1111+
assert('message' not in event2)
11121112

11131113

11141114
@pytest.mark.openchannel('v1')

0 commit comments

Comments
 (0)