@@ -6532,7 +6532,7 @@ impl<SP: Deref> FundedChannel<SP> where
65326532 }
65336533
65346534 if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6535- msg.next_local_commitment_number == 0 {
6535+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
65366536 return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
65376537 }
65386538
@@ -6661,16 +6661,19 @@ impl<SP: Deref> FundedChannel<SP> where
66616661 if session.unsigned_tx.compute_txid() == next_funding_txid {
66626662 // if it has not received tx_signatures for that funding transaction:
66636663 if !session.counterparty_sent_tx_signatures {
6664- // MUST retransmit its commitment_signed for that funding transaction.
6665- let commitment_signed = self.context.get_initial_commitment_signed(logger)?;
6666- let commitment_update = Some(msgs::CommitmentUpdate {
6667- commitment_signed,
6668- update_add_htlcs: vec![],
6669- update_fulfill_htlcs: vec![],
6670- update_fail_htlcs: vec![],
6671- update_fail_malformed_htlcs: vec![],
6672- update_fee: None,
6673- });
6664+ // if next_commitment_number is zero:
6665+ let commitment_update = if msg.next_local_commitment_number == 0 {
6666+ // MUST retransmit its commitment_signed for that funding transaction.
6667+ let commitment_signed = self.context.get_initial_commitment_signed(logger)?;
6668+ Some(msgs::CommitmentUpdate {
6669+ commitment_signed,
6670+ update_add_htlcs: vec![],
6671+ update_fulfill_htlcs: vec![],
6672+ update_fail_htlcs: vec![],
6673+ update_fail_malformed_htlcs: vec![],
6674+ update_fee: None,
6675+ })
6676+ } else { None };
66746677 // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
66756678 if session.received_commitment_signed && session.holder_sends_tx_signatures_first {
66766679 // MUST send its tx_signatures for that funding transaction.
@@ -6692,7 +6695,18 @@ impl<SP: Deref> FundedChannel<SP> where
66926695 // TODO(dual_funding): Should probably error here (or send tx_abort) but not in spec.
66936696 (None, None, None)
66946697 }
6695- } else { (None, None, None) };
6698+ } else {
6699+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6700+ if msg.next_local_commitment_number == 0 {
6701+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6702+ return Err(ChannelError::close(format!(
6703+ "Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)",
6704+ msg.next_remote_commitment_number,
6705+ our_commitment_transaction
6706+ )));
6707+ }
6708+ (None, None, None)
6709+ };
66966710
66976711 Ok(ReestablishResponses {
66986712 channel_ready, shutdown_msg, announcement_sigs,
0 commit comments