@@ -66,7 +66,7 @@ use crate::util::errors::APIError;
6666use crate::util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits, MaxDustHTLCExposure};
6767use crate::util::scid_utils::scid_from_parts;
6868
69- use alloc::collections::{btree_map, BTreeMap} ;
69+ use alloc::collections::BTreeMap;
7070
7171use crate::io;
7272use crate::prelude::*;
@@ -1520,7 +1520,6 @@ impl<SP: Deref> Channel<SP> where
15201520 let mut funded_channel = FundedChannel {
15211521 funding: chan.funding,
15221522 pending_funding: vec![],
1523- commitment_signed_batch: BTreeMap::new(),
15241523 context: chan.context,
15251524 interactive_tx_signing_session: chan.interactive_tx_signing_session,
15261525 holder_commitment_point,
@@ -4920,7 +4919,6 @@ pub(super) struct DualFundingChannelContext {
49204919pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
49214920 pub funding: FundingScope,
49224921 pending_funding: Vec<FundingScope>,
4923- commitment_signed_batch: BTreeMap<Txid, msgs::CommitmentSigned>,
49244922 pub context: ChannelContext<SP>,
49254923 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
49264924 holder_commitment_point: HolderCommitmentPoint,
@@ -5736,6 +5734,53 @@ impl<SP: Deref> FundedChannel<SP> where
57365734 pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
57375735 where L::Target: Logger
57385736 {
5737+ self.commitment_signed_check_state()?;
5738+
5739+ if !self.pending_funding.is_empty() {
5740+ return Err(ChannelError::close("Peer sent commitment_signed without a batch when there's a pending splice".to_owned()));
5741+ }
5742+
5743+ let updates = self
5744+ .context
5745+ .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)
5746+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5747+ vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5748+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5749+ }]
5750+ )?;
5751+
5752+ self.commitment_signed_update_monitor(updates, logger)
5753+ }
5754+
5755+ pub fn commitment_signed_batch<L: Deref>(&mut self, batch: &BTreeMap<Txid, msgs::CommitmentSigned>, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5756+ where L::Target: Logger
5757+ {
5758+ self.commitment_signed_check_state()?;
5759+
5760+ // Any commitment_signed not associated with a FundingScope is ignored below if a
5761+ // pending splice transaction has confirmed since receiving the batch.
5762+ let updates = core::iter::once(&self.funding)
5763+ .chain(self.pending_funding.iter())
5764+ .map(|funding| {
5765+ let funding_txid = funding.get_funding_txo().unwrap().txid;
5766+ let msg = batch
5767+ .get(&funding_txid)
5768+ .ok_or_else(|| ChannelError::close(format!("Peer did not send a commitment_signed for pending splice transaction: {}", funding_txid)))?;
5769+ self.context
5770+ .validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
5771+ .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5772+ ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5773+ commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5774+ }
5775+ )
5776+ }
5777+ )
5778+ .collect::<Result<Vec<_>, ChannelError>>()?;
5779+
5780+ self.commitment_signed_update_monitor(updates, logger)
5781+ }
5782+
5783+ fn commitment_signed_check_state(&self) -> Result<(), ChannelError> {
57395784 if self.context.channel_state.is_quiescent() {
57405785 return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
57415786 }
@@ -5749,59 +5794,12 @@ impl<SP: Deref> FundedChannel<SP> where
57495794 return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
57505795 }
57515796
5752- if msg.batch.is_none() && !self.pending_funding.is_empty() {
5753- return Err(ChannelError::close("Peer sent commitment_signed without a batch when there's a pending splice".to_owned()));
5754- }
5755-
5756- let mut updates = match &msg.batch {
5757- // No pending splice
5758- None => {
5759- debug_assert!(self.pending_funding.is_empty());
5760- debug_assert!(self.commitment_signed_batch.is_empty());
5761- self.context
5762- .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)
5763- .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5764- vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5765- commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5766- }]
5767- )?
5768- },
5769- // May or may not have a pending splice
5770- Some(batch) => {
5771- match self.commitment_signed_batch.entry(batch.funding_txid) {
5772- btree_map::Entry::Vacant(entry) => { entry.insert(msg.clone()); },
5773- btree_map::Entry::Occupied(entry) => {
5774- return Err(ChannelError::close(format!("Peer sent commitment_signed with duplicate funding_txid {} in a batch", entry.key())));
5775- },
5776- }
5777-
5778- if self.commitment_signed_batch.len() < batch.batch_size as usize {
5779- return Ok(None);
5780- }
5781-
5782- // Any commitment_signed not associated with a FundingScope is ignored below if a
5783- // pending splice transaction has confirmed since receiving the batch.
5784- core::iter::once(&self.funding)
5785- .chain(self.pending_funding.iter())
5786- .map(|funding| {
5787- let funding_txid = funding.get_funding_txo().unwrap().txid;
5788- let msg = self.commitment_signed_batch
5789- .get(&funding_txid)
5790- .ok_or_else(|| ChannelError::close(format!("Peer did not send a commitment_signed for pending splice transaction: {}", funding_txid)))?;
5791- self.context
5792- .validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
5793- .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5794- ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5795- commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5796- }
5797- )
5798- }
5799- )
5800- .collect::<Result<Vec<_>, ChannelError>>()?
5801- },
5802- };
5803- self.commitment_signed_batch.clear();
5797+ Ok(())
5798+ }
58045799
5800+ fn commitment_signed_update_monitor<L: Deref>(&mut self, mut updates: Vec<ChannelMonitorUpdateStep>, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5801+ where L::Target: Logger
5802+ {
58055803 if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
58065804 // We only fail to advance our commitment point/number if we're currently
58075805 // waiting for our signer to unblock and provide a commitment point.
@@ -9606,7 +9604,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
96069604 let mut channel = FundedChannel {
96079605 funding: self.funding,
96089606 pending_funding: vec![],
9609- commitment_signed_batch: BTreeMap::new(),
96109607 context: self.context,
96119608 interactive_tx_signing_session: None,
96129609 is_v2_established: false,
@@ -9884,7 +9881,6 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
98849881 let mut channel = FundedChannel {
98859882 funding: self.funding,
98869883 pending_funding: vec![],
9887- commitment_signed_batch: BTreeMap::new(),
98889884 context: self.context,
98899885 interactive_tx_signing_session: None,
98909886 is_v2_established: false,
@@ -11151,7 +11147,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1115111147 funding_transaction,
1115211148 },
1115311149 pending_funding: pending_funding.unwrap(),
11154- commitment_signed_batch: BTreeMap::new(),
1115511150 context: ChannelContext {
1115611151 user_id,
1115711152
0 commit comments