lightningd: clean up channels when connectd says peer is gone.

This is redundant now, since connectd only sends us this once we tell
it it's OK, but that's changing, so clean up now.  This means that
connectd will be able to make *unsolicited* closes, if it needs to.

We share logic with peer_please_disconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-07-16 14:19:29 +09:30
committed by neil saitug
parent 9dc3880360
commit c64ce4bbf3
3 changed files with 33 additions and 24 deletions

View File

@@ -390,7 +390,6 @@ static void peer_please_disconnect(struct lightningd *ld, const u8 *msg)
{
struct node_id id;
struct peer *peer;
struct channel *c, **channels;
if (!fromwire_connectd_reconnected(msg, &id))
fatal("Bad msg %s from connectd", tal_hex(tmpctx, msg));
@@ -399,25 +398,7 @@ static void peer_please_disconnect(struct lightningd *ld, const u8 *msg)
if (!peer)
return;
/* Freeing channels can free peer, so gather first. */
channels = tal_arr(tmpctx, struct channel *, 0);
list_for_each(&peer->channels, c, list)
tal_arr_expand(&channels, c);
if (peer->uncommitted_channel)
kill_uncommitted_channel(peer->uncommitted_channel,
"Reconnected");
for (size_t i = 0; i < tal_count(channels); i++) {
c = channels[i];
if (channel_active(c)) {
channel_cleanup_commands(c, "Reconnected");
channel_fail_reconnect(c, "Reconnected");
} else if (channel_unsaved(c)) {
log_info(c->log, "Killing opening daemon: Reconnected");
channel_unsaved_close_conn(c, "Reconnected");
}
}
peer_channels_cleanup_on_disconnect(peer);
}
struct custommsg_payload {