@@ -6417,27 +6417,46 @@ where
6417
6417
Ok(channel_monitor)
6418
6418
}
6419
6419
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,
6423
6425
{
6424
6426
self.commitment_signed_check_state()?;
6425
6427
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
+
6426
6434
let updates = self
6427
6435
.context
6428
6436
.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
+ },
6433
6450
)?;
6434
6451
6435
6452
self.commitment_signed_update_monitor(updates, logger)
6436
6453
}
6437
6454
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,
6441
6460
{
6442
6461
self.commitment_signed_check_state()?;
6443
6462
@@ -6446,15 +6465,22 @@ where
6446
6465
let funding_txid = match msg.funding_txid {
6447
6466
Some(funding_txid) => funding_txid,
6448
6467
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
+ ));
6450
6471
},
6451
6472
};
6452
6473
6453
6474
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
+ },
6455
6478
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
+ },
6458
6484
}
6459
6485
}
6460
6486
@@ -6464,36 +6490,56 @@ where
6464
6490
.chain(self.pending_funding.iter())
6465
6491
.map(|funding| {
6466
6492
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
+ })?;
6470
6499
self.context
6471
6500
.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
+ },
6476
6512
)
6477
- }
6478
- )
6513
+ })
6479
6514
.collect::<Result<Vec<_>, ChannelError>>()?;
6480
6515
6481
6516
self.commitment_signed_update_monitor(updates, logger)
6482
6517
}
6483
6518
6484
- #[rustfmt::skip]
6485
6519
fn commitment_signed_check_state(&self) -> Result<(), ChannelError> {
6486
6520
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
+ ));
6488
6524
}
6489
6525
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
+ ));
6491
6530
}
6492
6531
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
+ ));
6494
6535
}
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
+ ));
6497
6543
}
6498
6544
6499
6545
Ok(())
0 commit comments