@@ -6417,27 +6417,46 @@ where
64176417 Ok(channel_monitor)
64186418 }
64196419
6420- #[rustfmt::skip]
6421- pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
6422- where L::Target: Logger
6420+ pub fn commitment_signed<L: Deref>(
6421+ &mut self, msg: &msgs::CommitmentSigned, logger: &L,
6422+ ) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
6423+ where
6424+ L::Target: Logger,
64236425 {
64246426 self.commitment_signed_check_state()?;
64256427
6428+ if !self.pending_funding.is_empty() {
6429+ return Err(ChannelError::close(
6430+ "Got a single commitment_signed message when expecting a batch".to_owned(),
6431+ ));
6432+ }
6433+
64266434 let updates = self
64276435 .context
64286436 .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)
6429- .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
6430- vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
6431- commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
6432- }]
6437+ .map(
6438+ |LatestHolderCommitmentTXInfo {
6439+ commitment_tx,
6440+ htlc_outputs,
6441+ nondust_htlc_sources,
6442+ }| {
6443+ vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
6444+ commitment_tx,
6445+ htlc_outputs,
6446+ claimed_htlcs: vec![],
6447+ nondust_htlc_sources,
6448+ }]
6449+ },
64336450 )?;
64346451
64356452 self.commitment_signed_update_monitor(updates, logger)
64366453 }
64376454
6438- #[rustfmt::skip]
6439- pub fn commitment_signed_batch<L: Deref>(&mut self, batch: Vec<msgs::CommitmentSigned>, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
6440- where L::Target: Logger
6455+ pub fn commitment_signed_batch<L: Deref>(
6456+ &mut self, batch: Vec<msgs::CommitmentSigned>, logger: &L,
6457+ ) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
6458+ where
6459+ L::Target: Logger,
64416460 {
64426461 self.commitment_signed_check_state()?;
64436462
@@ -6446,15 +6465,22 @@ where
64466465 let funding_txid = match msg.funding_txid {
64476466 Some(funding_txid) => funding_txid,
64486467 None => {
6449- return Err(ChannelError::close("Peer sent batched commitment_signed without a funding_txid".to_string()));
6468+ return Err(ChannelError::close(
6469+ "Peer sent batched commitment_signed without a funding_txid".to_string(),
6470+ ));
64506471 },
64516472 };
64526473
64536474 match messages.entry(funding_txid) {
6454- btree_map::Entry::Vacant(entry) => { entry.insert(msg); },
6475+ btree_map::Entry::Vacant(entry) => {
6476+ entry.insert(msg);
6477+ },
64556478 btree_map::Entry::Occupied(_) => {
6456- return Err(ChannelError::close(format!("Peer sent batched commitment_signed with duplicate funding_txid {}", funding_txid)));
6457- }
6479+ return Err(ChannelError::close(format!(
6480+ "Peer sent batched commitment_signed with duplicate funding_txid {}",
6481+ funding_txid
6482+ )));
6483+ },
64586484 }
64596485 }
64606486
@@ -6464,36 +6490,56 @@ where
64646490 .chain(self.pending_funding.iter())
64656491 .map(|funding| {
64666492 let funding_txid = funding.get_funding_txo().unwrap().txid;
6467- let msg = messages
6468- .get(&funding_txid)
6469- .ok_or_else(|| ChannelError::close(format!("Peer did not send a commitment_signed for pending splice transaction: {}", funding_txid)))?;
6493+ let msg = messages.get(&funding_txid).ok_or_else(|| {
6494+ ChannelError::close(format!(
6495+ "Peer did not send a commitment_signed for pending splice transaction: {}",
6496+ funding_txid
6497+ ))
6498+ })?;
64706499 self.context
64716500 .validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
6472- .map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
6473- ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
6474- commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
6475- }
6501+ .map(
6502+ |LatestHolderCommitmentTXInfo {
6503+ commitment_tx,
6504+ htlc_outputs,
6505+ nondust_htlc_sources,
6506+ }| ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
6507+ commitment_tx,
6508+ htlc_outputs,
6509+ claimed_htlcs: vec![],
6510+ nondust_htlc_sources,
6511+ },
64766512 )
6477- }
6478- )
6513+ })
64796514 .collect::<Result<Vec<_>, ChannelError>>()?;
64806515
64816516 self.commitment_signed_update_monitor(updates, logger)
64826517 }
64836518
6484- #[rustfmt::skip]
64856519 fn commitment_signed_check_state(&self) -> Result<(), ChannelError> {
64866520 if self.context.channel_state.is_quiescent() {
6487- return Err(ChannelError::WarnAndDisconnect("Got commitment_signed message while quiescent".to_owned()));
6521+ return Err(ChannelError::WarnAndDisconnect(
6522+ "Got commitment_signed message while quiescent".to_owned(),
6523+ ));
64886524 }
64896525 if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
6490- return Err(ChannelError::close("Got commitment signed message when channel was not in an operational state".to_owned()));
6526+ return Err(ChannelError::close(
6527+ "Got commitment signed message when channel was not in an operational state"
6528+ .to_owned(),
6529+ ));
64916530 }
64926531 if self.context.channel_state.is_peer_disconnected() {
6493- return Err(ChannelError::close("Peer sent commitment_signed when we needed a channel_reestablish".to_owned()));
6532+ return Err(ChannelError::close(
6533+ "Peer sent commitment_signed when we needed a channel_reestablish".to_owned(),
6534+ ));
64946535 }
6495- if self.context.channel_state.is_both_sides_shutdown() && self.context.last_sent_closing_fee.is_some() {
6496- return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
6536+ if self.context.channel_state.is_both_sides_shutdown()
6537+ && self.context.last_sent_closing_fee.is_some()
6538+ {
6539+ return Err(ChannelError::close(
6540+ "Peer sent commitment_signed after we'd started exchanging closing_signeds"
6541+ .to_owned(),
6542+ ));
64976543 }
64986544
64996545 Ok(())
0 commit comments