@@ -52,7 +52,7 @@ use crate::ln::chan_utils;
5252use crate::ln::onion_utils::HTLCFailReason;
5353use crate::chain::BestBlock;
5454use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
55- use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
55+ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LatestHolderCommitmentTXInfo, LATENCY_GRACE_PERIOD_BLOCKS};
5656use crate::chain::transaction::{OutPoint, TransactionData};
5757use crate::sign::ecdsa::EcdsaChannelSigner;
5858use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
@@ -5494,22 +5494,9 @@ impl<SP: Deref> FundedChannel<SP> where
54945494 Ok(channel_monitor)
54955495 }
54965496
5497- pub fn commitment_signed <L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate> , ChannelError>
5497+ fn validate_commitment_signed <L: Deref>(&self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<LatestHolderCommitmentTXInfo , ChannelError>
54985498 where L::Target: Logger
54995499 {
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-
55135500 let funding_script = self.funding.get_funding_redeemscript();
55145501
55155502 let keys = self.context.build_holder_transaction_keys(&self.funding, self.holder_commitment_point.current_point());
@@ -5622,6 +5609,31 @@ impl<SP: Deref> FundedChannel<SP> where
56225609 self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.outbound_htlc_preimages)
56235610 .map_err(|_| ChannelError::close("Failed to validate our commitment".to_owned()))?;
56245611
5612+ Ok(LatestHolderCommitmentTXInfo {
5613+ commitment_tx: holder_commitment_tx,
5614+ htlc_outputs: htlcs_and_sigs,
5615+ nondust_htlc_sources,
5616+ })
5617+ }
5618+
5619+ pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5620+ where L::Target: Logger
5621+ {
5622+ if self.context.channel_state.is_quiescent() {
5623+ return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
5624+ }
5625+ if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
5626+ return Err(ChannelError::close("Got commitment signed message when channel was not in an operational state".to_owned()));
5627+ }
5628+ if self.context.channel_state.is_peer_disconnected() {
5629+ return Err(ChannelError::close("Peer sent commitment_signed when we needed a channel_reestablish".to_owned()));
5630+ }
5631+ if self.context.channel_state.is_both_sides_shutdown() && self.context.last_sent_closing_fee.is_some() {
5632+ return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
5633+ }
5634+
5635+ let commitment_tx_info = self.validate_commitment_signed(msg, logger)?;
5636+
56255637 // Update state now that we've passed all the can-fail calls...
56265638 let mut need_commitment = false;
56275639 if let &mut Some((_, ref mut update_state)) = &mut self.context.pending_update_fee {
@@ -5661,13 +5673,16 @@ impl<SP: Deref> FundedChannel<SP> where
56615673 }
56625674 }
56635675
5676+ let LatestHolderCommitmentTXInfo {
5677+ commitment_tx, htlc_outputs, nondust_htlc_sources,
5678+ } = commitment_tx_info;
56645679 self.context.latest_monitor_update_id += 1;
56655680 let mut monitor_update = ChannelMonitorUpdate {
56665681 update_id: self.context.latest_monitor_update_id,
56675682 counterparty_node_id: Some(self.context.counterparty_node_id),
56685683 updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5669- commitment_tx: holder_commitment_tx ,
5670- htlc_outputs: htlcs_and_sigs ,
5684+ commitment_tx,
5685+ htlc_outputs,
56715686 claimed_htlcs,
56725687 nondust_htlc_sources,
56735688 }],
0 commit comments