@@ -6540,7 +6540,7 @@ impl<SP: Deref> FundedChannel<SP> where
65406540 }
65416541
65426542 if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6543- msg.next_local_commitment_number == 0 {
6543+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
65446544 return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
65456545 }
65466546
@@ -6669,16 +6669,19 @@ impl<SP: Deref> FundedChannel<SP> where
66696669 if session.unsigned_tx.compute_txid() == next_funding_txid {
66706670 // if it has not received tx_signatures for that funding transaction:
66716671 if !session.counterparty_sent_tx_signatures {
6672- // MUST retransmit its commitment_signed for that funding transaction.
6673- let commitment_signed = self.context.get_initial_commitment_signed(logger)?;
6674- let commitment_update = Some(msgs::CommitmentUpdate {
6675- commitment_signed,
6676- update_add_htlcs: vec![],
6677- update_fulfill_htlcs: vec![],
6678- update_fail_htlcs: vec![],
6679- update_fail_malformed_htlcs: vec![],
6680- update_fee: None,
6681- });
6672+ // if next_commitment_number is zero:
6673+ let commitment_update = if msg.next_local_commitment_number == 0 {
6674+ // MUST retransmit its commitment_signed for that funding transaction.
6675+ let commitment_signed = self.context.get_initial_commitment_signed(logger)?;
6676+ Some(msgs::CommitmentUpdate {
6677+ commitment_signed,
6678+ update_add_htlcs: vec![],
6679+ update_fulfill_htlcs: vec![],
6680+ update_fail_htlcs: vec![],
6681+ update_fail_malformed_htlcs: vec![],
6682+ update_fee: None,
6683+ })
6684+ } else { None };
66826685 // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
66836686 if session.received_commitment_signed && session.holder_sends_tx_signatures_first {
66846687 // MUST send its tx_signatures for that funding transaction.
@@ -6700,7 +6703,18 @@ impl<SP: Deref> FundedChannel<SP> where
67006703 // TODO(dual_funding): Should probably error here (or send tx_abort) but not in spec.
67016704 (None, None, None)
67026705 }
6703- } else { (None, None, None) };
6706+ } else {
6707+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6708+ if msg.next_local_commitment_number == 0 {
6709+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6710+ return Err(ChannelError::close(format!(
6711+ "Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)",
6712+ msg.next_remote_commitment_number,
6713+ our_commitment_transaction
6714+ )));
6715+ }
6716+ (None, None, None)
6717+ };
67046718
67056719 Ok(ReestablishResponses {
67066720 channel_ready, shutdown_msg, announcement_sigs,
0 commit comments