From d8221aae760f840b2e614c19b7c358547b54d978 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 21 Jan 2021 20:58:37 -0600 Subject: [PATCH] df: update channel_id when opening; closing; disconnecting We were missing the channel_id for accepter opens; it's also a good idea to reset it to 0xFF when we disconnect totally --- lightningd/dual_open_control.c | 7 +++++++ lightningd/peer_control.c | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 1e89baf48..26f1f203f 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -53,6 +53,9 @@ unsaved_channel_disconnect(struct channel *channel, was_pending(command_fail(channel->open_attempt->cmd, LIGHTNINGD, "%s", desc)); notify_disconnect(channel->peer->ld, &channel->peer->id); + channel->open_attempt = tal_free(channel->open_attempt); + if (list_empty(&channel->inflights)) + memset(&channel->cid, 0xFF, sizeof(channel->cid)); } void kill_unsaved_channel(struct channel *channel, @@ -655,6 +658,7 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS) } } + channel->cid = payload->channel_id; channel->opener = REMOTE; channel->open_attempt = new_channel_open_attempt(channel); msg = towire_dualopend_got_offer_reply(NULL, payload->accepter_funding, @@ -1120,6 +1124,8 @@ opening_failed_cancel_commands(struct channel *channel, /* FIXME: cancels? */ channel->open_attempt = tal_free(channel->open_attempt); + if (list_empty(&channel->inflights)) + memset(&channel->cid, 0xFF, sizeof(channel->cid)); } static void open_failed(struct subd *dualopend, const u8 *msg) @@ -1438,6 +1444,7 @@ static void rbf_got_offer(struct subd *dualopend, const u8 *msg) return; } + assert(channel_id_eq(&channel->cid, &payload->channel_id)); /* Fill in general channel info from channel */ payload->peer_id = channel->peer->id; payload->feerate_our_max = feerate_max(dualopend->ld, NULL); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 2b8590458..e209f45f8 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1152,7 +1152,6 @@ void peer_connected(struct lightningd *ld, const u8 *msg, if (!hook_payload->channel) hook_payload->channel = peer_unsaved_channel(peer); - assert(hook_payload->channel); plugin_hook_call_peer_connected(ld, hook_payload); }