+ debug_assert!(nondust_htlc_sources.is_empty());
+ } else {
+ // If we don't have any non-dust HTLCs in htlc_outputs, assume they were all passed via
+ // `nondust_htlc_sources`, building up the final htlc_outputs by combining
+ // `nondust_htlc_sources` and the `holder_commitment_tx`
+ #[cfg(debug_assertions)] {
+ let mut prev = -1;
+ for htlc in holder_commitment_tx.trust().htlcs().iter() {
+ assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
+ prev = htlc.transaction_output_index.unwrap() as i32;
+ }
+ }
+ debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
+ debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
+ debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
+
+ let mut sources_iter = nondust_htlc_sources.into_iter();
+
+ for (htlc, counterparty_sig) in holder_commitment_tx.trust().htlcs().iter()
+ .zip(holder_commitment_tx.counterparty_htlc_sigs.iter())
+ {
+ if htlc.offered {
+ let source = sources_iter.next().expect("Non-dust HTLC sources didn't match commitment tx");
+ #[cfg(debug_assertions)] {
+ assert!(source.possibly_matches_output(htlc));
+ }
+ htlc_outputs.push((htlc.clone(), Some(counterparty_sig.clone()), Some(source)));
+ } else {
+ htlc_outputs.push((htlc.clone(), Some(counterparty_sig.clone()), None));
+ }
+ }
+ debug_assert!(sources_iter.next().is_none());
+ }
+
+ let trusted_tx = holder_commitment_tx.trust();
+ let txid = trusted_tx.txid();
+ let tx_keys = trusted_tx.keys();
+ self.current_holder_commitment_number = trusted_tx.commitment_number();
+ let mut new_holder_commitment_tx = HolderSignedTx {
+ txid,
+ revocation_key: tx_keys.revocation_key,
+ a_htlc_key: tx_keys.broadcaster_htlc_key,
+ b_htlc_key: tx_keys.countersignatory_htlc_key,
+ delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
+ per_commitment_point: tx_keys.per_commitment_point,
+ htlc_outputs,
+ to_self_value_sat: holder_commitment_tx.to_broadcaster_value_sat(),
+ feerate_per_kw: trusted_tx.feerate_per_kw(),