Skip to content

Commit c5cde13

Browse files
committed
chanbackup: only send channel backups to max 2 peers at a time.
This, too, is vital for large nodes, which don't want a significant traffic increase. Signed-off-by: Rusty Russell <[email protected]>
1 parent 90bbd8a commit c5cde13

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

plugins/chanbackup.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
/* VERSION is the current version of the data encrypted in the file */
2929
#define VERSION ((u64)1)
3030

31+
/* How many peers do we send a backup to? */
32+
#define NUM_BACKUP_PEERS 2
33+
3134
struct peer_backup {
3235
struct node_id peer;
3336
/* Empty if it's a placeholder */
@@ -561,7 +564,7 @@ static struct command_result *send_to_peers(struct command *cmd)
561564
get_file_data(tmpctx, cmd->plugin));
562565

563566
*idx = 0;
564-
for (peer = peer_map_first(cb->peers, &it);
567+
for (peer = peer_map_pick(cb->peers, pseudorand_u64(), &it);
565568
peer;
566569
peer = peer_map_next(cb->peers, &it)) {
567570
struct info *info = tal(cmd, struct info);
@@ -579,6 +582,10 @@ static struct command_result *send_to_peers(struct command *cmd)
579582
json_add_hex_talarr(req->js, "msg", serialise_scb);
580583
(*info->idx)++;
581584
send_outreq(req);
585+
586+
/* Only send to NUM_BACKUP_PEERS for each update */
587+
if (*info->idx == NUM_BACKUP_PEERS)
588+
break;
582589
}
583590

584591
if (*idx == 0)

0 commit comments

Comments
 (0)