@@ -1074,6 +1074,8 @@ pub(super) struct ReestablishResponses {
1074
1074
pub order: RAACommitmentOrder,
1075
1075
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
1076
1076
pub shutdown_msg: Option<msgs::Shutdown>,
1077
+ pub tx_signatures: Option<msgs::TxSignatures>,
1078
+ pub tx_abort: Option<msgs::TxAbort>,
1077
1079
}
1078
1080
1079
1081
/// The first message we send to our peer after connection
@@ -2540,7 +2542,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2540
2542
2541
2543
let mut output_index = None;
2542
2544
let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2543
- for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2545
+ for (idx, outp) in signing_session.unsigned_tx() .outputs().enumerate() {
2544
2546
if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
2545
2547
if output_index.is_some() {
2546
2548
return Err(ChannelError::Close(
@@ -2553,7 +2555,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2553
2555
}
2554
2556
}
2555
2557
let outpoint = if let Some(output_index) = output_index {
2556
- OutPoint { txid: signing_session.unsigned_tx.compute_txid(), index: output_index }
2558
+ OutPoint { txid: signing_session.unsigned_tx() .compute_txid(), index: output_index }
2557
2559
} else {
2558
2560
return Err(ChannelError::Close(
2559
2561
(
@@ -2567,7 +2569,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2567
2569
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2568
2570
let commitment_signed = match commitment_signed {
2569
2571
Ok(commitment_signed) => {
2570
- self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2572
+ self.funding.funding_transaction = Some(signing_session.unsigned_tx() .build_unsigned_tx());
2571
2573
commitment_signed
2572
2574
},
2573
2575
Err(err) => {
@@ -6513,7 +6515,7 @@ impl<SP: Deref> FundedChannel<SP> where
6513
6515
}
6514
6516
6515
6517
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6516
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6518
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
6517
6519
return Err(ChannelError::Close(
6518
6520
(
6519
6521
"The txid for the transaction does not match".to_string(),
@@ -7163,7 +7165,10 @@ impl<SP: Deref> FundedChannel<SP> where
7163
7165
}
7164
7166
7165
7167
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
7166
- msg.next_local_commitment_number == 0 {
7168
+ (msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none()) {
7169
+ // Note: This also covers the following case in the V2 channel establishment specification:
7170
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
7171
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
7167
7172
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
7168
7173
}
7169
7174
@@ -7227,6 +7232,8 @@ impl<SP: Deref> FundedChannel<SP> where
7227
7232
raa: None, commitment_update: None,
7228
7233
order: RAACommitmentOrder::CommitmentFirst,
7229
7234
shutdown_msg, announcement_sigs,
7235
+ tx_signatures: None,
7236
+ tx_abort: None,
7230
7237
});
7231
7238
}
7232
7239
@@ -7236,6 +7243,8 @@ impl<SP: Deref> FundedChannel<SP> where
7236
7243
raa: None, commitment_update: None,
7237
7244
order: RAACommitmentOrder::CommitmentFirst,
7238
7245
shutdown_msg, announcement_sigs,
7246
+ tx_signatures: None,
7247
+ tx_abort: None,
7239
7248
});
7240
7249
}
7241
7250
@@ -7278,11 +7287,84 @@ impl<SP: Deref> FundedChannel<SP> where
7278
7287
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
7279
7288
}
7280
7289
7290
+ // if next_funding_txid is set:
7291
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
7292
+ if let Some(session) = &self.interactive_tx_signing_session {
7293
+ // if next_funding_txid matches the latest interactive funding transaction:
7294
+ let our_next_funding_txid = session.unsigned_tx().compute_txid();
7295
+ if our_next_funding_txid == next_funding_txid {
7296
+ debug_assert_eq!(session.unsigned_tx().compute_txid(), self.maybe_get_next_funding_txid().unwrap());
7297
+
7298
+ let commitment_update = if !session.has_received_tx_signatures() && msg.next_local_commitment_number == 0 {
7299
+ // if it has not received tx_signatures for that funding transaction AND
7300
+ // if next_commitment_number is zero:
7301
+ // MUST retransmit its commitment_signed for that funding transaction.
7302
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7303
+ Some(msgs::CommitmentUpdate {
7304
+ commitment_signed: vec![commitment_signed],
7305
+ update_add_htlcs: vec![],
7306
+ update_fulfill_htlcs: vec![],
7307
+ update_fail_htlcs: vec![],
7308
+ update_fail_malformed_htlcs: vec![],
7309
+ update_fee: None,
7310
+ })
7311
+ } else { None };
7312
+ // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
7313
+ let tx_signatures = if (
7314
+ // if it has not received tx_signatures for that funding transaction AND
7315
+ // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
7316
+ // MUST send its tx_signatures for that funding transaction.
7317
+ !session.has_received_tx_signatures() && session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first()
7318
+ // else if it has already received tx_signatures for that funding transaction:
7319
+ // MUST send its tx_signatures for that funding transaction.
7320
+ ) || session.has_received_tx_signatures() {
7321
+ if self.context.channel_state.is_monitor_update_in_progress() {
7322
+ // The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
7323
+ // if we were up first for signing and had a monitor update in progress, but check again just in case.
7324
+ debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
7325
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7326
+ if self.context.monitor_pending_tx_signatures.is_none() {
7327
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7328
+ }
7329
+ None
7330
+ } else {
7331
+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
7332
+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
7333
+ // holder must send one.
7334
+ session.holder_tx_signatures().clone()
7335
+ }
7336
+ } else {
7337
+ None
7338
+ };
7339
+ if !session.has_received_commitment_signed() {
7340
+ self.context.expecting_peer_commitment_signed = true;
7341
+ }
7342
+ (commitment_update, tx_signatures, None)
7343
+ } else {
7344
+ // The `next_funding_txid` does not match the latest interactive funding transaction so we
7345
+ // MUST send tx_abort to let the remote know that they can forget this funding transaction.
7346
+ (None, None, Some(msgs::TxAbort {
7347
+ channel_id: self.context.channel_id(),
7348
+ data: format!(
7349
+ "next_funding_txid {} does match our latest interactive funding txid {}",
7350
+ next_funding_txid, our_next_funding_txid,
7351
+ ).into_bytes() }))
7352
+ }
7353
+ } else {
7354
+ return Err(ChannelError::Warn("No active signing session. The associated funding transaction may have already been broadcast.".into()));
7355
+ }
7356
+ } else {
7357
+ // Don't send anything related to interactive signing if `next_funding_txid` is not set.
7358
+ (None, None, None)
7359
+ };
7360
+
7281
7361
Ok(ReestablishResponses {
7282
7362
channel_ready, shutdown_msg, announcement_sigs,
7283
7363
raa: required_revoke,
7284
- commitment_update: None ,
7364
+ commitment_update,
7285
7365
order: self.context.resend_order.clone(),
7366
+ tx_signatures,
7367
+ tx_abort,
7286
7368
})
7287
7369
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
7288
7370
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -7297,6 +7379,8 @@ impl<SP: Deref> FundedChannel<SP> where
7297
7379
channel_ready, shutdown_msg, announcement_sigs,
7298
7380
commitment_update: None, raa: None,
7299
7381
order: self.context.resend_order.clone(),
7382
+ tx_signatures: None,
7383
+ tx_abort: None,
7300
7384
})
7301
7385
} else {
7302
7386
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -7319,6 +7403,8 @@ impl<SP: Deref> FundedChannel<SP> where
7319
7403
channel_ready, shutdown_msg, announcement_sigs,
7320
7404
raa, commitment_update,
7321
7405
order: self.context.resend_order.clone(),
7406
+ tx_signatures: None,
7407
+ tx_abort: None,
7322
7408
})
7323
7409
}
7324
7410
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8609,7 +8695,7 @@ impl<SP: Deref> FundedChannel<SP> where
8609
8695
// to the txid of that interactive transaction, else we MUST NOT set it.
8610
8696
if let Some(signing_session) = &self.interactive_tx_signing_session {
8611
8697
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8612
- if !signing_session.counterparty_sent_tx_signatures {
8698
+ if !signing_session.has_received_tx_signatures() {
8613
8699
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8614
8700
Some(self.funding_outpoint().txid)
8615
8701
} else {
0 commit comments