From a418615b7f36c7c1fa9dc67447996559ad9033ab Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Tue, 7 Feb 2023 10:31:38 +0100 Subject: [PATCH] rpc: adds num_channels to listpeers This will save a lot of RPC ping/pong when plugins still need to iterate both, `listpeers` and `listpeerchannels`. When `num_channels` is 0 they can skip additional calls. Changelog-Added: RPC `listpeers` output now has `num_channels`. --- lightningd/peer_control.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index f32eb2917..6a9d19369 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1932,11 +1932,16 @@ static void json_add_peer(struct lightningd *ld, const enum log_level *ll) { struct channel *channel; + u32 num_channels; json_object_start(response, NULL); json_add_node_id(response, "id", &p->id); json_add_bool(response, "connected", p->connected == PEER_CONNECTED); + num_channels = 0; + list_for_each(&p->channels, channel, list) + num_channels++; + json_add_num(response, "num_channels", num_channels); /* If it's not connected, features are unreliable: we don't * store them in the database, and they would only reflect @@ -1954,7 +1959,6 @@ static void json_add_peer(struct lightningd *ld, fmt_wireaddr(response, p->remote_addr)); json_add_hex_talarr(response, "features", p->their_features); } - if (deprecated_apis) { json_array_start(response, "channels"); json_add_uncommitted_channel(response, p->uncommitted_channel, NULL);