@@ -66,6 +66,8 @@ use crate::util::errors::APIError;
66
66
use crate::util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits, MaxDustHTLCExposure};
67
67
use crate::util::scid_utils::scid_from_parts;
68
68
69
+ use alloc::collections::BTreeMap;
70
+
69
71
use crate::io;
70
72
use crate::prelude::*;
71
73
use core::{cmp,mem,fmt};
@@ -5775,6 +5777,11 @@ impl<SP: Deref> FundedChannel<SP> where
5775
5777
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
5776
5778
)));
5777
5779
}
5780
+
5781
+ if msg.batch.is_some() {
5782
+ return Err(ChannelError::close("Peer sent initial commitment_signed with a batch".to_owned()));
5783
+ }
5784
+
5778
5785
let holder_commitment_point = &mut self.holder_commitment_point.clone();
5779
5786
self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "initial commitment_signed");
5780
5787
@@ -5802,6 +5809,49 @@ impl<SP: Deref> FundedChannel<SP> where
5802
5809
pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5803
5810
where L::Target: Logger
5804
5811
{
5812
+ self.commitment_signed_check_state()?;
5813
+
5814
+ let updates = self
5815
+ .context
5816
+ .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)
5817
+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5818
+ vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5819
+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5820
+ }]
5821
+ )?;
5822
+
5823
+ self.commitment_signed_update_monitor(updates, logger)
5824
+ }
5825
+
5826
+ pub fn commitment_signed_batch<L: Deref>(&mut self, batch: &BTreeMap<Txid, msgs::CommitmentSigned>, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5827
+ where L::Target: Logger
5828
+ {
5829
+ self.commitment_signed_check_state()?;
5830
+
5831
+ // Any commitment_signed not associated with a FundingScope is ignored below if a
5832
+ // pending splice transaction has confirmed since receiving the batch.
5833
+ let updates = core::iter::once(&self.funding)
5834
+ .chain(self.pending_funding.iter())
5835
+ .map(|funding| {
5836
+ let funding_txid = funding.get_funding_txo().unwrap().txid;
5837
+ let msg = batch
5838
+ .get(&funding_txid)
5839
+ .ok_or_else(|| ChannelError::close(format!("Peer did not send a commitment_signed for pending splice transaction: {}", funding_txid)))?;
5840
+ self.context
5841
+ .validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
5842
+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5843
+ ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5844
+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5845
+ }
5846
+ )
5847
+ }
5848
+ )
5849
+ .collect::<Result<Vec<_>, ChannelError>>()?;
5850
+
5851
+ self.commitment_signed_update_monitor(updates, logger)
5852
+ }
5853
+
5854
+ fn commitment_signed_check_state(&self) -> Result<(), ChannelError> {
5805
5855
if self.context.channel_state.is_quiescent() {
5806
5856
return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
5807
5857
}
@@ -5815,8 +5865,12 @@ impl<SP: Deref> FundedChannel<SP> where
5815
5865
return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
5816
5866
}
5817
5867
5818
- let commitment_tx_info = self.context.validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)?;
5868
+ Ok(())
5869
+ }
5819
5870
5871
+ fn commitment_signed_update_monitor<L: Deref>(&mut self, mut updates: Vec<ChannelMonitorUpdateStep>, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5872
+ where L::Target: Logger
5873
+ {
5820
5874
if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
5821
5875
// We only fail to advance our commitment point/number if we're currently
5822
5876
// waiting for our signer to unblock and provide a commitment point.
@@ -5870,18 +5924,21 @@ impl<SP: Deref> FundedChannel<SP> where
5870
5924
}
5871
5925
}
5872
5926
5873
- let LatestHolderCommitmentTXInfo {
5874
- commitment_tx, htlc_outputs, nondust_htlc_sources,
5875
- } = commitment_tx_info;
5927
+ for mut update in updates.iter_mut() {
5928
+ if let ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5929
+ claimed_htlcs: ref mut update_claimed_htlcs, ..
5930
+ } = &mut update {
5931
+ debug_assert!(update_claimed_htlcs.is_empty());
5932
+ *update_claimed_htlcs = claimed_htlcs.clone();
5933
+ } else {
5934
+ debug_assert!(false);
5935
+ }
5936
+ }
5937
+
5876
5938
self.context.latest_monitor_update_id += 1;
5877
5939
let mut monitor_update = ChannelMonitorUpdate {
5878
5940
update_id: self.context.latest_monitor_update_id,
5879
- updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5880
- commitment_tx,
5881
- htlc_outputs,
5882
- claimed_htlcs,
5883
- nondust_htlc_sources,
5884
- }],
5941
+ updates,
5885
5942
channel_id: Some(self.context.channel_id()),
5886
5943
};
5887
5944
0 commit comments