@@ -931,6 +931,8 @@ pub(super) struct ReestablishResponses {
931
931
pub order: RAACommitmentOrder,
932
932
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
933
933
pub shutdown_msg: Option<msgs::Shutdown>,
934
+ pub tx_signatures: Option<msgs::TxSignatures>,
935
+ pub tx_abort: Option<msgs::TxAbort>,
934
936
}
935
937
936
938
/// The first message we send to our peer after connection
@@ -2088,7 +2090,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2088
2090
2089
2091
let mut output_index = None;
2090
2092
let expected_spk = self.context.get_funding_redeemscript().to_p2wsh();
2091
- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2093
+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
2092
2094
if outp.script_pubkey() == &expected_spk && outp.value() == self.context.get_value_satoshis() {
2093
2095
if output_index.is_some() {
2094
2096
return Err(ChannelError::Close(
@@ -2101,7 +2103,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2101
2103
}
2102
2104
}
2103
2105
let outpoint = if let Some(output_index) = output_index {
2104
- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2106
+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
2105
2107
} else {
2106
2108
return Err(ChannelError::Close(
2107
2109
(
@@ -2116,7 +2118,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2116
2118
let commitment_signed = self.context.get_initial_commitment_signed(logger);
2117
2119
let commitment_signed = match commitment_signed {
2118
2120
Ok(commitment_signed) => {
2119
- self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2121
+ self.context.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
2120
2122
commitment_signed
2121
2123
},
2122
2124
Err(err) => {
@@ -5961,7 +5963,7 @@ impl<SP: Deref> FundedChannel<SP> where
5961
5963
}
5962
5964
5963
5965
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
5964
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
5966
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
5965
5967
return Err(ChannelError::Close(
5966
5968
(
5967
5969
"The txid for the transaction does not match".to_string(),
@@ -6591,7 +6593,7 @@ impl<SP: Deref> FundedChannel<SP> where
6591
6593
}
6592
6594
6593
6595
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
6594
- msg.next_local_commitment_number == 0 {
6596
+ msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none() {
6595
6597
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
6596
6598
}
6597
6599
@@ -6655,6 +6657,8 @@ impl<SP: Deref> FundedChannel<SP> where
6655
6657
raa: None, commitment_update: None,
6656
6658
order: RAACommitmentOrder::CommitmentFirst,
6657
6659
shutdown_msg, announcement_sigs,
6660
+ tx_signatures: None,
6661
+ tx_abort: None,
6658
6662
});
6659
6663
}
6660
6664
@@ -6664,6 +6668,8 @@ impl<SP: Deref> FundedChannel<SP> where
6664
6668
raa: None, commitment_update: None,
6665
6669
order: RAACommitmentOrder::CommitmentFirst,
6666
6670
shutdown_msg, announcement_sigs,
6671
+ tx_signatures: None,
6672
+ tx_abort: None,
6667
6673
});
6668
6674
}
6669
6675
@@ -6709,11 +6715,67 @@ impl<SP: Deref> FundedChannel<SP> where
6709
6715
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
6710
6716
}
6711
6717
6718
+ // if next_funding_txid is set:
6719
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
6720
+ if let Some(session) = &self.interactive_tx_signing_session {
6721
+ // if next_funding_txid matches the latest interactive funding transaction:
6722
+ if session.unsigned_tx().compute_txid() == next_funding_txid {
6723
+ // if it has not received tx_signatures for that funding transaction:
6724
+ if !session.counterparty_sent_tx_signatures() {
6725
+ // if next_commitment_number is zero:
6726
+ let commitment_update = if msg.next_local_commitment_number == 0 {
6727
+ // MUST retransmit its commitment_signed for that funding transaction.
6728
+ let commitment_signed = self.context.get_initial_commitment_signed(logger)?;
6729
+ Some(msgs::CommitmentUpdate {
6730
+ commitment_signed,
6731
+ update_add_htlcs: vec![],
6732
+ update_fulfill_htlcs: vec![],
6733
+ update_fail_htlcs: vec![],
6734
+ update_fail_malformed_htlcs: vec![],
6735
+ update_fee: None,
6736
+ })
6737
+ } else { None };
6738
+ // if it has already received commitment_signed and it should sign first, as specified in the tx_signatures requirements:
6739
+ if session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first() {
6740
+ // MUST send its tx_signatures for that funding transaction.
6741
+ (commitment_update, session.holder_tx_signatures().clone(), None)
6742
+ } else {
6743
+ (commitment_update, None, None)
6744
+ }
6745
+ } else {
6746
+ // if it has already received tx_signatures for that funding transaction:
6747
+ // MUST send its tx_signatures for that funding transaction.
6748
+ (None, session.holder_tx_signatures().clone(), None)
6749
+ }
6750
+ } else {
6751
+ // MUST send tx_abort to let the sending node know that they can forget this funding transaction.
6752
+ (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
6753
+ }
6754
+ } else {
6755
+ // Counterparty set `next_funding_txid` at incorrect state.
6756
+ // TODO(dual_funding): Should probably error here (or send tx_abort) but not in spec.
6757
+ (None, None, None)
6758
+ }
6759
+ } else {
6760
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
6761
+ if msg.next_local_commitment_number == 0 {
6762
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
6763
+ return Err(ChannelError::close(format!(
6764
+ "Peer attempted to reestablish channel expecting a future local commitment transaction: {} (received) vs {} (expected)",
6765
+ msg.next_remote_commitment_number,
6766
+ our_commitment_transaction
6767
+ )));
6768
+ }
6769
+ (None, None, None)
6770
+ };
6771
+
6712
6772
Ok(ReestablishResponses {
6713
6773
channel_ready, shutdown_msg, announcement_sigs,
6714
6774
raa: required_revoke,
6715
- commitment_update: None ,
6775
+ commitment_update,
6716
6776
order: self.context.resend_order.clone(),
6777
+ tx_signatures,
6778
+ tx_abort,
6717
6779
})
6718
6780
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
6719
6781
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -6728,6 +6790,8 @@ impl<SP: Deref> FundedChannel<SP> where
6728
6790
channel_ready, shutdown_msg, announcement_sigs,
6729
6791
commitment_update: None, raa: None,
6730
6792
order: self.context.resend_order.clone(),
6793
+ tx_signatures: None,
6794
+ tx_abort: None,
6731
6795
})
6732
6796
} else {
6733
6797
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -6750,6 +6814,8 @@ impl<SP: Deref> FundedChannel<SP> where
6750
6814
channel_ready, shutdown_msg, announcement_sigs,
6751
6815
raa, commitment_update,
6752
6816
order: self.context.resend_order.clone(),
6817
+ tx_signatures: None,
6818
+ tx_abort: None,
6753
6819
})
6754
6820
}
6755
6821
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8027,7 +8093,7 @@ impl<SP: Deref> FundedChannel<SP> where
8027
8093
// to the txid of that interactive transaction, else we MUST NOT set it.
8028
8094
if let Some(signing_session) = &self.interactive_tx_signing_session {
8029
8095
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8030
- if !signing_session.counterparty_sent_tx_signatures {
8096
+ if !signing_session.counterparty_sent_tx_signatures() {
8031
8097
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8032
8098
Some(self.funding_outpoint().txid)
8033
8099
} else {
0 commit comments