Skip to content

Commit b2573f5

Browse files
committed
lightningd: add channel_id filter to listpeerchannels
Sometimes we don't know the short_channel_id yet (e.g the channel has not been broadcasted), but we still know the channel_id from the funding transaction. Add a channel_id filter to listpeerchannels and clarify that id, short_channel_id and channel_id are mutually exclusive. Changelog-Added: `listpeerchannels` now accepts a `channel_id` filter, for cases where the `short_channel_id` is not yet known. Signed-off-by: Peter Neuroth <[email protected]>
1 parent 5c0827e commit b2573f5

File tree

9 files changed

+902
-859
lines changed

9 files changed

+902
-859
lines changed

.msggen.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,7 @@
30303030
"ListPeerChannels.channels[].updates.remote.htlc_minimum_msat": 1
30313031
},
30323032
"ListpeerchannelsRequest": {
3033+
"ListPeerChannels.channel_id": 3,
30333034
"ListPeerChannels.id": 1,
30343035
"ListPeerChannels.short_channel_id": 2
30353036
},
@@ -10692,6 +10693,10 @@
1069210693
"added": "v23.02",
1069310694
"deprecated": null
1069410695
},
10696+
"ListPeerChannels.channel_id": {
10697+
"added": "v25.12",
10698+
"deprecated": null
10699+
},
1069510700
"ListPeerChannels.channels[]": {
1069610701
"added": "v23.02",
1069710702
"deprecated": null

cln-grpc/proto/node.proto

Lines changed: 1 addition & 0 deletions
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: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

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

contrib/msggen/msggen/schema.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23853,9 +23853,11 @@
2385323853
"rpc": "listpeerchannels",
2385423854
"title": "Command returning data on channels of connected lightning nodes",
2385523855
"description": [
23856-
"The **listpeerchannels** RPC command returns list of this node's channels, with the possibility to filter them by peer's node id.",
23856+
"The **listpeerchannels** RPC command returns a list of this node's channels.",
2385723857
"",
23858-
"If no *id* is supplied, then channel data on all lightning nodes that are connected, or not connected but have open channels with this node, are returned."
23858+
"By default, data for all known channels is returned, including those to peers that are currently connected and those to peers that are disconnected but still have open channels.",
23859+
"",
23860+
"At most one of *id*, *short_channel_id* or *channel_id* may be provided as a filter. If more than one is provided, the command fails with an error."
2385923861
],
2386023862
"categories": [
2386123863
"readonly"
@@ -23867,14 +23869,21 @@
2386723869
"id": {
2386823870
"type": "pubkey",
2386923871
"description": [
23870-
"If supplied, limits the channels to just the peer with the given ID, if it exists."
23872+
"If supplied, limits the channels to just the peer with the given ID, if it exists. Cannot be used with 'short_channel_id' or 'channel_id'."
2387123873
]
2387223874
},
2387323875
"short_channel_id": {
2387423876
"added": "v25.05",
2387523877
"type": "short_channel_id",
2387623878
"description": [
23877-
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
23879+
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id' or 'channel_id'."
23880+
]
23881+
},
23882+
"channel_id": {
23883+
"added": "v25.12",
23884+
"type": "hash",
23885+
"description": [
23886+
"If supplied, limits the channels to just this channel_id, if it exists. Cannot be used with 'id' or 'short_channel_id'."
2387823887
]
2387923888
}
2388023889
}

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

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

doc/schemas/listpeerchannels.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"rpc": "listpeerchannels",
66
"title": "Command returning data on channels of connected lightning nodes",
77
"description": [
8-
"The **listpeerchannels** RPC command returns list of this node's channels, with the possibility to filter them by peer's node id.",
8+
"The **listpeerchannels** RPC command returns a list of this node's channels.",
99
"",
10-
"If no *id* is supplied, then channel data on all lightning nodes that are connected, or not connected but have open channels with this node, are returned."
10+
"By default, data for all known channels is returned, including those to peers that are currently connected and those to peers that are disconnected but still have open channels.",
11+
"",
12+
"At most one of *id*, *short_channel_id* or *channel_id* may be provided as a filter. If more than one is provided, the command fails with an error."
1113
],
1214
"categories": [
1315
"readonly"
@@ -19,14 +21,21 @@
1921
"id": {
2022
"type": "pubkey",
2123
"description": [
22-
"If supplied, limits the channels to just the peer with the given ID, if it exists."
24+
"If supplied, limits the channels to just the peer with the given ID, if it exists. Cannot be used with 'short_channel_id' or 'channel_id'."
2325
]
2426
},
2527
"short_channel_id": {
2628
"added": "v25.05",
2729
"type": "short_channel_id",
2830
"description": [
29-
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
31+
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id' or 'channel_id'."
32+
]
33+
},
34+
"channel_id": {
35+
"added": "v25.12",
36+
"type": "hash",
37+
"description": [
38+
"If supplied, limits the channels to just this channel_id, if it exists. Cannot be used with 'id' or 'short_channel_id'."
3039
]
3140
}
3241
}

lightningd/peer_control.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ccan/tal/str/str.h>
77
#include <channeld/channeld_wiregen.h>
88
#include <common/addr.h>
9+
#include <common/channel_id.h>
910
#include <common/htlc_trim.h>
1011
#include <common/initial_commit_tx.h>
1112
#include <common/json_channel_type.h>
@@ -2631,16 +2632,22 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
26312632
struct peer *peer;
26322633
struct json_stream *response;
26332634
struct short_channel_id *scid;
2635+
struct channel_id *cid;
26342636

26352637
if (!param_check(cmd, buffer, params,
26362638
p_opt("id", param_node_id, &peer_id),
26372639
p_opt("short_channel_id", param_short_channel_id, &scid),
2640+
p_opt("channel_id", param_channel_id, &cid),
26382641
NULL))
26392642
return command_param_failed();
26402643

2641-
if (scid && peer_id)
2644+
int count = (peer_id != NULL) + (scid != NULL) + (cid != NULL);
2645+
if (count > 1) {
26422646
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2643-
"Cannot specify both short_channel_id and id");
2647+
"Must not specify more than one of "
2648+
"short_channel_id, channel_id or id"
2649+
);
2650+
}
26442651

