Skip to content

Commit 90bbd8a

Browse files
committed
chanbackup: use peer table instead of calling "listpeerchannels".
This is much better for very large nodes with lots of channel activity. Signed-off-by: Rusty Russell <[email protected]>
1 parent 4eafc1a commit 90bbd8a

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

plugins/chanbackup.c

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -536,20 +536,16 @@ static struct command_result *after_send_scb_single_fail(struct command *cmd,
536536
return notification_or_hook_done(cmd);
537537
}
538538

539-
static struct command_result *after_listpeers(struct command *cmd,
540-
const char *method,
541-
const char *buf,
542-
const jsmntok_t *params,
543-
void *cb_arg UNUSED)
539+
static struct command_result *send_to_peers(struct command *cmd)
544540
{
545-
const jsmntok_t *peers, *peer;
546541
struct out_req *req;
547-
size_t i;
548542
size_t *idx = tal(cmd, size_t);
549-
bool is_connected;
550543
u8 *serialise_scb;
544+
struct peer_map_iter it;
545+
const struct node_id *peer;
546+
struct chanbackup *cb = chanbackup(cmd->plugin);
551547

552-
if (!chanbackup(cmd->plugin)->peer_backup)
548+
if (!cb->peer_backup)
553549
return notification_or_hook_done(cmd);
554550

555551
/* BOLT #1:
@@ -564,42 +560,25 @@ static struct command_result *after_listpeers(struct command *cmd,
564560
serialise_scb = towire_peer_storage(cmd,
565561
get_file_data(tmpctx, cmd->plugin));
566562

567-
peers = json_get_member(buf, params, "peers");
568-
569563
*idx = 0;
570-
json_for_each_arr(i, peer, peers) {
571-
const char *err;
572-
u8 *features;
573-
574-
/* If connected is false, features is missing, so this fails */
575-
err = json_scan(cmd, buf, peer,
576-
"{connected:%,features:%}",
577-
JSON_SCAN(json_to_bool, &is_connected),
578-
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex,
579-
&features));
580-
if (err || !is_connected)
581-
continue;
564+
for (peer = peer_map_first(cb->peers, &it);
565+
peer;
566+
peer = peer_map_next(cb->peers, &it)) {
567+
struct info *info = tal(cmd, struct info);
582568

583-
/* We shouldn't have to check, but LND hangs up? */
584-
if (feature_offered(features, OPT_PROVIDE_STORAGE)) {
585-
const jsmntok_t *nodeid;
586-
struct info *info = tal(cmd, struct info);
587-
588-
info->idx = idx;
589-
nodeid = json_get_member(buf, peer, "id");
590-
json_to_node_id(buf, nodeid, &info->node_id);
591-
592-
req = jsonrpc_request_start(cmd,
593-
"sendcustommsg",
594-
after_send_scb_single,
595-
after_send_scb_single_fail,
596-
info);
597-
598-
json_add_node_id(req->js, "node_id", &info->node_id);
599-
json_add_hex_talarr(req->js, "msg", serialise_scb);
600-
(*info->idx)++;
601-
send_outreq(req);
602-
}
569+
info->idx = idx;
570+
info->node_id = *peer;
571+
572+
req = jsonrpc_request_start(cmd,
573+
"sendcustommsg",
574+
after_send_scb_single,
575+
after_send_scb_single_fail,
576+
info);
577+
578+
json_add_node_id(req->js, "node_id", &info->node_id);
579+
json_add_hex_talarr(req->js, "msg", serialise_scb);
580+
(*info->idx)++;
581+
send_outreq(req);
603582
}
604583

605584
if (*idx == 0)
@@ -615,17 +594,12 @@ static struct command_result *after_staticbackup(struct command *cmd,
615594
{
616595
struct modern_scb_chan **scb_chan;
617596
const jsmntok_t *scbs = json_get_member(buf, params, "scb");
618-
struct out_req *req;
597+
619598
json_to_scb_chan(buf, scbs, &scb_chan);
620599
plugin_log(cmd->plugin, LOG_DBG, "Updating the SCB");
621600

622601
update_scb(cmd->plugin, scb_chan);
623-
req = jsonrpc_request_start(cmd,
624-
"listpeers",
625-
after_listpeers,
626-
plugin_broken_cb,
627-
NULL);
628-
return send_outreq(req);
602+
return send_to_peers(cmd);
629603
}
630604

631605
/* Write to the datastore */

0 commit comments

Comments
 (0)