Skip to content

Commit a81c1c5

Browse files
yaslamacdecker
authored andcommitted
Add no-reconnect-private option to disable automatic reconnect-attempts
to peers connected to our node with private channels only
1 parent abfe55e commit a81c1c5

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

lightningd/connect_control.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ void try_reconnect(const tal_t *ctx,
391391
{
392392
if (!peer->ld->reconnect)
393393
return;
394+
if (!peer->ld->reconnect_private) {
395+
u32 public_channels = 0;
396+
struct channel *channel;
397+
list_for_each(&peer->channels, channel, list) {
398+
if (channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)
399+
public_channels++;
400+
}
401+
if (public_channels == 0)
402+
return;
403+
}
394404

395405
/* Did we last attempt to connect recently? Enter backoff mode. */
396406
if (time_less(time_between(time_now(), peer->last_connect_attempt),

lightningd/lightningd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
243243
ld->listen = true;
244244
ld->autolisten = true;
245245
ld->reconnect = true;
246+
ld->reconnect_private = true;
246247
ld->try_reexec = false;
247248
ld->recover_secret = NULL;
248249
ld->db_upgrade_ok = NULL;

lightningd/lightningd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ struct lightningd {
172172
/* Do we want to reconnect to other peers? */
173173
bool reconnect;
174174

175+
/* Do we want to reconnect to other peers having only unannouced channels with us? */
176+
bool reconnect_private;
177+
175178
/* How many outstanding startup connection attempts? */
176179
size_t num_startup_connects;
177180

lightningd/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ static void dev_register_opts(struct lightningd *ld)
804804
opt_set_invbool,
805805
&ld->reconnect,
806806
"Disable automatic reconnect-attempts by this node, but accept incoming");
807+
clnopt_noarg("--dev-no-reconnect-private", OPT_DEV,
808+
opt_set_invbool,
809+
&ld->reconnect_private,
810+
"Disable automatic reconnect-attempts to peers with private channel(s) only, but accept incoming");
807811
clnopt_noarg("--dev-fast-reconnect", OPT_DEV,
808812
opt_set_bool,
809813
&ld->dev_fast_reconnect,

0 commit comments

Comments
 (0)