@@ -968,6 +968,8 @@ pub(super) struct ReestablishResponses {
968
968
pub order: RAACommitmentOrder,
969
969
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
970
970
pub shutdown_msg: Option<msgs::Shutdown>,
971
+ pub tx_signatures: Option<msgs::TxSignatures>,
972
+ pub tx_abort: Option<msgs::TxAbort>,
971
973
}
972
974
973
975
/// The first message we send to our peer after connection
@@ -2273,7 +2275,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2273
2275
2274
2276
let mut output_index = None;
2275
2277
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() {
2277
2279
if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
2278
2280
if output_index.is_some() {
2279
2281
return Err(ChannelError::Close(
@@ -2286,7 +2288,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2286
2288
}
2287
2289
}
2288
2290
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 }
2290
2292
} else {
2291
2293
return Err(ChannelError::Close(
2292
2294
(
@@ -2300,7 +2302,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2300
2302
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2301
2303
let commitment_signed = match commitment_signed {
2302
2304
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());
2304
2306
commitment_signed
2305
2307
},
2306
2308
Err(err) => {
@@ -6164,7 +6166,7 @@ impl<SP: Deref> FundedChannel<SP> where
6164
6166
}
6165
6167
6166
6168
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6167
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6169
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
6168
6170
return Err(ChannelError::Close(
6169
6171
(
6170
6172
"The txid for the transaction does not match".to_string(),
@@ -6809,7 +6811,10 @@ impl<SP: Deref> FundedChannel<SP> where
6809
6811
}
6810
6812
6811
6813
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6812
- msg.next_local_commitment_number == 0 {
6814
+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6815
+ // Note: This also covers the following case in the V2 channel establishment specification:
6816
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6817
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6813
6818
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
6814
6819
}
6815
6820
@@ -6873,6 +6878,8 @@ impl<SP: Deref> FundedChannel<SP> where
6873
6878
raa: None, commitment_update: None,
6874
6879
order: RAACommitmentOrder::CommitmentFirst,
6875
6880
shutdown_msg, announcement_sigs,
6881
+ tx_signatures: None,
6882
+ tx_abort: None,
6876
6883
});
6877
6884
}
6878
6885
@@ -6882,6 +6889,8 @@ impl<SP: Deref> FundedChannel<SP> where
6882
6889
raa: None, commitment_update: None,
6883
6890
order: RAACommitmentOrder::CommitmentFirst,
6884
6891
shutdown_msg, announcement_sigs,
6892
+ tx_signatures: None,
6893
+ tx_abort: None,
6885
6894
});
6886
6895
}
6887
6896
@@ -6924,11 +6933,72 @@ impl<SP: Deref> FundedChannel<SP> where
6924
6933
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
6925
6934
}
6926
6935
6936
+ // if next_funding_txid is set:
6937
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
6938
+ if let Some(session) = &self.interactive_tx_signing_session {
6939
+ // if next_funding_txid matches the latest interactive funding transaction:
6940
+ if session.unsigned_tx().compute_txid() == next_funding_txid {
6941
+ // if it has not received tx_signatures for that funding transaction:
6942
+ if !session.counterparty_sent_tx_signatures() {
6943
+ // if next_commitment_number is zero:
6944
+ let commitment_update = if msg.next_local_commitment_number == 0 {
6945
+ // MUST retransmit its commitment_signed for that funding transaction.
6946
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
6947
+ Some(msgs::CommitmentUpdate {
6948
+ commitment_signed,
6949
+ update_add_htlcs: vec![],
6950
+ update_fulfill_htlcs: vec![],
6951
+ update_fail_htlcs: vec![],
6952
+ update_fail_malformed_htlcs: vec![],
6953
+ update_fee: None,
6954
+ })
6955
+ } else { None };
6956
+ // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
6957
+ if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
6958
+ // MUST send its tx_signatures for that funding transaction.
6959
+ if self.context.channel_state.is_monitor_update_in_progress() {
6960
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6961
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
6962
+ // We can still send the initial commitment transaction if a monitor update is pending.
6963
+ (commitment_update, None, None)
6964
+ } else {
6965
+ (commitment_update, session.holder_tx_signatures().clone(), None)
6966
+ }
6967
+ } else {
6968
+ (commitment_update, None, None)
6969
+ }
6970
+ } else {
6971
+ // if it has already received tx_signatures for that funding transaction:
6972
+ // MUST send its tx_signatures for that funding transaction.
6973
+ if self.context.channel_state.is_monitor_update_in_progress() {
6974
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6975
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
6976
+ (None, None, None)
6977
+ } else {
6978
+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
6979
+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
6980
+ // holder must send one.
6981
+ (None, session.holder_tx_signatures().clone(), None)
6982
+ }
6983
+ }
6984
+ } else {
6985
+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
6986
+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
6987
+ }
6988
+ } else {
6989
+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
6990
+ }
6991
+ } else {
6992
+ (None, None, None)
6993
+ };
6994
+
6927
6995
Ok(ReestablishResponses {
6928
6996
channel_ready, shutdown_msg, announcement_sigs,
6929
6997
raa: required_revoke,
6930
- commitment_update: None ,
6998
+ commitment_update,
6931
6999
order: self.context.resend_order.clone(),
7000
+ tx_signatures,
7001
+ tx_abort,
6932
7002
})
6933
7003
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
6934
7004
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -6943,6 +7013,8 @@ impl<SP: Deref> FundedChannel<SP> where
6943
7013
channel_ready, shutdown_msg, announcement_sigs,
6944
7014
commitment_update: None, raa: None,
6945
7015
order: self.context.resend_order.clone(),
7016
+ tx_signatures: None,
7017
+ tx_abort: None,
6946
7018
})
6947
7019
} else {
6948
7020
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -6965,6 +7037,8 @@ impl<SP: Deref> FundedChannel<SP> where
6965
7037
channel_ready, shutdown_msg, announcement_sigs,
6966
7038
raa, commitment_update,
6967
7039
order: self.context.resend_order.clone(),
7040
+ tx_signatures: None,
7041
+ tx_abort: None,
6968
7042
})
6969
7043
}
6970
7044
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8259,7 +8333,7 @@ impl<SP: Deref> FundedChannel<SP> where
8259
8333
// to the txid of that interactive transaction, else we MUST NOT set it.
8260
8334
if let Some(signing_session) = &self.interactive_tx_signing_session {
8261
8335
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8262
- if !signing_session.counterparty_sent_tx_signatures {
8336
+ if !signing_session.counterparty_sent_tx_signatures() {
8263
8337
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8264
8338
Some(self.funding_outpoint().txid)
8265
8339
} else {
0 commit comments