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