diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 2c92afbe9..d684f1ff5 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -149,6 +149,22 @@ static void lockin_complete(struct channel *channel) record_channel_open(channel); } +bool channel_on_funding_locked(struct channel *channel, + struct pubkey *next_per_commitment_point) +{ + if (channel->remote_funding_locked) { + channel_internal_error(channel, + "channel_got_funding_locked twice"); + return false; + } + update_per_commit_point(channel, next_per_commitment_point); + + log_debug(channel->log, "Got funding_locked"); + channel->remote_funding_locked = true; + + return true; +} + /* We were informed by channeld that it announced the channel and sent * an update, so we can now start sending a node_announcement. The * first step is to build the provisional announcement and ask the HSM @@ -166,15 +182,8 @@ static void peer_got_funding_locked(struct channel *channel, const u8 *msg) return; } - if (channel->remote_funding_locked) { - channel_internal_error(channel, - "channel_got_funding_locked twice"); + if (!channel_on_funding_locked(channel, &next_per_commitment_point)) return; - } - update_per_commit_point(channel, &next_per_commitment_point); - - log_debug(channel->log, "Got funding_locked"); - channel->remote_funding_locked = true; if (channel->scid) lockin_complete(channel); diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h index 735e73e1c..53395a6b0 100644 --- a/lightningd/channel_control.h +++ b/lightningd/channel_control.h @@ -29,6 +29,9 @@ void channel_notify_new_block(struct lightningd *ld, struct command_result *cancel_channel_before_broadcast(struct command *cmd, struct peer *peer); +/* Update the channel info on funding locked */ +bool channel_on_funding_locked(struct channel *channel, + struct pubkey *next_per_commitment_point); /* Forget a channel. Deletes the channel and handles all * associated waiting commands, if present. Notifies peer if available */ void forget_channel(struct channel *channel, const char *err_msg);