Skip to content

lightningd: add short_channel_id option to listpeerchannels. #8237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
7 changes: 6 additions & 1 deletion .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,8 @@
"ListPeerChannels.channels[].updates.remote.htlc_minimum_msat": 1
},
"ListpeerchannelsRequest": {
"ListPeerChannels.id": 1
"ListPeerChannels.id": 1,
"ListPeerChannels.short_channel_id": 2
},
"ListpeerchannelsResponse": {
"ListPeerChannels.channels[]": 1
Expand Down Expand Up @@ -10338,6 +10339,10 @@
"added": "v23.02",
"deprecated": null
},
"ListPeerChannels.short_channel_id": {
"added": "v25.05",
"deprecated": null
},
"ListPeers": {
"added": "pre-v0.10.1",
"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.

7 changes: 7 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23126,6 +23126,13 @@
"description": [
"If supplied, limits the channels to just the peer with the given ID, if it exists."
]
},
"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'."
]
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,13 +999,15 @@ def listpeers(self, peerid=None, level=None):
}
return self.call("listpeers", payload)

def listpeerchannels(self, peer_id=None):
def listpeerchannels(self, peer_id=None, short_channel_id=None):
"""
Show current peers channels, and if the {peer_id} is specified
all the channels for the peer are returned.
all the channels for the peer are returned, and if {short_channel_id} is
specified only that channel is returned.
"""
payload = {
"id": peer_id,
"short_channel_id": short_channel_id,
}
return self.call("listpeerchannels", payload)

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

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions doc/schemas/listpeerchannels.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"description": [
"If supplied, limits the channels to just the peer with the given ID, if it exists."
]
},
"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'."
]
}
}
},
Expand Down
17 changes: 13 additions & 4 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2465,20 +2465,29 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
struct node_id *peer_id;
struct peer *peer;
struct json_stream *response;
struct short_channel_id *scid;

/* FIME: filter by status */
if (!param(cmd, buffer, params,
p_opt("id", param_node_id, &peer_id),
NULL))
if (!param_check(cmd, buffer, params,
p_opt("id", param_node_id, &peer_id),
p_opt("short_channel_id", param_short_channel_id, &scid),
NULL))
return command_param_failed();

if (scid && peer_id)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Cannot specify both short_channel_id and id");

response = json_stream_success(cmd);
json_array_start(response, "channels");

if (peer_id) {
peer = peer_by_id(cmd->ld, peer_id);
if (peer)
json_add_peerchannels(cmd, response, peer);
} else if (scid) {
const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true);
if (c)
json_add_channel(cmd, response, NULL, c, c->peer);
} else {
struct peer_node_id_map_iter it;

Expand Down
13 changes: 13 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4780,3 +4780,16 @@ def test_private_channel_no_reconnect(node_factory):
wait_for(lambda: only_one(l3.rpc.listpeers()['peers'])['connected'] is True)

assert only_one(l1.rpc.listpeers()['peers'])['connected'] is False


def test_listpeerchannels_by_scid(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(short_channel_id=c['short_channel_id']) == chans
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"):
l2.rpc.listpeerchannels(peer_id=l1.info['id'], short_channel_id='1x2x3')
Loading