@@ -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};
@@ -1515,6 +1517,7 @@ impl<SP: Deref> Channel<SP> where
1515
1517
let mut funded_channel = FundedChannel {
1516
1518
funding: chan.funding,
1517
1519
pending_funding: vec![],
1520
+ commitment_signed_batch: vec![],
1518
1521
context: chan.context,
1519
1522
interactive_tx_signing_session: chan.interactive_tx_signing_session,
1520
1523
holder_commitment_point,
@@ -4916,6 +4919,7 @@ pub(super) struct DualFundingChannelContext {
4916
4919
pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4917
4920
pub funding: FundingScope,
4918
4921
pending_funding: Vec<FundingScope>,
4922
+ commitment_signed_batch: Vec<msgs::CommitmentSigned>,
4919
4923
pub context: ChannelContext<SP>,
4920
4924
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
4921
4925
holder_commitment_point: HolderCommitmentPoint,
@@ -5739,7 +5743,53 @@ impl<SP: Deref> FundedChannel<SP> where
5739
5743
return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
5740
5744
}
5741
5745
5742
- let commitment_tx_info = self.context.validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)?;
5746
+ if msg.batch.is_none() && !self.pending_funding.is_empty() {
5747
+ return Err(ChannelError::close("Peer sent commitment_signed without a batch when there's a pending splice".to_owned()));
5748
+ }
5749
+
5750
+ let mut updates = match &msg.batch {
5751
+ // No pending splice
5752
+ None => {
5753
+ debug_assert!(self.pending_funding.is_empty());
5754
+ self.context
5755
+ .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)
5756
+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5757
+ vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5758
+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5759
+ }]
5760
+ )?
5761
+ },
5762
+ // May or may not have a pending splice
5763
+ Some(batch) => {
5764
+ self.commitment_signed_batch.push(msg.clone());
5765
+ if self.commitment_signed_batch.len() < batch.batch_size as usize {
5766
+ return Ok(None);
5767
+ }
5768
+
5769
+ let commitment_signed_batch: BTreeMap<_, _> = self.commitment_signed_batch
5770
+ .drain(..)
5771
+ .map(|msg| (msg.batch.as_ref().expect("commitment_signed should have a batch").funding_txid, msg))
5772
+ .collect();
5773
+
5774
+ core::iter::once(&self.funding)
5775
+ .chain(self.pending_funding.iter())
5776
+ .map(|funding| {
5777
+ let funding_txid = funding.get_funding_txo().unwrap().txid;
5778
+ let msg = commitment_signed_batch
5779
+ .get(&funding_txid)
5780
+ .ok_or_else(|| ChannelError::close(format!("Peer did not send a commitment_signed for pending splice transaction: {}", funding_txid)))?;
5781
+ self.context
5782
+ .validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
5783
+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5784
+ ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5785
+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5786
+ }
5787
+ )
5788
+ }
5789
+ )
5790
+ .collect::<Result<Vec<_>, ChannelError>>()?
5791
+ },
5792
+ };
5743
5793
5744
5794
if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
5745
5795
// We only fail to advance our commitment point/number if we're currently
@@ -5794,18 +5844,21 @@ impl<SP: Deref> FundedChannel<SP> where
5794
5844
}
5795
5845
}
5796
5846
5797
- let LatestHolderCommitmentTXInfo {
5798
- commitment_tx, htlc_outputs, nondust_htlc_sources,
5799
- } = commitment_tx_info;
5847
+ for mut update in updates.iter_mut() {
5848
+ if let ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5849
+ claimed_htlcs: ref mut update_claimed_htlcs, ..
5850
+ } = &mut update {
5851
+ debug_assert!(update_claimed_htlcs.is_empty());
5852
+ *update_claimed_htlcs = claimed_htlcs.clone();
5853
+ } else {
5854
+ debug_assert!(false);
5855
+ }
5856
+ }
5857
+
5800
5858
self.context.latest_monitor_update_id += 1;
5801
5859
let mut monitor_update = ChannelMonitorUpdate {
5802
5860
update_id: self.context.latest_monitor_update_id,
5803
- updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5804
- commitment_tx,
5805
- htlc_outputs,
5806
- claimed_htlcs,
5807
- nondust_htlc_sources,
5808
- }],
5861
+ updates,
5809
5862
channel_id: Some(self.context.channel_id()),
5810
5863
};
5811
5864
@@ -9499,6 +9552,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9499
9552
let mut channel = FundedChannel {
9500
9553
funding: self.funding,
9501
9554
pending_funding: vec![],
9555
+ commitment_signed_batch: vec![],
9502
9556
context: self.context,
9503
9557
interactive_tx_signing_session: None,
9504
9558
is_v2_established: false,
@@ -9776,6 +9830,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9776
9830
let mut channel = FundedChannel {
9777
9831
funding: self.funding,
9778
9832
pending_funding: vec![],
9833
+ commitment_signed_batch: vec![],
9779
9834
context: self.context,
9780
9835
interactive_tx_signing_session: None,
9781
9836
is_v2_established: false,
@@ -11042,6 +11097,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11042
11097
funding_transaction,
11043
11098
},
11044
11099
pending_funding: pending_funding.unwrap(),
11100
+ commitment_signed_batch: vec![],
11045
11101
context: ChannelContext {
11046
11102
user_id,
11047
11103
0 commit comments