@@ -969,6 +969,8 @@ pub(super) struct ReestablishResponses {
969
969
pub order: RAACommitmentOrder,
970
970
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
971
971
pub shutdown_msg: Option<msgs::Shutdown>,
972
+ pub tx_signatures: Option<msgs::TxSignatures>,
973
+ pub tx_abort: Option<msgs::TxAbort>,
972
974
}
973
975
974
976
/// The first message we send to our peer after connection
@@ -2282,7 +2284,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2282
2284
2283
2285
let mut output_index = None;
2284
2286
let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2285
- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2287
+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
2286
2288
if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
2287
2289
if output_index.is_some() {
2288
2290
return Err(ChannelError::Close(
@@ -2295,7 +2297,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2295
2297
}
2296
2298
}
2297
2299
let outpoint = if let Some(output_index) = output_index {
2298
- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2300
+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
2299
2301
} else {
2300
2302
return Err(ChannelError::Close(
2301
2303
(
@@ -2309,7 +2311,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2309
2311
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2310
2312
let commitment_signed = match commitment_signed {
2311
2313
Ok(commitment_signed) => {
2312
- self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2314
+ self.funding.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
2313
2315
commitment_signed
2314
2316
},
2315
2317
Err(err) => {
@@ -6259,7 +6261,7 @@ impl<SP: Deref> FundedChannel<SP> where
6259
6261
}
6260
6262
6261
6263
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6262
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6264
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
6263
6265
return Err(ChannelError::Close(
6264
6266
(
6265
6267
"The txid for the transaction does not match".to_string(),
@@ -6904,7 +6906,10 @@ impl<SP: Deref> FundedChannel<SP> where
6904
6906
}
6905
6907
6906
6908
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6907
- msg.next_local_commitment_number == 0 {
6909
+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6910
+ // Note: This also covers the following case in the V2 channel establishment specification:
6911
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6912
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6908
6913
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
6909
6914
}
6910
6915
@@ -6968,6 +6973,8 @@ impl<SP: Deref> FundedChannel<SP> where
6968
6973
raa: None, commitment_update: None,
6969
6974
order: RAACommitmentOrder::CommitmentFirst,
6970
6975
shutdown_msg, announcement_sigs,
6976
+ tx_signatures: None,
6977
+ tx_abort: None,
6971
6978
});
6972
6979
}
6973
6980
@@ -6977,6 +6984,8 @@ impl<SP: Deref> FundedChannel<SP> where
6977
6984
raa: None, commitment_update: None,
6978
6985
order: RAACommitmentOrder::CommitmentFirst,
6979
6986
shutdown_msg, announcement_sigs,
6987
+ tx_signatures: None,
6988
+ tx_abort: None,
6980
6989
});
6981
6990
}
6982
6991
@@ -7019,11 +7028,72 @@ impl<SP: Deref> FundedChannel<SP> where
7019
7028
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
7020
7029
}
7021
7030
7031
+ // if next_funding_txid is set:
7032
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
7033
+ if let Some(session) = &self.interactive_tx_signing_session {
7034
+ // if next_funding_txid matches the latest interactive funding transaction:
7035
+ if session.unsigned_tx().compute_txid() == next_funding_txid {
7036
+ // if it has not received tx_signatures for that funding transaction:
7037
+ if !session.counterparty_sent_tx_signatures() {
7038
+ // if next_commitment_number is zero:
7039
+ let commitment_update = if msg.next_local_commitment_number == 0 {
7040
+ // MUST retransmit its commitment_signed for that funding transaction.
7041
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7042
+ Some(msgs::CommitmentUpdate {
7043
+ commitment_signed,
7044
+ update_add_htlcs: vec![],
7045
+ update_fulfill_htlcs: vec![],
7046
+ update_fail_htlcs: vec![],
7047
+ update_fail_malformed_htlcs: vec![],
7048
+ update_fee: None,
7049
+ })
7050
+ } else { None };
7051
+ // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
7052
+ if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
7053
+ // MUST send its tx_signatures for that funding transaction.
7054
+ if self.context.channel_state.is_monitor_update_in_progress() {
7055
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7056
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7057
+ // We can still send the initial commitment transaction if a monitor update is pending.
7058
+ (commitment_update, None, None)
7059
+ } else {
7060
+ (commitment_update, session.holder_tx_signatures().clone(), None)
7061
+ }
7062
+ } else {
7063
+ (commitment_update, None, None)
7064
+ }
7065
+ } else {
7066
+ // if it has already received tx_signatures for that funding transaction:
7067
+ // MUST send its tx_signatures for that funding transaction.
7068
+ if self.context.channel_state.is_monitor_update_in_progress() {
7069
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7070
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7071
+ (None, None, None)
7072
+ } else {
7073
+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
7074
+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
7075
+ // holder must send one.
7076
+ (None, session.holder_tx_signatures().clone(), None)
7077
+ }
7078
+ }
7079
+ } else {
7080
+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
7081
+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
7082
+ }
7083
+ } else {
7084
+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
7085
+ }
7086
+ } else {
7087
+ (None, None, None)
7088
+ };
7089
+
7022
7090
Ok(ReestablishResponses {
7023
7091
channel_ready, shutdown_msg, announcement_sigs,
7024
7092
raa: required_revoke,
7025
- commitment_update: None ,
7093
+ commitment_update,
7026
7094
order: self.context.resend_order.clone(),
7095
+ tx_signatures,
7096
+ tx_abort,
7027
7097
})
7028
7098
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
7029
7099
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -7038,6 +7108,8 @@ impl<SP: Deref> FundedChannel<SP> where
7038
7108
channel_ready, shutdown_msg, announcement_sigs,
7039
7109
commitment_update: None, raa: None,
7040
7110
order: self.context.resend_order.clone(),
7111
+ tx_signatures: None,
7112
+ tx_abort: None,
7041
7113
})
7042
7114
} else {
7043
7115
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -7060,6 +7132,8 @@ impl<SP: Deref> FundedChannel<SP> where
7060
7132
channel_ready, shutdown_msg, announcement_sigs,
7061
7133
raa, commitment_update,
7062
7134
order: self.context.resend_order.clone(),
7135
+ tx_signatures: None,
7136
+ tx_abort: None,
7063
7137
})
7064
7138
}
7065
7139
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8353,7 +8427,7 @@ impl<SP: Deref> FundedChannel<SP> where
8353
8427
// to the txid of that interactive transaction, else we MUST NOT set it.
8354
8428
if let Some(signing_session) = &self.interactive_tx_signing_session {
8355
8429
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8356
- if !signing_session.counterparty_sent_tx_signatures {
8430
+ if !signing_session.counterparty_sent_tx_signatures() {
8357
8431
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8358
8432
Some(self.funding_outpoint().txid)
8359
8433
} else {
0 commit comments