Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,7 @@
"ListPeerChannels.channels[].updates.remote.htlc_minimum_msat": 1
},
"ListpeerchannelsRequest": {
"ListPeerChannels.channel_id": 3,
"ListPeerChannels.id": 1,
"ListPeerChannels.short_channel_id": 2
},
Expand Down Expand Up @@ -10692,6 +10693,10 @@
"added": "v23.02",
"deprecated": null
},
"ListPeerChannels.channel_id": {
"added": "v26.03",
"deprecated": null
},
"ListPeerChannels.channels[]": {
"added": "v23.02",
"deprecated": null
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23853,9 +23853,11 @@
"rpc": "listpeerchannels",
"title": "Command returning data on channels of connected lightning nodes",
"description": [
"The **listpeerchannels** RPC command returns list of this node's channels, with the possibility to filter them by peer's node id.",
"The **listpeerchannels** RPC command returns a list of this node's channels.",
"",
"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."
"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.",
"",
"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."
],
"categories": [
"readonly"
Expand All @@ -23867,14 +23869,21 @@
"id": {
"type": "pubkey",
"description": [
"If supplied, limits the channels to just the peer with the given ID, if it exists."
"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'."
]
},
"short_channel_id": {
"added": "v25.05",
"type": "short_channel_id",
"description": [
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
"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'."
]
},
"channel_id": {
"added": "v26.03",
"type": "hash",
"description": [
"If supplied, limits the channels to just this channel_id, if it exists. Cannot be used with 'id' or 'short_channel_id'."
]
}
}
Expand Down
3 changes: 2 additions & 1 deletion contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def listpeers(self, peerid=None, level=None):
}
return self.call("listpeers", payload)

def listpeerchannels(self, peer_id=None, short_channel_id=None):
def listpeerchannels(self, peer_id=None, short_channel_id=None, channel_id=None):
"""
Show current peers channels, and if the {peer_id} is specified
all the channels for the peer are returned, and if {short_channel_id} is
Expand All @@ -1071,6 +1071,7 @@ def listpeerchannels(self, peer_id=None, short_channel_id=None):
payload = {
"id": peer_id,
"short_channel_id": short_channel_id,
"channel_id": channel_id,
}
return self.call("listpeerchannels", payload)

Expand Down
1,698 changes: 849 additions & 849 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions doc/schemas/listpeerchannels.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"rpc": "listpeerchannels",
"title": "Command returning data on channels of connected lightning nodes",
"description": [
"The **listpeerchannels** RPC command returns list of this node's channels, with the possibility to filter them by peer's node id.",
"The **listpeerchannels** RPC command returns a list of this node's channels.",
"",
"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."
"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.",
"",
"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."
],
"categories": [
"readonly"
Expand All @@ -19,14 +21,21 @@
"id": {
"type": "pubkey",
"description": [
"If supplied, limits the channels to just the peer with the given ID, if it exists."
"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'."
]
},
"short_channel_id": {
"added": "v25.05",
"type": "short_channel_id",
"description": [
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
"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'."
]
},
"channel_id": {
"added": "v26.03",
"type": "hash",
"description": [
"If supplied, limits the channels to just this channel_id, if it exists. Cannot be used with 'id' or 'short_channel_id'."
]
}
}
Expand Down
15 changes: 13 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ccan/tal/str/str.h>
#include <channeld/channeld_wiregen.h>
#include <common/addr.h>
#include <common/channel_id.h>
#include <common/htlc_trim.h>
#include <common/initial_commit_tx.h>
#include <common/json_channel_type.h>
Expand Down Expand Up @@ -2631,16 +2632,22 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
struct peer *peer;
struct json_stream *response;
struct short_channel_id *scid;
struct channel_id *cid;

if (!param_check(cmd, buffer, params,
p_opt("id", param_node_id, &peer_id),
p_opt("short_channel_id", param_short_channel_id, &scid),
p_opt("channel_id", param_channel_id, &cid),
NULL))
return command_param_failed();

if (scid && peer_id)
int count = (peer_id != NULL) + (scid != NULL) + (cid != NULL);
if (count > 1) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Cannot specify both short_channel_id and id");
"Must not specify more than one of "
"short_channel_id, channel_id or id"
);
}

response = json_stream_success(cmd);
json_array_start(response, "channels");
Expand All @@ -2653,6 +2660,10 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true);
if (c)
json_add_channel(cmd, response, NULL, c, c->peer);
} else if (cid) {
const struct channel *c = channel_by_cid(cmd->ld, cid);
if (c)
json_add_channel(cmd, response, NULL, c, c->peer);
} else {
struct peer_node_id_map_iter it;

Expand Down
4 changes: 4 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void broadcast_tx_(const tal_t *ctx UNNEEDED,
bool (*refresh)(struct channel * UNNEEDED, const struct bitcoin_tx ** UNNEEDED, void *) UNNEEDED,
void *cbarg TAKES UNNEEDED)
{ fprintf(stderr, "broadcast_tx_ called!\n"); abort(); }
/* Generated stub for channel_by_cid */
struct channel *channel_by_cid(struct lightningd *ld UNNEEDED,
const struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "channel_by_cid called!\n"); abort(); }
/* Generated stub for channel_change_state_reason_str */
const char *channel_change_state_reason_str(enum state_change reason UNNEEDED)
{ fprintf(stderr, "channel_change_state_reason_str called!\n"); abort(); }
Expand Down
1 change: 1 addition & 0 deletions plugins/lsps-plugin/src/lsps2/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl<A: ClnApi> HtlcAcceptedHookHandler<A> {
let mut is_active = false;
while !is_active {
let ls_ch_req = ListpeerchannelsRequest {
channel_id: None,
id: Some(ds_rec.peer_id),
short_channel_id: None,
};
Expand Down
15 changes: 14 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4886,8 +4886,21 @@ def test_listpeerchannels_by_scid(node_factory):
assert l2.rpc.listpeerchannels(short_channel_id=c['alias']['local']) == chans
assert l2.rpc.listpeerchannels(short_channel_id=c['alias']['remote']) == {'channels': []}

with pytest.raises(RpcError, match="Cannot specify both short_channel_id and id"):
with pytest.raises(RpcError, match="Must not specify more than one of short_channel_id, channel_id or id"):
l2.rpc.listpeerchannels(peer_id=l1.info['id'], short_channel_id='1x2x3')
l2.rpc.listpeerchannels(channel_id=c["channel_id"], short_channel_id='1x2x3')


def test_listpeerchannels_by_channel_id(node_factory):
l1, l2, l3 = node_factory.line_graph(3, announce_channels=False)

chans = l2.rpc.listpeerchannels(l1.info['id'])
c = only_one(chans['channels'])
assert l2.rpc.listpeerchannels(channel_id=c['channel_id']) == chans

with pytest.raises(RpcError, match="Must not specify more than one of short_channel_id, channel_id or id"):
l2.rpc.listpeerchannels(peer_id=l1.info['id'], channel_id=c['channel_id'])
l2.rpc.listpeerchannels(short_channel_id="1x2x3", channel_id=['channel_id'])


def test_networkevents(node_factory, executor):
Expand Down
Loading