@@ -6807,6 +6807,9 @@ impl<SP: Deref> FundedChannel<SP> where
68076807
68086808 if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
68096809 msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6810+ // Note: This also covers the following case in the V2 channel establishment specification:
6811+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6812+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
68106813 return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
68116814 }
68126815
@@ -6948,14 +6951,30 @@ impl<SP: Deref> FundedChannel<SP> where
69486951 // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
69496952 if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
69506953 // MUST send its tx_signatures for that funding transaction.
6951- (commitment_update, session.holder_tx_signatures().clone(), None)
6954+ if self.context.channel_state.is_monitor_update_in_progress() {
6955+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6956+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
6957+ // We can still send the initial commitment transaction if a monitor update is pending.
6958+ (commitment_update, None, None)
6959+ } else {
6960+ (commitment_update, session.holder_tx_signatures().clone(), None)
6961+ }
69526962 } else {
69536963 (commitment_update, None, None)
69546964 }
69556965 } else {
69566966 // if it has already received tx_signatures for that funding transaction:
69576967 // MUST send its tx_signatures for that funding transaction.
6958- (None, session.holder_tx_signatures().clone(), None)
6968+ if self.context.channel_state.is_monitor_update_in_progress() {
6969+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6970+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
6971+ (None, None, None)
6972+ } else {
6973+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
6974+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
6975+ // holder must send one.
6976+ (None, session.holder_tx_signatures().clone(), None)
6977+ }
69596978 }
69606979 } else {
69616980 // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
@@ -6965,15 +6984,6 @@ impl<SP: Deref> FundedChannel<SP> where
69656984 return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
69666985 }
69676986 } else {
6968- // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6969- if msg.next_local_commitment_number == 0 {
6970- // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6971- return Err(ChannelError::close(format!(
6972- "Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)",
6973- msg.next_remote_commitment_number,
6974- our_commitment_transaction
6975- )));
6976- }
69776987 (None, None, None)
69786988 };
69796989
0 commit comments