diff --git a/lightningd/channel.c b/lightningd/channel.c index a87bc1d9d..cc48c0527 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -386,17 +386,6 @@ void channel_fail_transient(struct channel *channel, const char *fmt, ...) channel_set_owner(channel, NULL); /* Reconnect unless we've dropped/are dropping to chain. */ - if (channel_active(channel)) { - struct lightningd *ld = channel->peer->ld; - -#if DEVELOPER - /* Don't schedule an attempt if we disabled reconnections with - * the `--dev-no-reconnect` flag */ - if (ld->no_reconnect) - return; -#endif /* DEVELOPER */ - u8 *msg = towire_gossipctl_reach_peer(NULL, - &channel->peer->id); - subd_send_msg(ld->gossip, take(msg)); - } + if (channel_active(channel)) + try_reconnect(channel->peer); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 984811f64..c77ce3e52 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1071,6 +1071,22 @@ static const struct json_command close_command = { }; AUTODATA(json_command, &close_command); +void try_reconnect(struct peer *peer) +{ + struct lightningd *ld = peer->ld; + u8 *msg; + +#if DEVELOPER + /* Don't schedule an attempt if we disabled reconnections with + * the `--dev-no-reconnect` flag */ + if (ld->no_reconnect) + return; +#endif /* DEVELOPER */ + + msg = towire_gossipctl_reach_peer(NULL, &peer->id); + subd_send_msg(ld->gossip, take(msg)); +} + static void activate_peer(struct peer *peer) { u8 *msg; @@ -1083,10 +1099,8 @@ static void activate_peer(struct peer *peer) /* We can only have one active channel: reconnect if not already. */ channel = peer_active_channel(peer); - if (channel && !channel->owner) { - msg = towire_gossipctl_reach_peer(peer, &peer->id); - subd_send_msg(peer->ld->gossip, take(msg)); - } + if (channel && !channel->owner) + try_reconnect(peer); list_for_each(&peer->channels, channel, list) { /* Watching lockin may be unnecessary, but it's harmless. */ diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index dd8b524f1..4cac8e46d 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -61,6 +61,9 @@ struct peer *new_peer(struct lightningd *ld, u64 dbid, /* Also removes from db. */ void delete_peer(struct peer *peer); +/* Tell gossipd to try to reconnect (unless --dev-no-reconnect) */ +void try_reconnect(struct peer *peer); + struct peer *peer_by_id(struct lightningd *ld, const struct pubkey *id); struct peer *peer_from_json(struct lightningd *ld, const char *buffer,