@@ -7027,49 +7027,51 @@ impl<SP: Deref> FundedChannel<SP> where
70277027 // if next_funding_txid matches the latest interactive funding transaction:
70287028 if session.unsigned_tx().compute_txid() == next_funding_txid {
70297029 debug_assert_eq!(session.unsigned_tx().compute_txid(), self.maybe_get_next_funding_txid().unwrap());
7030- // if it has not received tx_signatures for that funding transaction:
7031- if !session.counterparty_sent_tx_signatures() {
7030+
7031+ let commitment_update = if !session.counterparty_sent_tx_signatures() && msg.next_local_commitment_number == 0 {
7032+ // if it has not received tx_signatures for that funding transaction AND
70327033 // if next_commitment_number is zero:
7033- let commitment_update = if msg.next_local_commitment_number == 0 {
7034- // MUST retransmit its commitment_signed for that funding transaction.
7035- let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7036- Some(msgs::CommitmentUpdate {
7037- commitment_signed,
7038- update_add_htlcs: vec![],
7039- update_fulfill_htlcs: vec![],
7040- update_fail_htlcs: vec![],
7041- update_fail_malformed_htlcs: vec![],
7042- update_fee: None,
7043- })
7044- } else { None };
7045- // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
7046- if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
7047- // MUST send its tx_signatures for that funding transaction.
7048- if self.context.channel_state.is_monitor_update_in_progress() {
7049- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7050- self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7051- // We can still send the initial commitment transaction if a monitor update is pending.
7052- (commitment_update, None, None)
7053- } else {
7054- (commitment_update, session.holder_tx_signatures().clone(), None)
7055- }
7056- } else {
7057- (commitment_update, None, None)
7058- }
7059- } else {
7060- // if it has already received tx_signatures for that funding transaction:
7061- // MUST send its tx_signatures for that funding transaction.
7034+ // MUST retransmit its commitment_signed for that funding transaction.
7035+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7036+ Some(msgs::CommitmentUpdate {
7037+ commitment_signed,
7038+ update_add_htlcs: vec![],
7039+ update_fulfill_htlcs: vec![],
7040+ update_fail_htlcs: vec![],
7041+ update_fail_malformed_htlcs: vec![],
7042+ update_fee: None,
7043+ })
7044+ } else { None };
7045+ // if it has not received tx_signatures for that funding transaction AND
7046+ // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
7047+ // MUST send its tx_signatures for that funding transaction.
7048+ // else if it HAS received commitment_signed AND has received tx_signatures for that funding transaction:
7049+ // MUST send its tx_signatures for that funding transaction.
7050+ let tx_signatures = if session.has_received_commitment_signed() && ((
7051+ !session.counterparty_sent_tx_signatures() &&
7052+ session.holder_sends_tx_signatures_first()
7053+ ) || session.counterparty_sent_tx_signatures()) {
7054+ // This should have already been set in `commitment_signed_initial_v2`, but check again
7055+ // just in case.
70627056 if self.context.channel_state.is_monitor_update_in_progress() {
70637057 log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7064- self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7065- (None, None, None)
7058+ if self.context.monitor_pending_tx_signatures.is_none() {
7059+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7060+ }
7061+ None
70667062 } else {
70677063 // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
70687064 // when the holder provides their witnesses as this will queue a `tx_signatures` if the
70697065 // holder must send one.
7070- (None, session.holder_tx_signatures().clone(), None )
7066+ session.holder_tx_signatures().clone()
70717067 }
7072- }
7068+ } else {
7069+ if !session.has_received_commitment_signed() {
7070+ self.context.expecting_peer_commitment_signed = true;
7071+ }
7072+ None
7073+ };
7074+ (commitment_update, tx_signatures, None)
70737075 } else {
70747076 // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
70757077 (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
@@ -7078,6 +7080,7 @@ impl<SP: Deref> FundedChannel<SP> where
70787080 return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
70797081 }
70807082 } else {
7083+ // Don't send anything related to interactive signing if `next_funding_txid` is not set.
70817084 (None, None, None)
70827085 };
70837086
0 commit comments