Skip to content

Commit c81ec4f

Browse files
committed
lightningd: deprecate (undocumented!) "unknown" old_state field in channel_state_changed notification.
Reported-by: daywalker90 Changelog-Deprecated: JSON-RPC: channel_state_changed notification field `old_state` value "unknown" (it will be omitted, instead) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 8e41ee4 commit c81ec4f

File tree

10 files changed

+28
-19
lines changed

10 files changed

+28
-19
lines changed

cln-grpc/proto/node.proto

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/notifications.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ impl ToString for ChannelStateChangedCause {
188188

189189
#[derive(Clone, Debug, Deserialize, Serialize)]
190190
pub struct ChannelStateChangedNotification {
191+
#[serde(skip_serializing_if = "Option::is_none")]
192+
pub old_state: Option<ChannelState>,
191193
// Path `channel_state_changed.cause`
192194
pub cause: ChannelStateChangedCause,
193195
// Path `channel_state_changed.new_state`
194196
pub new_state: ChannelState,
195-
// Path `channel_state_changed.old_state`
196-
pub old_state: ChannelState,
197197
pub channel_id: Sha256,
198198
pub message: String,
199199
pub peer_id: PublicKey,

contrib/msggen/msggen/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36672,7 +36672,6 @@
3667236672
"channel_id",
3667336673
"short_channel_id",
3667436674
"timestamp",
36675-
"old_state",
3667636675
"new_state",
3667736676
"cause",
3667836677
"message"
@@ -36725,7 +36724,8 @@
3672536724
"DUALOPEND_OPEN_COMMIT_READY"
3672636725
],
3672736726
"description": [
36728-
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
36727+
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally.",
36728+
"The deprecated value 'unknown' is also present for new channels: after 26.02 this field will be omitted instead."
3672936729
],
3673036730
"added": "pre-v0.10.1"
3673136731
},

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/developers-guide/deprecations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ hidden: false
2727
| xpay.ignore_bolt12_mpp | Field | v25.05 | v25.11 | Try MPP even if the BOLT12 invoice doesn't explicitly allow it (CLN didn't until 25.02) |
2828
| listpeerchannels.max_total_htlc_in_msat | Field | v25.02 | v26.02 | Use our_max_total_htlc_out_msat |
2929
| wait.details | Field | v25.05 | v26.05 | Use subsystem-specific object instead |
30+
| channel_state_changed.old_state.unknown | Notification Field | v25.05 | v26.02 | Value "unknown" is deprecated: field will be omitted instead |
3031

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

doc/schemas/notification/channel_state_changed.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"channel_id",
1616
"short_channel_id",
1717
"timestamp",
18-
"old_state",
1918
"new_state",
2019
"cause",
2120
"message"
@@ -68,7 +67,8 @@
6867
"DUALOPEND_OPEN_COMMIT_READY"
6968
],
7069
"description": [
71-
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
70+
"The channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally.",
71+
"The deprecated value 'unknown' is also present for new channels: after 26.02 this field will be omitted instead."
7272
],
7373
"added": "pre-v0.10.1"
7474
},

lightningd/notification.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ void notify_channel_opened(struct lightningd *ld,
255255
}
256256

257257
static void channel_state_changed_notification_serialize(struct json_stream *stream,
258+
struct lightningd *ld,
258259
const struct node_id *peer_id,
259260
const struct channel_id *cid,
260261
const struct short_channel_id *scid,
@@ -271,7 +272,10 @@ static void channel_state_changed_notification_serialize(struct json_stream *str
271272
else
272273
json_add_null(stream, "short_channel_id");
273274
json_add_timeiso(stream, "timestamp", timestamp);
274-
json_add_string(stream, "old_state", channel_state_str(old_state));
275+
if (old_state != 0 || lightningd_deprecated_out_ok(ld, ld->deprecated_ok,
276+
"channel_state_changed", "old_state.unknown",
277+
"v25.05", "v26.02"))
278+
json_add_string(stream, "old_state", channel_state_str(old_state));
275279
json_add_string(stream, "new_state", channel_state_str(new_state));
276280
json_add_string(stream, "cause", channel_change_state_reason_str(cause));
277281
if (message != NULL)
@@ -293,7 +297,7 @@ void notify_channel_state_changed(struct lightningd *ld,
293297
const char *message)
294298
{
295299
struct jsonrpc_notification *n = notify_start("channel_state_changed");
296-
channel_state_changed_notification_serialize(n->stream, peer_id, cid, scid, timestamp, old_state, new_state, cause, message);
300+
channel_state_changed_notification_serialize(n->stream, ld, peer_id, cid, scid, timestamp, old_state, new_state, cause, message);
297301
notify_send(ld, n);
298302
}
299303

plugins/funder.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,10 +1140,11 @@ static struct command_result *json_channel_state_changed(struct command *cmd,
11401140
struct channel_id cid;
11411141
const char *err, *old_state, *new_state;
11421142

1143+
old_state = NULL;
11431144
err = json_scan(tmpctx, buf, params,
11441145
"{channel_state_changed:"
11451146
"{channel_id:%"
1146-
",old_state:%"
1147+
",old_state?:%"
11471148
",new_state:%}}",
11481149
JSON_SCAN(json_to_channel_id, &cid),
11491150
JSON_SCAN_TAL(cmd, json_strdup, &old_state),
@@ -1159,6 +1160,9 @@ static struct command_result *json_channel_state_changed(struct command *cmd,
11591160
/* Moving out of "awaiting lockin",
11601161
* means we clean up the datastore */
11611162
/* FIXME: splicing state? */
1163+
if (!old_state)
1164+
return notification_handled(cmd);
1165+
11621166
if (!streq(old_state, "DUALOPEND_AWAITING_LOCKIN")
11631167
&& !streq(old_state, "CHANNELD_AWAITING_LOCKIN"))
11641168
return notification_handled(cmd);

tests/test_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def wait_for_event(node):
869869
assert(event2['cause'] == "remote")
870870

871871
for ev in [event1, event2]:
872-
assert(ev['old_state'] == "unknown")
872+
'old_state' not in ev
873873
assert(ev['new_state'] == "CHANNELD_AWAITING_LOCKIN")
874874
assert(ev['message'] == "new channel opened")
875875

@@ -1006,7 +1006,7 @@ def wait_for_event(node):
10061006
assert event2['new_state'] == "DUALOPEND_AWAITING_LOCKIN"
10071007
assert event2['message'] == "Sigs exchanged, waiting for lock-in"
10081008
else:
1009-
assert(event2['old_state'] == "unknown")
1009+
assert "unknown" not in event2
10101010
assert(event2['new_state'] == "CHANNELD_AWAITING_LOCKIN")
10111011
assert(event2['message'] == "new channel opened")
10121012

0 commit comments

Comments
 (0)