rbf: clean up channel on error

Make sure we clean up unsaved channels appropriately on failure.

We forget the peer/channel if it's unsaved!
This commit is contained in:
niftynei 2021-02-09 15:24:23 -06:00 committed by Rusty Russell
parent ff069ff924
commit 1acc1aa27e
2 changed files with 30 additions and 10 deletions

View File

@ -380,8 +380,35 @@ void channel_errmsg(struct channel *channel,
{
notify_disconnect(channel->peer->ld, &channel->peer->id);
/* Clean up any in-progress open attempts */
if (channel->open_attempt) {
struct open_attempt *oa = channel->open_attempt;
if (oa->cmd) {
was_pending(command_fail(oa->cmd, LIGHTNINGD,
"%s", desc));
oa->cmd = NULL;
}
notify_channel_open_failed(channel->peer->ld, &channel->cid);
channel->open_attempt = tal_free(channel->open_attempt);
}
if (channel->openchannel_signed_cmd) {
was_pending(command_fail(channel->openchannel_signed_cmd,
LIGHTNINGD, "%s", desc));
channel->openchannel_signed_cmd = NULL;
}
/* No per_peer_state means a subd crash or disconnection. */
if (!pps) {
/* If the channel is unsaved, we forget it */
if (channel_unsaved(channel)) {
log_unusual(channel->log, "%s",
"Unsaved peer failed."
" Disconnecting and deleting channel.");
delete_channel(channel);
return;
}
channel_fail_reconnect(channel, "%s: %s",
channel->owner->name, desc);
return;
@ -391,16 +418,6 @@ void channel_errmsg(struct channel *channel,
if (err_for_them && !channel->error && !warning)
channel->error = tal_dup_talarr(channel, u8, err_for_them);
/* Clean up any in-progress open attempts */
if (channel->open_attempt) {
struct open_attempt *oa = channel->open_attempt;
if (oa->cmd)
was_pending(command_fail(oa->cmd, LIGHTNINGD,
"%s", desc));
notify_channel_open_failed(channel->peer->ld, &channel->cid);
channel->open_attempt = tal_free(channel->open_attempt);
}
/* Other implementations chose to ignore errors early on. Not
* surprisingly, they now spew out spurious errors frequently,
* and we would close the channel on them. We now support warnings

View File

@ -606,6 +606,9 @@ u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_bas
/* Generated stub for towire_connectd_connect_to_peer */
u8 *towire_connectd_connect_to_peer(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, u32 seconds_waited UNNEEDED, const struct wireaddr_internal *addrhint UNNEEDED)
{ fprintf(stderr, "towire_connectd_connect_to_peer called!\n"); abort(); }
/* Generated stub for towire_connectd_peer_disconnected */
u8 *towire_connectd_peer_disconnected(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_connectd_peer_disconnected called!\n"); abort(); }
/* Generated stub for towire_dualopend_send_shutdown */
u8 *towire_dualopend_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED)
{ fprintf(stderr, "towire_dualopend_send_shutdown called!\n"); abort(); }