@@ -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
@@ -2275,7 +2277,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22752277
22762278 let mut output_index = None;
22772279 let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2278- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2280+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
22792281 if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
22802282 if output_index.is_some() {
22812283 return Err(ChannelError::Close(
@@ -2288,7 +2290,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22882290 }
22892291 }
22902292 let outpoint = if let Some(output_index) = output_index {
2291- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2293+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
22922294 } else {
22932295 return Err(ChannelError::Close(
22942296 (
@@ -2302,7 +2304,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23022304 let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
23032305 let commitment_signed = match commitment_signed {
23042306 Ok(commitment_signed) => {
2305- self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2307+ self.funding.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
23062308 commitment_signed
23072309 },
23082310 Err(err) => {
@@ -6254,7 +6256,7 @@ impl<SP: Deref> FundedChannel<SP> where
62546256 }
62556257
62566258 if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6257- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6259+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
62586260 return Err(ChannelError::Close(
62596261 (
62606262 "The txid for the transaction does not match".to_string(),
@@ -6899,7 +6901,10 @@ impl<SP: Deref> FundedChannel<SP> where
68996901 }
69006902
69016903 if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6902- msg.next_local_commitment_number == 0 {
6904+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6905+ // Note: This also covers the following case in the V2 channel establishment specification:
6906+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6907+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
69036908 return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
69046909 }
69056910
@@ -6963,6 +6968,8 @@ impl<SP: Deref> FundedChannel<SP> where
69636968 raa: None, commitment_update: None,
69646969 order: RAACommitmentOrder::CommitmentFirst,
69656970 shutdown_msg, announcement_sigs,
6971+ tx_signatures: None,
6972+ tx_abort: None,
69666973 });
69676974 }
69686975
@@ -6972,6 +6979,8 @@ impl<SP: Deref> FundedChannel<SP> where
69726979 raa: None, commitment_update: None,
69736980 order: RAACommitmentOrder::CommitmentFirst,
69746981 shutdown_msg, announcement_sigs,
6982+ tx_signatures: None,
6983+ tx_abort: None,
69756984 });
69766985 }
69776986
@@ -7014,11 +7023,72 @@ impl<SP: Deref> FundedChannel<SP> where
70147023 log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
70157024 }
70167025
7026+ // if next_funding_txid is set:
7027+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
7028+ if let Some(session) = &self.interactive_tx_signing_session {
7029+ // if next_funding_txid matches the latest interactive funding transaction:
7030+ if session.unsigned_tx().compute_txid() == next_funding_txid {
7031+ // if it has not received tx_signatures for that funding transaction:
7032+ if !session.counterparty_sent_tx_signatures() {
7033+ // if next_commitment_number is zero:
7034+ let commitment_update = if msg.next_local_commitment_number == 0 {
7035+ // MUST retransmit its commitment_signed for that funding transaction.
7036+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7037+ Some(msgs::CommitmentUpdate {
7038+ commitment_signed,
7039+ update_add_htlcs: vec![],
7040+ update_fulfill_htlcs: vec![],
7041+ update_fail_htlcs: vec![],
7042+ update_fail_malformed_htlcs: vec![],
7043+ update_fee: None,
7044+ })
7045+ } else { None };
7046+ // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
7047+ if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
7048+ // MUST send its tx_signatures for that funding transaction.
7049+ if self.context.channel_state.is_monitor_update_in_progress() {
7050+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7051+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7052+ // We can still send the initial commitment transaction if a monitor update is pending.
7053+ (commitment_update, None, None)
7054+ } else {
7055+ (commitment_update, session.holder_tx_signatures().clone(), None)
7056+ }
7057+ } else {
7058+ (commitment_update, None, None)
7059+ }
7060+ } else {
7061+ // if it has already received tx_signatures for that funding transaction:
7062+ // MUST send its tx_signatures for that funding transaction.
7063+ if self.context.channel_state.is_monitor_update_in_progress() {
7064+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7065+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7066+ (None, None, None)
7067+ } else {
7068+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
7069+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
7070+ // holder must send one.
7071+ (None, session.holder_tx_signatures().clone(), None)
7072+ }
7073+ }
7074+ } else {
7075+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
7076+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
7077+ }
7078+ } else {
7079+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
7080+ }
7081+ } else {
7082+ (None, None, None)
7083+ };
7084+
70177085 Ok(ReestablishResponses {
70187086 channel_ready, shutdown_msg, announcement_sigs,
70197087 raa: required_revoke,
7020- commitment_update: None ,
7088+ commitment_update,
70217089 order: self.context.resend_order.clone(),
7090+ tx_signatures,
7091+ tx_abort,
70227092 })
70237093 } else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
70247094 if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -7033,6 +7103,8 @@ impl<SP: Deref> FundedChannel<SP> where
70337103 channel_ready, shutdown_msg, announcement_sigs,
70347104 commitment_update: None, raa: None,
70357105 order: self.context.resend_order.clone(),
7106+ tx_signatures: None,
7107+ tx_abort: None,
70367108 })
70377109 } else {
70387110 let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -7055,6 +7127,8 @@ impl<SP: Deref> FundedChannel<SP> where
70557127 channel_ready, shutdown_msg, announcement_sigs,
70567128 raa, commitment_update,
70577129 order: self.context.resend_order.clone(),
7130+ tx_signatures: None,
7131+ tx_abort: None,
70587132 })
70597133 }
70607134 } else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8348,7 +8422,7 @@ impl<SP: Deref> FundedChannel<SP> where
83488422 // to the txid of that interactive transaction, else we MUST NOT set it.
83498423 if let Some(signing_session) = &self.interactive_tx_signing_session {
83508424 // Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8351- if !signing_session.counterparty_sent_tx_signatures {
8425+ if !signing_session.counterparty_sent_tx_signatures() {
83528426 // ...but we didn't receive a `tx_signatures` from the counterparty yet.
83538427 Some(self.funding_outpoint().txid)
83548428 } else {
0 commit comments