@@ -4705,6 +4705,14 @@ struct CommitmentTxInfoCached {
47054705 feerate: u32,
47064706}
47074707
4708+ /// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
4709+ /// return type of `FundedChannel::validate_commitment_signed`.
4710+ struct LatestHolderCommitmentTXInfo {
4711+ pub commitment_tx: HolderCommitmentTransaction,
4712+ pub htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
4713+ pub nondust_htlc_sources: Vec<HTLCSource>,
4714+ }
4715+
47084716/// Contents of a wire message that fails an HTLC backwards. Useful for [`FundedChannel::fail_htlc`] to
47094717/// fail with either [`msgs::UpdateFailMalformedHTLC`] or [`msgs::UpdateFailHTLC`] as needed.
47104718trait FailHTLCContents {
@@ -5493,22 +5501,9 @@ impl<SP: Deref> FundedChannel<SP> where
54935501 Ok(channel_monitor)
54945502 }
54955503
5496- pub fn commitment_signed <L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate> , ChannelError>
5504+ fn validate_commitment_signed <L: Deref>(&self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<LatestHolderCommitmentTXInfo , ChannelError>
54975505 where L::Target: Logger
54985506 {
5499- if self.context.channel_state.is_quiescent() {
5500- return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
5501- }
5502- if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
5503- return Err(ChannelError::close("Got commitment signed message when channel was not in an operational state".to_owned()));
5504- }
5505- if self.context.channel_state.is_peer_disconnected() {
5506- return Err(ChannelError::close("Peer sent commitment_signed when we needed a channel_reestablish".to_owned()));
5507- }
5508- if self.context.channel_state.is_both_sides_shutdown() && self.context.last_sent_closing_fee.is_some() {
5509- return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
5510- }
5511-
55125507 let funding_script = self.funding.get_funding_redeemscript();
55135508
55145509 let keys = self.context.build_holder_transaction_keys(&self.funding, self.holder_commitment_point.current_point());
@@ -5621,6 +5616,31 @@ impl<SP: Deref> FundedChannel<SP> where
56215616 self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.outbound_htlc_preimages)
56225617 .map_err(|_| ChannelError::close("Failed to validate our commitment".to_owned()))?;
56235618
5619+ Ok(LatestHolderCommitmentTXInfo {
5620+ commitment_tx: holder_commitment_tx,
5621+ htlc_outputs: htlcs_and_sigs,
5622+ nondust_htlc_sources,
5623+ })
5624+ }
5625+
5626+ pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5627+ where L::Target: Logger
5628+ {
5629+ if self.context.channel_state.is_quiescent() {
5630+ return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
5631+ }
5632+ if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
5633+ return Err(ChannelError::close("Got commitment signed message when channel was not in an operational state".to_owned()));
5634+ }
5635+ if self.context.channel_state.is_peer_disconnected() {
5636+ return Err(ChannelError::close("Peer sent commitment_signed when we needed a channel_reestablish".to_owned()));
5637+ }
5638+ if self.context.channel_state.is_both_sides_shutdown() && self.context.last_sent_closing_fee.is_some() {
5639+ return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
5640+ }
5641+
5642+ let commitment_tx_info = self.validate_commitment_signed(msg, logger)?;
5643+
56245644 // Update state now that we've passed all the can-fail calls...
56255645 let mut need_commitment = false;
56265646 if let &mut Some((_, ref mut update_state)) = &mut self.context.pending_update_fee {
@@ -5660,13 +5680,16 @@ impl<SP: Deref> FundedChannel<SP> where
56605680 }
56615681 }
56625682
5683+ let LatestHolderCommitmentTXInfo {
5684+ commitment_tx, htlc_outputs, nondust_htlc_sources,
5685+ } = commitment_tx_info;
56635686 self.context.latest_monitor_update_id += 1;
56645687 let mut monitor_update = ChannelMonitorUpdate {
56655688 update_id: self.context.latest_monitor_update_id,
56665689 counterparty_node_id: Some(self.context.counterparty_node_id),
56675690 updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5668- commitment_tx: holder_commitment_tx ,
5669- htlc_outputs: htlcs_and_sigs ,
5691+ commitment_tx,
5692+ htlc_outputs,
56705693 claimed_htlcs,
56715694 nondust_htlc_sources,
56725695 }],
0 commit comments