@@ -967,6 +967,8 @@ pub(super) struct ReestablishResponses {
967
967
pub order: RAACommitmentOrder,
968
968
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
969
969
pub shutdown_msg: Option<msgs::Shutdown>,
970
+ pub tx_signatures: Option<msgs::TxSignatures>,
971
+ pub tx_abort: Option<msgs::TxAbort>,
970
972
}
971
973
972
974
/// The first message we send to our peer after connection
@@ -2272,7 +2274,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2272
2274
2273
2275
let mut output_index = None;
2274
2276
let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2275
- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2277
+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
2276
2278
if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
2277
2279
if output_index.is_some() {
2278
2280
return Err(ChannelError::Close(
@@ -2285,7 +2287,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2285
2287
}
2286
2288
}
2287
2289
let outpoint = if let Some(output_index) = output_index {
2288
- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2290
+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
2289
2291
} else {
2290
2292
return Err(ChannelError::Close(
2291
2293
(
@@ -2299,7 +2301,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2299
2301
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2300
2302
let commitment_signed = match commitment_signed {
2301
2303
Ok(commitment_signed) => {
2302
- self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2304
+ self.funding.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
2303
2305
commitment_signed
2304
2306
},
2305
2307
Err(err) => {
@@ -6159,7 +6161,7 @@ impl<SP: Deref> FundedChannel<SP> where
6159
6161
}
6160
6162
6161
6163
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6162
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6164
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
6163
6165
return Err(ChannelError::Close(
6164
6166
(
6165
6167
"The txid for the transaction does not match".to_string(),
@@ -6804,7 +6806,7 @@ impl<SP: Deref> FundedChannel<SP> where
6804
6806
}
6805
6807
6806
6808
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6807
- msg.next_local_commitment_number == 0 {
6809
+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6808
6810
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
6809
6811
}
6810
6812
@@ -6868,6 +6870,8 @@ impl<SP: Deref> FundedChannel<SP> where
6868
6870
raa: None, commitment_update: None,
6869
6871
order: RAACommitmentOrder::CommitmentFirst,
6870
6872
shutdown_msg, announcement_sigs,
6873
+ tx_signatures: None,
6874
+ tx_abort: None,
6871
6875
});
6872
6876
}
6873
6877
@@ -6877,6 +6881,8 @@ impl<SP: Deref> FundedChannel<SP> where
6877
6881
raa: None, commitment_update: None,
6878
6882
order: RAACommitmentOrder::CommitmentFirst,
6879
6883
shutdown_msg, announcement_sigs,
6884
+ tx_signatures: None,
6885
+ tx_abort: None,
6880
6886
});
6881
6887
}
6882
6888
@@ -6919,11 +6925,65 @@ impl<SP: Deref> FundedChannel<SP> where
6919
6925
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
6920
6926
}
6921
6927
6928
+ // if next_funding_txid is set:
6929
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
6930
+ if let Some(session) = &self.interactive_tx_signing_session {
6931
+ // if next_funding_txid matches the latest interactive funding transaction:
6932
+ if session.unsigned_tx().compute_txid() == next_funding_txid {
6933
+ // if it has not received tx_signatures for that funding transaction:
6934
+ if !session.counterparty_sent_tx_signatures() {
6935
+ // if next_commitment_number is zero:
6936
+ let commitment_update = if msg.next_local_commitment_number == 0 {
6937
+ // MUST retransmit its commitment_signed for that funding transaction.
6938
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
6939
+ Some(msgs::CommitmentUpdate {
6940
+ commitment_signed,
6941
+ update_add_htlcs: vec![],
6942
+ update_fulfill_htlcs: vec![],
6943
+ update_fail_htlcs: vec![],
6944
+ update_fail_malformed_htlcs: vec![],
6945
+ update_fee: None,
6946
+ })
6947
+ } else { None };
6948
+ // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
6949
+ if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
6950
+ // MUST send its tx_signatures for that funding transaction.
6951
+ (commitment_update, session.holder_tx_signatures().clone(), None)
6952
+ } else {
6953
+ (commitment_update, None, None)
6954
+ }
6955
+ } else {
6956
+ // if it has already received tx_signatures for that funding transaction:
6957
+ // MUST send its tx_signatures for that funding transaction.
6958
+ (None, session.holder_tx_signatures().clone(), None)
6959
+ }
6960
+ } else {
6961
+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
6962
+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
6963
+ }
6964
+ } else {
6965
+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
6966
+ }
6967
+ } else {
6968
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6969
+ if msg.next_local_commitment_number == 0 {
6970
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6971
+ return Err(ChannelError::close(format!(
6972
+ "Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)",
6973
+ msg.next_remote_commitment_number,
6974
+ our_commitment_transaction
6975
+ )));
6976
+ }
6977
+ (None, None, None)
6978
+ };
6979
+
6922
6980
Ok(ReestablishResponses {
6923
6981
channel_ready, shutdown_msg, announcement_sigs,
6924
6982
raa: required_revoke,
6925
- commitment_update: None ,
6983
+ commitment_update,
6926
6984
order: self.context.resend_order.clone(),
6985
+ tx_signatures,
6986
+ tx_abort,
6927
6987
})
6928
6988
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
6929
6989
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -6938,6 +6998,8 @@ impl<SP: Deref> FundedChannel<SP> where
6938
6998
channel_ready, shutdown_msg, announcement_sigs,
6939
6999
commitment_update: None, raa: None,
6940
7000
order: self.context.resend_order.clone(),
7001
+ tx_signatures: None,
7002
+ tx_abort: None,
6941
7003
})
6942
7004
} else {
6943
7005
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -6960,6 +7022,8 @@ impl<SP: Deref> FundedChannel<SP> where
6960
7022
channel_ready, shutdown_msg, announcement_sigs,
6961
7023
raa, commitment_update,
6962
7024
order: self.context.resend_order.clone(),
7025
+ tx_signatures: None,
7026
+ tx_abort: None,
6963
7027
})
6964
7028
}
6965
7029
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8250,7 +8314,7 @@ impl<SP: Deref> FundedChannel<SP> where
8250
8314
// to the txid of that interactive transaction, else we MUST NOT set it.
8251
8315
if let Some(signing_session) = &self.interactive_tx_signing_session {
8252
8316
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8253
- if !signing_session.counterparty_sent_tx_signatures {
8317
+ if !signing_session.counterparty_sent_tx_signatures() {
8254
8318
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8255
8319
Some(self.funding_outpoint().txid)
8256
8320
} else {
0 commit comments