Skip to content

Commit

Permalink
Add no-reconnect-private option to disable automatic reconnect-attempts
Browse files Browse the repository at this point in the history
to peers connected to our node with private channels only
  • Loading branch information
yaslama authored and cdecker committed Feb 13, 2024
1 parent abfe55e commit a81c1c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ void try_reconnect(const tal_t *ctx,
{
if (!peer->ld->reconnect)
return;
if (!peer->ld->reconnect_private) {
u32 public_channels = 0;
struct channel *channel;
list_for_each(&peer->channels, channel, list) {
if (channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)
public_channels++;
}
if (public_channels == 0)
return;
}

/* Did we last attempt to connect recently? Enter backoff mode. */
if (time_less(time_between(time_now(), peer->last_connect_attempt),
Expand Down
1 change: 1 addition & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->listen = true;
ld->autolisten = true;
ld->reconnect = true;
ld->reconnect_private = true;
ld->try_reexec = false;
ld->recover_secret = NULL;
ld->db_upgrade_ok = NULL;
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ struct lightningd {
/* Do we want to reconnect to other peers? */
bool reconnect;

/* Do we want to reconnect to other peers having only unannouced channels with us? */
bool reconnect_private;

/* How many outstanding startup connection attempts? */
size_t num_startup_connects;

Expand Down
4 changes: 4 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,10 @@ static void dev_register_opts(struct lightningd *ld)
opt_set_invbool,
&ld->reconnect,
"Disable automatic reconnect-attempts by this node, but accept incoming");
clnopt_noarg("--dev-no-reconnect-private", OPT_DEV,
opt_set_invbool,
&ld->reconnect_private,
"Disable automatic reconnect-attempts to peers with private channel(s) only, but accept incoming");
clnopt_noarg("--dev-fast-reconnect", OPT_DEV,
opt_set_bool,
&ld->dev_fast_reconnect,
Expand Down

0 comments on commit a81c1c5

Please sign in to comment.