@@ -6889,7 +6889,7 @@ impl<SP: Deref> FundedChannel<SP> where
6889
6889
log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
6890
6890
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
6891
6891
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
6892
- let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger).map(|(cu, _)| cu) {
6892
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger) {
6893
6893
if self.context.signer_pending_commitment_update {
6894
6894
log_trace!(logger, "Commitment update generated: clearing signer_pending_commitment_update");
6895
6895
self.context.signer_pending_commitment_update = false;
@@ -8619,7 +8619,7 @@ impl<SP: Deref> FundedChannel<SP> where
8619
8619
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
8620
8620
8621
8621
let (mut htlcs_ref, counterparty_commitment_tx) =
8622
- self.build_commitment_no_state_update(logger);
8622
+ self.build_commitment_no_state_update(&self.funding, logger);
8623
8623
let counterparty_commitment_txid = counterparty_commitment_tx.trust().txid();
8624
8624
let htlcs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
8625
8625
htlcs_ref.drain(..).map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
@@ -8647,19 +8647,21 @@ impl<SP: Deref> FundedChannel<SP> where
8647
8647
monitor_update
8648
8648
}
8649
8649
8650
- fn build_commitment_no_state_update<L: Deref>(&self, logger: &L)
8651
- -> (Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>, CommitmentTransaction)
8652
- where L::Target: Logger
8650
+ fn build_commitment_no_state_update<L: Deref>(
8651
+ &self, funding: &FundingScope, logger: &L,
8652
+ ) -> (Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>, CommitmentTransaction)
8653
+ where
8654
+ L::Target: Logger,
8653
8655
{
8654
- let counterparty_keys = self.context.build_remote_transaction_keys(&self. funding);
8655
- let commitment_stats = self.context.build_commitment_transaction(&self. funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8656
+ let counterparty_keys = self.context.build_remote_transaction_keys(funding);
8657
+ let commitment_stats = self.context.build_commitment_transaction(funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8656
8658
let counterparty_commitment_tx = commitment_stats.tx;
8657
8659
8658
8660
#[cfg(any(test, fuzzing))]
8659
8661
{
8660
- if !self. funding.is_outbound() {
8661
- let projected_commit_tx_info = self. funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
8662
- *self. funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
8662
+ if !funding.is_outbound() {
8663
+ let projected_commit_tx_info = funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap().take();
8664
+ *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
8663
8665
if let Some(info) = projected_commit_tx_info {
8664
8666
let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
8665
8667
if info.total_pending_htlcs == total_pending_htlcs
@@ -8678,13 +8680,30 @@ impl<SP: Deref> FundedChannel<SP> where
8678
8680
8679
8681
/// Only fails in case of signer rejection. Used for channel_reestablish commitment_signed
8680
8682
/// generation when we shouldn't change HTLC/channel state.
8681
- fn send_commitment_no_state_update<L: Deref>(&self, logger: &L) -> Result<(msgs::CommitmentSigned, (Txid, Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>)), ChannelError> where L::Target: Logger {
8683
+ fn send_commitment_no_state_update<L: Deref>(
8684
+ &self, logger: &L,
8685
+ ) -> Result<Vec<msgs::CommitmentSigned>, ChannelError>
8686
+ where
8687
+ L::Target: Logger,
8688
+ {
8689
+ core::iter::once(&self.funding)
8690
+ .chain(self.pending_funding.iter())
8691
+ .map(|funding| self.send_commitment_no_state_update_for_funding(funding, logger))
8692
+ .collect::<Result<Vec<_>, ChannelError>>()
8693
+ }
8694
+
8695
+ fn send_commitment_no_state_update_for_funding<L: Deref>(
8696
+ &self, funding: &FundingScope, logger: &L,
8697
+ ) -> Result<msgs::CommitmentSigned, ChannelError>
8698
+ where
8699
+ L::Target: Logger,
8700
+ {
8682
8701
// Get the fee tests from `build_commitment_no_state_update`
8683
8702
#[cfg(any(test, fuzzing))]
8684
- self.build_commitment_no_state_update(logger);
8703
+ self.build_commitment_no_state_update(funding, logger);
8685
8704
8686
- let counterparty_keys = self.context.build_remote_transaction_keys(&self. funding);
8687
- let commitment_stats = self.context.build_commitment_transaction(&self. funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8705
+ let counterparty_keys = self.context.build_remote_transaction_keys(funding);
8706
+ let commitment_stats = self.context.build_commitment_transaction(funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8688
8707
let counterparty_commitment_txid = commitment_stats.tx.trust().txid();
8689
8708
8690
8709
match &self.context.holder_signer {
@@ -8698,7 +8717,7 @@ impl<SP: Deref> FundedChannel<SP> where
8698
8717
}
8699
8718
8700
8719
let res = ecdsa.sign_counterparty_commitment(
8701
- &self. funding.channel_transaction_parameters,
8720
+ &funding.channel_transaction_parameters,
8702
8721
&commitment_stats.tx,
8703
8722
commitment_stats.inbound_htlc_preimages,
8704
8723
commitment_stats.outbound_htlc_preimages,
@@ -8709,26 +8728,32 @@ impl<SP: Deref> FundedChannel<SP> where
8709
8728
8710
8729
log_trace!(logger, "Signed remote commitment tx {} (txid {}) with redeemscript {} -> {} in channel {}",
8711
8730
encode::serialize_hex(&commitment_stats.tx.trust().built_transaction().transaction),
8712
- &counterparty_commitment_txid, encode::serialize_hex(&self. funding.get_funding_redeemscript()),
8731
+ &counterparty_commitment_txid, encode::serialize_hex(&funding.get_funding_redeemscript()),
8713
8732
log_bytes!(signature.serialize_compact()[..]), &self.context.channel_id());
8714
8733
8715
8734
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(htlcs) {
8716
8735
log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
8717
- encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, commitment_stats.feerate_per_kw, self. funding.get_holder_selected_contest_delay(), htlc, &self.context.channel_type, &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
8736
+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&counterparty_commitment_txid, commitment_stats.feerate_per_kw, funding.get_holder_selected_contest_delay(), htlc, &self.context.channel_type, &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
8718
8737
encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, &self.context.channel_type, &counterparty_keys)),
8719
8738
log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
8720
8739
log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
8721
8740
}
8722
8741
}
8723
8742
8724
- Ok((msgs::CommitmentSigned {
8743
+ let batch = if self.pending_funding.is_empty() { None } else {
8744
+ Some(msgs::CommitmentSignedBatch {
8745
+ batch_size: self.pending_funding.len() as u16 + 1,
8746
+ funding_txid: funding.get_funding_txo().unwrap().txid,
8747
+ })
8748
+ };
8749
+ Ok(msgs::CommitmentSigned {
8725
8750
channel_id: self.context.channel_id,
8726
8751
signature,
8727
8752
htlc_signatures,
8728
- batch: None ,
8753
+ batch,
8729
8754
#[cfg(taproot)]
8730
8755
partial_signature_with_nonce: None,
8731
- }, (counterparty_commitment_txid, commitment_stats.htlcs_included)) )
8756
+ })
8732
8757
},
8733
8758
// TODO (taproot|arik)
8734
8759
#[cfg(taproot)]
0 commit comments