channel_control: break out function for on_funding_locked

We're about to move channel-locking over to dualopend, and will want to
reuse this.
This commit is contained in:
niftynei 2020-11-23 19:24:50 -06:00 committed by Christian Decker
parent b2bb80cb1b
commit c5e28e4746
2 changed files with 20 additions and 8 deletions

View File

@ -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);

View File

@ -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);