Skip to content

Commit 8974375

Browse files
committed
lightningd: add short_channel_id option to listpeerchannels.
Requested-by: @whitslack Closes: #8233 Changelog-Added: JSON-RPC: `listpeerchannels` now has a `short_channel_id` parameter for just listing a specific channel. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 5a3943f commit 8974375

File tree

10 files changed

+821
-773
lines changed

10 files changed

+821
-773
lines changed

.msggen.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@
27812781
"ListPeerChannels.channels[].updates.remote.htlc_minimum_msat": 1
27822782
},
27832783
"ListpeerchannelsRequest": {
2784-
"ListPeerChannels.id": 1
2784+
"ListPeerChannels.id": 1,
2785+
"ListPeerChannels.short_channel_id": 2
27852786
},
27862787
"ListpeerchannelsResponse": {
27872788
"ListPeerChannels.channels[]": 1
@@ -10338,6 +10339,10 @@
1033810339
"added": "v23.02",
1033910340
"deprecated": null
1034010341
},
10342+
"ListPeerChannels.short_channel_id": {
10343+
"added": "v25.05",
10344+
"deprecated": null
10345+
},
1034110346
"ListPeers": {
1034210347
"added": "pre-v0.10.1",
1034310348
"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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23126,6 +23126,13 @@
2312623126
"description": [
2312723127
"If supplied, limits the channels to just the peer with the given ID, if it exists."
2312823128
]
23129+
},
23130+
"short_channel_id": {
23131+
"added": "v25.05",
23132+
"type": "short_channel_id",
23133+
"description": [
23134+
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
23135+
]
2312923136
}
2313023137
}
2313123138
},

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,15 @@ def listpeers(self, peerid=None, level=None):
10081008
}
10091009
return self.call("listpeers", payload)
10101010

1011-
def listpeerchannels(self, peer_id=None):
1011+
def listpeerchannels(self, peer_id=None, short_channel_id=None):
10121012
"""
10131013
Show current peers channels, and if the {peer_id} is specified
1014-
all the channels for the peer are returned.
1014+
all the channels for the peer are returned, and if {short_channel_id} is
1015+
specified only that channel is returned.
10151016
"""
10161017
payload = {
10171018
"id": peer_id,
1019+
"short_channel_id": short_channel_id,
10181020
}
10191021
return self.call("listpeerchannels", payload)
10201022

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

Lines changed: 766 additions & 766 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
"description": [
2222
"If supplied, limits the channels to just the peer with the given ID, if it exists."
2323
]
24+
},
25+
"short_channel_id": {
26+
"added": "v25.05",
27+
"type": "short_channel_id",
28+
"description": [
29+
"If supplied, limits the channels to just this short_channel_id (or local alias), if it exists. Cannot be used with 'id'."
30+
]
2431
}
2532
}
2633
},

lightningd/peer_control.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,20 +2465,29 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
24652465
struct node_id *peer_id;
24662466
struct peer *peer;
24672467
struct json_stream *response;
2468+
struct short_channel_id *scid;
24682469

2469-
/* FIME: filter by status */
2470-
if (!param(cmd, buffer, params,
2471-
p_opt("id", param_node_id, &peer_id),
2472-
NULL))
2470+
if (!param_check(cmd, buffer, params,
2471+
p_opt("id", param_node_id, &peer_id),
2472+
p_opt("short_channel_id", param_short_channel_id, &scid),
2473+
NULL))
24732474
return command_param_failed();
24742475

2476+
if (scid && peer_id)
2477+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2478+
"Cannot specify both short_channel_id and id");
2479+
24752480
response = json_stream_success(cmd);
24762481
json_array_start(response, "channels");
24772482

24782483
if (peer_id) {
24792484
peer = peer_by_id(cmd->ld, peer_id);
24802485
if (peer)
24812486
json_add_peerchannels(cmd, response, peer);
2487+
} else if (scid) {
2488+
const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true);
2489+
if (c)
2490+
json_add_channel(cmd, response, NULL, c, c->peer);
24822491
} else {
24832492
struct peer_node_id_map_iter it;
24842493

tests/test_connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,3 +4780,16 @@ def test_private_channel_no_reconnect(node_factory):
47804780
wait_for(lambda: only_one(l3.rpc.listpeers()['peers'])['connected'] is True)
47814781

47824782
assert only_one(l1.rpc.listpeers()['peers'])['connected'] is False
4783+
4784+
4785+
def test_listpeerchannels_by_scid(node_factory):
4786+
l1, l2, l3 = node_factory.line_graph(3, announce_channels=False)
4787+
4788+
chans = l2.rpc.listpeerchannels(l1.info['id'])
4789+
c = only_one(chans['channels'])
4790+
assert l2.rpc.listpeerchannels(short_channel_id=c['short_channel_id']) == chans
4791+
assert l2.rpc.listpeerchannels(short_channel_id=c['alias']['local']) == chans
4792+
assert l2.rpc.listpeerchannels(short_channel_id=c['alias']['remote']) == {'channels': []}
4793+
4794+
with pytest.raises(RpcError, match="Cannot specify both short_channel_id and id"):
4795+
l2.rpc.listpeerchannels(peer_id=l1.info['id'], short_channel_id='1x2x3')

0 commit comments

Comments
 (0)