Skip to content

Commit 538a007

Browse files
JssDWtcdecker
authored andcommitted
topology: call listpeerchannels_done directly
When cln is run without deprecated apis, the `listchannels` call would still query `listpeerchannels`, even though it wouldn't use the result. This adds unnecessary time to the call. Especially in case the node has many channels. This commit skips the listpeerchannels call in case the outcome won't be used. Changelog-Fixed: Improve listchannels performance
1 parent 81e30ea commit 538a007

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

plugins/topology.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ static void gossmod_add_unknown_localchan(struct gossmap_localmods *mods,
381381
buf, chantok, gossmap);
382382
}
383383

384-
/* FIXME: We don't need this listpeerchannels at all if not deprecated! */
385384
static struct command_result *listpeerchannels_done(struct command *cmd,
386385
const char *buf,
387386
const jsmntok_t *result,
@@ -472,9 +471,18 @@ static struct command_result *json_listchannels(struct command *cmd,
472471
"Can only specify one of "
473472
"`short_channel_id`, "
474473
"`source` or `destination`");
475-
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
474+
475+
// FIXME: Once this deprecation is removed, `listpeerchannels_done` can
476+
// be embedded in the current function.
477+
if (command_deprecated_out_ok(cmd, "include_private", "v24.02", "v24.08")) {
478+
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
476479
listpeerchannels_done, forward_error, opts);
477-
return send_outreq(cmd->plugin, req);
480+
return send_outreq(cmd->plugin, req);
481+
}
482+
483+
// If deprecations are not necessary, call listpeerchannels_done directly,
484+
// the output will not be used there.
485+
return listpeerchannels_done(cmd, NULL, NULL, opts);
478486
}
479487

480488
static void json_add_node(struct json_stream *js,

0 commit comments

Comments
 (0)