diff --git a/lightningd/channel.c b/lightningd/channel.c index 69c08b1f7..86678dd75 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -97,6 +99,10 @@ static void destroy_channel(struct channel *channel) channel_state_name(channel), htlc_state_name(hin->hstate)); + for (size_t i = 0; i < tal_count(channel->forgets); i++) + was_pending(command_fail(channel->forgets[i], LIGHTNINGD, + "Channel structure was freed!")); + /* Free any old owner still hanging around. */ channel_set_owner(channel, NULL); @@ -250,6 +256,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->remote_upfront_shutdown_script = tal_steal(channel, remote_upfront_shutdown_script); channel->option_static_remotekey = option_static_remotekey; + channel->forgets = tal_arr(channel, struct command *, 0); list_add_tail(&peer->channels, &channel->list); tal_add_destructor(channel, destroy_channel); diff --git a/lightningd/channel.h b/lightningd/channel.h index bc609e77b..7ac530d7c 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -120,6 +120,9 @@ struct channel { /* Was this negotiated with `option_static_remotekey? */ bool option_static_remotekey; + + /* Any commands trying to forget us. */ + struct command **forgets; }; struct channel *new_channel(struct peer *peer, u64 dbid,