diff --git a/common/json_stream.c b/common/json_stream.c index 582e5e7e3..b272760c2 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -313,11 +313,6 @@ void json_add_bool(struct json_stream *result, const char *fieldname, bool value json_add_primitive(result, fieldname, value ? "true" : "false"); } -void json_add_null(struct json_stream *stream, const char *fieldname) -{ - json_add_primitive(stream, fieldname, "null"); -} - void json_add_hex(struct json_stream *js, const char *fieldname, const void *data, size_t len) { diff --git a/common/json_stream.h b/common/json_stream.h index da65761c8..05e2df74c 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -240,8 +240,7 @@ void json_add_s32(struct json_stream *result, const char *fieldname, void json_add_bool(struct json_stream *result, const char *fieldname, bool value); -/* '"fieldname" : null' or 'null' if fieldname is NULL */ -void json_add_null(struct json_stream *stream, const char *fieldname); +/* Looking for json_add_null? Don't do that: we omit fields, don't 'null' them! */ /* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */ void json_add_hex(struct json_stream *result, const char *fieldname, diff --git a/doc/developers-guide/deprecated-features.md b/doc/developers-guide/deprecated-features.md index c70392217..5da91a552 100644 --- a/doc/developers-guide/deprecated-features.md +++ b/doc/developers-guide/deprecated-features.md @@ -25,7 +25,8 @@ privacy: | 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 | | encrypted_hsm | Config | v25.12 | v26.12 | `hsm-passphrase` is a name which also makes sense for modern hsm_secrets which use BIP 39 | | newaddr.addresstype.defaultbech32 | Parameter | v25.12 | v26.12 | Use `p2tr` in the response (present since v23.08 if `addresstype` is `p2tr`, and always present since v24.12). | - +| channel_state_changed.null_message | Notification Field | v25.12 | v26.12 | In channel_state_changed notification, `message` will be missing instead of `null` | + Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported. Types of deprecation: diff --git a/doc/schemas/notification/channel_state_changed.json b/doc/schemas/notification/channel_state_changed.json index c2f1aba18..a90fddbf5 100644 --- a/doc/schemas/notification/channel_state_changed.json +++ b/doc/schemas/notification/channel_state_changed.json @@ -15,8 +15,7 @@ "channel_id", "timestamp", "new_state", - "cause", - "message" + "cause" ], "properties": { "peer_id": { diff --git a/lightningd/notification.c b/lightningd/notification.c index 73a689b97..b2adb64eb 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -273,6 +273,12 @@ void notify_channel_opened(struct lightningd *ld, notify_send(ld, n); } +/* Don't use this: omit fields instead! */ +static void json_add_null(struct json_stream *stream, const char *fieldname) +{ + json_add_primitive(stream, fieldname, "null"); +} + static void channel_state_changed_notification_serialize(struct json_stream *stream, struct lightningd *ld, const struct node_id *peer_id, @@ -302,8 +308,12 @@ static void channel_state_changed_notification_serialize(struct json_stream *str json_add_string(stream, "cause", channel_change_state_reason_str(cause)); if (message != NULL) json_add_string(stream, "message", message); - else + else if (lightningd_deprecated_out_ok(ld, ld->deprecated_ok, + "channel_state_changed", + "null_message", + "v25.12", "v26.12")) { json_add_null(stream, "message"); + } } REGISTER_NOTIFICATION(channel_state_changed) diff --git a/plugins/bcli.c b/plugins/bcli.c index 51ff4942b..cb99763e7 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -418,6 +418,12 @@ static struct command_result *command_err_bcli_badjson(struct bitcoin_cli *bcli, return command_done_err(bcli->cmd, BCLI_ERROR, err, NULL); } +/* Don't use this in general: it's better to omit fields. */ +static void json_add_null(struct json_stream *stream, const char *fieldname) +{ + json_add_primitive(stream, fieldname, "null"); +} + static struct command_result *process_getutxout(struct bitcoin_cli *bcli) { const jsmntok_t *tokens;