@@ -969,6 +969,8 @@ pub(super) struct ReestablishResponses {
969969 pub order: RAACommitmentOrder,
970970 pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
971971 pub shutdown_msg: Option<msgs::Shutdown>,
972+ pub tx_signatures: Option<msgs::TxSignatures>,
973+ pub tx_abort: Option<msgs::TxAbort>,
972974}
973975
974976/// The first message we send to our peer after connection
@@ -2273,7 +2275,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22732275
22742276 let mut output_index = None;
22752277 let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2276- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2278+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
22772279 if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
22782280 if output_index.is_some() {
22792281 return Err(ChannelError::Close(
@@ -2286,7 +2288,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22862288 }
22872289 }
22882290 let outpoint = if let Some(output_index) = output_index {
2289- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2291+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
22902292 } else {
22912293 return Err(ChannelError::Close(
22922294 (
@@ -2300,7 +2302,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23002302 let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
23012303 let commitment_signed = match commitment_signed {
23022304 Ok(commitment_signed) => {
2303- self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2305+ self.funding.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
23042306 commitment_signed
23052307 },
23062308 Err(err) => {
@@ -6252,7 +6254,7 @@ impl<SP: Deref> FundedChannel<SP> where
62526254 }
62536255
62546256 if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6255- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6257+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
62566258 return Err(ChannelError::Close(
62576259 (
62586260 "The txid for the transaction does not match".to_string(),
@@ -6897,7 +6899,10 @@ impl<SP: Deref> FundedChannel<SP> where
68976899 }
68986900
68996901 if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6900- msg.next_local_commitment_number == 0 {
6902+ (msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none()) {
6903+ // Note: This also covers the following case in the V2 channel establishment specification:
6904+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6905+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
69016906 return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
69026907 }
69036908
@@ -6961,6 +6966,8 @@ impl<SP: Deref> FundedChannel<SP> where
69616966 raa: None, commitment_update: None,
69626967 order: RAACommitmentOrder::CommitmentFirst,
69636968 shutdown_msg, announcement_sigs,
6969+ tx_signatures: None,
6970+ tx_abort: None,
69646971 });
69656972 }
69666973
@@ -6970,6 +6977,8 @@ impl<SP: Deref> FundedChannel<SP> where
69706977 raa: None, commitment_update: None,
69716978 order: RAACommitmentOrder::CommitmentFirst,
69726979 shutdown_msg, announcement_sigs,
6980+ tx_signatures: None,
6981+ tx_abort: None,
69736982 });
69746983 }
69756984
@@ -7012,11 +7021,76 @@ impl<SP: Deref> FundedChannel<SP> where
70127021 log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
70137022 }
70147023
7024+ // if next_funding_txid is set:
7025+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
7026+ if let Some(session) = &self.interactive_tx_signing_session {
7027+ // if next_funding_txid matches the latest interactive funding transaction:
7028+ if session.unsigned_tx().compute_txid() == next_funding_txid {
7029+ debug_assert_eq!(session.unsigned_tx().compute_txid(), self.maybe_get_next_funding_txid().unwrap());
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
7033+ // if next_commitment_number is zero:
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.
7056+ if self.context.channel_state.is_monitor_update_in_progress() {
7057+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
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
7062+ } else {
7063+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
7064+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
7065+ // holder must send one.
7066+ session.holder_tx_signatures().clone()
7067+ }
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)
7075+ } else {
7076+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
7077+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
7078+ }
7079+ } else {
7080+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
7081+ }
7082+ } else {
7083+ // Don't send anything related to interactive signing if `next_funding_txid` is not set.
7084+ (None, None, None)
7085+ };
7086+
70157087 Ok(ReestablishResponses {
70167088 channel_ready, shutdown_msg, announcement_sigs,
70177089 raa: required_revoke,
7018- commitment_update: None ,
7090+ commitment_update,
70197091 order: self.context.resend_order.clone(),
7092+ tx_signatures,
7093+ tx_abort,
70207094 })
70217095 } else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
70227096 if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -7031,6 +7105,8 @@ impl<SP: Deref> FundedChannel<SP> where
70317105 channel_ready, shutdown_msg, announcement_sigs,
70327106 commitment_update: None, raa: None,
70337107 order: self.context.resend_order.clone(),
7108+ tx_signatures: None,
7109+ tx_abort: None,
70347110 })
70357111 } else {
70367112 let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -7053,6 +7129,8 @@ impl<SP: Deref> FundedChannel<SP> where
70537129 channel_ready, shutdown_msg, announcement_sigs,
70547130 raa, commitment_update,
70557131 order: self.context.resend_order.clone(),
7132+ tx_signatures: None,
7133+ tx_abort: None,
70567134 })
70577135 }
70587136 } else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8346,7 +8424,7 @@ impl<SP: Deref> FundedChannel<SP> where
83468424 // to the txid of that interactive transaction, else we MUST NOT set it.
83478425 if let Some(signing_session) = &self.interactive_tx_signing_session {
83488426 // Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8349- if !signing_session.counterparty_sent_tx_signatures {
8427+ if !signing_session.counterparty_sent_tx_signatures() {
83508428 // ...but we didn't receive a `tx_signatures` from the counterparty yet.
83518429 Some(self.funding_outpoint().txid)
83528430 } else {
0 commit comments