@@ -52,7 +52,7 @@ use crate::ln::chan_utils;
52
52
use crate::ln::onion_utils::HTLCFailReason;
53
53
use crate::chain::BestBlock;
54
54
use 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};
56
56
use crate::chain::transaction::{OutPoint, TransactionData};
57
57
use crate::sign::ecdsa::EcdsaChannelSigner;
58
58
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
@@ -5494,22 +5494,9 @@ impl<SP: Deref> FundedChannel<SP> where
5494
5494
Ok(channel_monitor)
5495
5495
}
5496
5496
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>
5498
5498
where L::Target: Logger
5499
5499
{
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
-
5513
5500
let funding_script = self.funding.get_funding_redeemscript();
5514
5501
5515
5502
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
5622
5609
self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.outbound_htlc_preimages)
5623
5610
.map_err(|_| ChannelError::close("Failed to validate our commitment".to_owned()))?;
5624
5611
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
+
5625
5637
// Update state now that we've passed all the can-fail calls...
5626
5638
let mut need_commitment = false;
5627
5639
if let &mut Some((_, ref mut update_state)) = &mut self.context.pending_update_fee {
@@ -5661,13 +5673,16 @@ impl<SP: Deref> FundedChannel<SP> where
5661
5673
}
5662
5674
}
5663
5675
5676
+ let LatestHolderCommitmentTXInfo {
5677
+ commitment_tx, htlc_outputs, nondust_htlc_sources,
5678
+ } = commitment_tx_info;
5664
5679
self.context.latest_monitor_update_id += 1;
5665
5680
let mut monitor_update = ChannelMonitorUpdate {
5666
5681
update_id: self.context.latest_monitor_update_id,
5667
5682
counterparty_node_id: Some(self.context.counterparty_node_id),
5668
5683
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5669
- commitment_tx: holder_commitment_tx ,
5670
- htlc_outputs: htlcs_and_sigs ,
5684
+ commitment_tx,
5685
+ htlc_outputs,
5671
5686
claimed_htlcs,
5672
5687
nondust_htlc_sources,
5673
5688
}],
0 commit comments