lightningd: clean up subds before freeing HTLCs.

Otherwise we get weird effects, as htlcs are being freed:

```
2022-01-26T05:07:37.8774610Z lightningd-1: 2022-01-26T04:47:48.770Z DEBUG   030eeb52087b9dbb27b7aec79ca5249369f6ce7b20a5684ce38d9f4595a21c2fda-chan#8: Failing HTLC 18446744073709551615 due to peer death
2022-01-26T05:07:37.8775287Z lightningd-1: 2022-01-26T04:47:48.770Z **BROKEN** 030eeb52087b9dbb27b7aec79ca5249369f6ce7b20a5684ce38d9f4595a21c2fda-chan#8: Neither origin nor in?
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-01-30 14:07:30 +10:30
parent d370aac020
commit 0c24334738
5 changed files with 42 additions and 5 deletions

View File

@@ -105,7 +105,9 @@ void uncommitted_channel_disconnect(struct uncommitted_channel *uc,
{
u8 *msg = towire_connectd_peer_disconnected(tmpctx, &uc->peer->id);
log_(uc->log, level, NULL, false, "%s", desc);
subd_send_msg(uc->peer->ld->connectd, msg);
/* NULL when we're shutting down */
if (uc->peer->ld->connectd)
subd_send_msg(uc->peer->ld->connectd, msg);
if (uc->fc && uc->fc->cmd)
was_pending(command_fail(uc->fc->cmd, LIGHTNINGD, "%s", desc));
notify_disconnect(uc->peer->ld, &uc->peer->id);
@@ -191,9 +193,11 @@ void handle_reestablish(struct lightningd *ld,
"Unknown channel for reestablish");
log_debug(ld->log, "Reestablish on UNKNOWN channel %s",
type_to_string(tmpctx, struct channel_id, channel_id));
subd_send_msg(ld->connectd,
take(towire_connectd_peer_final_msg(NULL, peer_id,
err)));
/* Unless we're shutting down */
if (ld->connectd)
subd_send_msg(ld->connectd,
take(towire_connectd_peer_final_msg(NULL, peer_id,
err)));
tal_free(peer_fd);
}
}