Skip to content

Commit 2971f5d

Browse files
nepetcdecker
authored andcommitted
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 known yet. Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
1 parent 31ad743 commit 2971f5d

12 files changed

Lines changed: 917 additions & 859 deletions

File tree

.msggen.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,7 @@
30453045
"ListPeerChannels.channels[].updates.remote.htlc_minimum_msat": 1
30463046
},
30473047
"ListpeerchannelsRequest": {
3048+
"ListPeerChannels.channel_id": 3,
30483049
"ListPeerChannels.id": 1,
30493050
"ListPeerChannels.short_channel_id": 2
30503051
},
@@ -10757,6 +10758,10 @@
1075710758
"added": "v23.02",
1075810759
"deprecated": null
1075910760
},
10761+
"ListPeerChannels.channel_id": {
10762+
"added": "v26.03",
10763+
"deprecated": null
10764+
},
1076010765
"ListPeerChannels.channels[]": {
1076110766
"added": "v23.02",
1076210767
"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
@@ -23509,9 +23509,11 @@
2350923509
"rpc": "listpeerchannels",
2351023510
"title": "Command returning data on channels of connected lightning nodes",
2351123511
"description": [
23512-
"The **listpeerchannels** RPC command returns list of this node's channels, with the possibility to filter them by peer's node id.",
23512+
"The **listpeerchannels** RPC command returns a list of this node's channels.",
2351323513
"",
23514-
"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."
23514+
"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.",
23515+
"",
23516+
"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."
2351523517
],
2351623518
"categories": [
2351723519
"readonly"
@@ -23523,14 +23525,21 @@
2352323525
"id": {
2352423526
"type": "pubkey",
2352523527
"description": [
23526-
"If supplied, limits the channels to just the peer with the given ID, if it exists."
23528+
"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'."
2352723529
]
2352823530
},
2352923531
"short_channel_id": {
2353023532
"added": "v25.05",
2353123533
"type": "short_channel_id",
2353223534
"description": [
23533-
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
23535+
"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'."
23536+
]
23537+
},
23538+
"channel_id": {
23539+
"added": "v26.03",
23540+
"type": "hash",
23541+
"description": [
23542+
"If supplied, limits the channels to just this channel_id, if it exists. Cannot be used with 'id' or 'short_channel_id'."
2353423543
]
2353523544
}
2353623545
}

contrib/pyln-client/pyln/client/lightning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ def listpeers(self, peerid=None, level=None):
10521052
}
10531053
return self.call("listpeers", payload)
10541054

1055-
def listpeerchannels(self, peer_id=None, short_channel_id=None):
1055+
def listpeerchannels(self, peer_id=None, short_channel_id=None, channel_id=None):
10561056
"""
10571057
Show current peers channels, and if the {peer_id} is specified
10581058
all the channels for the peer are returned, and if {short_channel_id} is
@@ -1061,6 +1061,7 @@ def listpeerchannels(self, peer_id=None, short_channel_id=None):
10611061
payload = {
10621062
"id": peer_id,
10631063
"short_channel_id": short_channel_id,
1064+
"channel_id": channel_id,
10641065
}
10651066
return self.call("listpeerchannels", payload)
10661067

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

Lines changed: 847 additions & 847 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": "v26.03",
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>
@@ -2630,16 +2631,22 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
26302631
struct peer *peer;
26312632
struct json_stream *response;
26322633
struct short_channel_id *scid;
2634+
struct channel_id *cid;
26332635

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

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

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

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)