diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 46452978eb..a10ecb9309 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1407,6 +1407,9 @@ pub(super) struct ChannelContext where SP::Target: SignerProvider { /// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is /// outbound or inbound. signer_pending_funding: bool, + /// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a + /// [`msgs::ChannelReady`]. + signer_pending_channel_ready: bool, // pending_update_fee is filled when sending and receiving update_fee. // @@ -1867,6 +1870,7 @@ impl ChannelContext where SP::Target: SignerProvider { signer_pending_commitment_update: false, signer_pending_funding: false, + signer_pending_channel_ready: false, #[cfg(debug_assertions)] @@ -2095,6 +2099,7 @@ impl ChannelContext where SP::Target: SignerProvider { signer_pending_commitment_update: false, signer_pending_funding: false, + signer_pending_channel_ready: false, // We'll add our counterparty's `funding_satoshis` to these max commitment output assertions // when we receive `accept_channel2`. @@ -5321,7 +5326,7 @@ impl Channel where assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0), "Funding transaction broadcast by the local client before it should have - LDK didn't do it!"); self.context.monitor_pending_channel_ready = false; - Some(self.get_channel_ready()) + self.get_channel_ready(logger) } else { None }; let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger); @@ -5624,7 +5629,7 @@ impl Channel where // We have OurChannelReady set! return Ok(ReestablishResponses { - channel_ready: Some(self.get_channel_ready()), + channel_ready: self.get_channel_ready(logger), raa: None, commitment_update: None, order: RAACommitmentOrder::CommitmentFirst, shutdown_msg, announcement_sigs, @@ -5663,7 +5668,7 @@ impl Channel where let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 { // We should never have to worry about MonitorUpdateInProgress resending ChannelReady - Some(self.get_channel_ready()) + self.get_channel_ready(logger) } else { None }; if msg.next_local_commitment_number == next_counterparty_commitment_number { @@ -6554,24 +6559,27 @@ impl Channel where } if self.context.signer_pending_funding { - // TODO: set signer_pending_channel_ready log_debug!(logger, "Can't produce channel_ready: the signer is pending funding."); + self.context.signer_pending_channel_ready = true; return None; } - // TODO: when get_per_commiment_point becomes async, check if the point is - // available, if not, set signer_pending_channel_ready and return None - - Some(self.get_channel_ready()) + self.get_channel_ready(logger) } - fn get_channel_ready(&self) -> msgs::ChannelReady { - debug_assert!(self.context.holder_commitment_point.is_available()); - msgs::ChannelReady { - channel_id: self.context.channel_id(), - next_per_commitment_point: self.context.holder_commitment_point.current_point() - .expect("TODO"), - short_channel_id_alias: Some(self.context.outbound_scid_alias), + fn get_channel_ready(&mut self, logger: &L) -> Option + where L::Target: Logger + { + if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point { + Some(msgs::ChannelReady { + channel_id: self.context.channel_id(), + next_per_commitment_point: current, + short_channel_id_alias: Some(self.context.outbound_scid_alias), + }) + } else { + log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available."); + self.context.signer_pending_channel_ready = true; + None } } @@ -9500,6 +9508,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch signer_pending_commitment_update: false, signer_pending_funding: false, + signer_pending_channel_ready: false, pending_update_fee, holding_cell_update_fee,