26452652
response = json_stream_success(cmd);
26462653
json_array_start(response, "channels");
@@ -2653,6 +2660,10 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
26532660
const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true);
26542661
if (c)
26552662
json_add_channel(cmd, response, NULL, c, c->peer);
2663+
} else if (cid) {
2664+
const struct channel *c = channel_by_cid(cmd->ld, cid);
2665+
if (c)
2666+
json_add_channel(cmd, response, NULL, c, c->peer);
26562667
} else {
26572668
struct peer_node_id_map_iter it;
26582669

lightningd/test/run-invoice-select-inchan.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ void broadcast_tx_(const tal_t *ctx UNNEEDED,
5353
bool (*refresh)(struct channel * UNNEEDED, const struct bitcoin_tx ** UNNEEDED, void *) UNNEEDED,
5454
void *cbarg TAKES UNNEEDED)
5555
{ fprintf(stderr, "broadcast_tx_ called!\n"); abort(); }
56+
/* Generated stub for channel_by_cid */
57+
struct channel *channel_by_cid(struct lightningd *ld UNNEEDED,
58+
const struct channel_id *cid UNNEEDED)
59+
{ fprintf(stderr, "channel_by_cid called!\n"); abort(); }
5660
/* Generated stub for channel_change_state_reason_str */
5761
const char *channel_change_state_reason_str(enum state_change reason UNNEEDED)
5862
{ fprintf(stderr, "channel_change_state_reason_str called!\n"); abort(); }

0 commit comments

Comments
 (0)