Skip to content

Commit

Permalink
lightningd: don't kill subds immediately on disconnect.
Browse files Browse the repository at this point in the history
Give them time to process any final messages!  If there's a reconnect,
then we need to clean them up immediately of course.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Jul 19, 2022
1 parent 6a28171 commit 671e664
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 16 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@ void maybe_delete_peer(struct peer *peer)
delete_peer(peer);
}

void peer_channels_cleanup_on_disconnect(struct peer *peer)
static void peer_channels_cleanup(struct lightningd *ld,
const struct node_id *id)
{
struct peer *peer;
struct channel *c, **channels;

peer = peer_by_id(ld, id);
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)
Expand Down Expand Up @@ -1297,6 +1303,11 @@ void peer_connected(struct lightningd *ld, const u8 *msg)
fatal("Connectd gave bad CONNECT_PEER_CONNECTED message %s",
tal_hex(msg, msg));

/* When a peer disconnects, we give subds time to clean themselves up
* (this lets connectd ensure they've seen the final messages). But
* nowe it's reconnected, we've gotta force them out. */
peer_channels_cleanup(ld, &id);

/* If we're already dealing with this peer, hand off to correct
* subdaemon. Otherwise, we'll hand to openingd to wait there. */
peer = peer_by_id(ld, &id);
Expand Down Expand Up @@ -1526,7 +1537,10 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
log_peer_debug(ld->log, &id, "peer_disconnect_done");
p->connected = PEER_DISCONNECTED;

peer_channels_cleanup_on_disconnect(p);
/* If there are literally no channels, might as well
* free immediately. */
if (!p->uncommitted_channel && list_empty(&p->channels))
tal_free(p);
}

/* If you were trying to connect, it failed. */
Expand Down
3 changes: 0 additions & 3 deletions lightningd/peer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ void peer_connected(struct lightningd *ld, const u8 *msg);
void peer_disconnect_done(struct lightningd *ld, const u8 *msg);
void peer_spoke(struct lightningd *ld, const u8 *msg);

/* May delete peer! */
void peer_channels_cleanup_on_disconnect(struct peer *peer);

/* Could be configurable. */
#define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL

Expand Down

0 comments on commit 671e664

Please sign in to comment.