@@ -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) => {
@@ -6543,7 +6545,7 @@ impl<SP: Deref> FundedChannel<SP> where
6543
6545
}
6544
6546
6545
6547
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6546
- if msg.tx_hash != signing_session.unsigned_tx.compute_txid() {
6548
+ if msg.tx_hash != signing_session.unsigned_tx() .compute_txid() {
6547
6549
return Err(ChannelError::Close(
6548
6550
(
6549
6551
"The txid for the transaction does not match".to_string(),
@@ -7193,7 +7195,10 @@ impl<SP: Deref> FundedChannel<SP> where
7193
7195
}
7194
7196
7195
7197
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
7196
- msg.next_local_commitment_number == 0 {
7198
+ (msg.next_local_commitment_number == 0 && msg.next_funding_txid.is_none()) {
7199
+ // Note: This also covers the following case in the V2 channel establishment specification:
7200
+ // if `next_funding_txid` is not set, and `next_commitment_number` is zero:
7201
+ // MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
7197
7202
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
7198
7203
}
7199
7204
@@ -7257,6 +7262,8 @@ impl<SP: Deref> FundedChannel<SP> where
7257
7262
raa: None, commitment_update: None,
7258
7263
order: RAACommitmentOrder::CommitmentFirst,
7259
7264
shutdown_msg, announcement_sigs,
7265
+ tx_signatures: None,
7266
+ tx_abort: None,
7260
7267
});
7261
7268
}
7262
7269
@@ -7266,6 +7273,8 @@ impl<SP: Deref> FundedChannel<SP> where
7266
7273
raa: None, commitment_update: None,
7267
7274
order: RAACommitmentOrder::CommitmentFirst,
7268
7275
shutdown_msg, announcement_sigs,
7276
+ tx_signatures: None,
7277
+ tx_abort: None,
7269
7278
});
7270
7279
}
7271
7280
@@ -7308,11 +7317,84 @@ impl<SP: Deref> FundedChannel<SP> where
7308
7317
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
7309
7318
}
7310
7319
7320
+ // if next_funding_txid is set:
7321
+ let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
7322
+ if let Some(session) = &self.interactive_tx_signing_session {
7323
+ // if next_funding_txid matches the latest interactive funding transaction:
7324
+ let our_next_funding_txid = session.unsigned_tx().compute_txid();
7325
+ if our_next_funding_txid == next_funding_txid {
7326
+ debug_assert_eq!(session.unsigned_tx().compute_txid(), self.maybe_get_next_funding_txid().unwrap());
7327
+
7328
+ let commitment_update = if !session.has_received_tx_signatures() && msg.next_local_commitment_number == 0 {
7329
+ // if it has not received tx_signatures for that funding transaction AND
7330
+ // if next_commitment_number is zero:
7331
+ // MUST retransmit its commitment_signed for that funding transaction.
7332
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
7333
+ Some(msgs::CommitmentUpdate {
7334
+ commitment_signed: vec![commitment_signed],
7335
+ update_add_htlcs: vec![],
7336
+ update_fulfill_htlcs: vec![],
7337
+ update_fail_htlcs: vec![],
7338
+ update_fail_malformed_htlcs: vec![],
7339
+ update_fee: None,
7340
+ })
7341
+ } else { None };
7342
+ // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
7343
+ let tx_signatures = if (
7344
+ // if it has not received tx_signatures for that funding transaction AND
7345
+ // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
7346
+ // MUST send its tx_signatures for that funding transaction.
7347
+ !session.has_received_tx_signatures() && session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first()
7348
+ // else if it has already received tx_signatures for that funding transaction:
7349
+ // MUST send its tx_signatures for that funding transaction.
7350
+ ) || session.has_received_tx_signatures() {
7351
+ if self.context.channel_state.is_monitor_update_in_progress() {
7352
+ // The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
7353
+ // if we were up first for signing and had a monitor update in progress, but check again just in case.
7354
+ debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
7355
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7356
+ if self.context.monitor_pending_tx_signatures.is_none() {
7357
+ self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
7358
+ }
7359
+ None
7360
+ } else {
7361
+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
7362
+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
7363
+ // holder must send one.
7364
+ session.holder_tx_signatures().clone()
7365
+ }
7366
+ } else {
7367
+ None
7368
+ };
7369
+ if !session.has_received_commitment_signed() {
7370
+ self.context.expecting_peer_commitment_signed = true;
7371
+ }
7372
+ (commitment_update, tx_signatures, None)
7373
+ } else {
7374
+ // The `next_funding_txid` does not match the latest interactive funding transaction so we
7375
+ // MUST send tx_abort to let the remote know that they can forget this funding transaction.
7376
+ (None, None, Some(msgs::TxAbort {
7377
+ channel_id: self.context.channel_id(),
7378
+ data: format!(
7379
+ "next_funding_txid {} does match our latest interactive funding txid {}",
7380
+ next_funding_txid, our_next_funding_txid,
7381
+ ).into_bytes() }))
7382
+ }
7383
+ } else {
7384
+ return Err(ChannelError::Warn("No active signing session. The associated funding transaction may have already been broadcast.".into()));
7385
+ }
7386
+ } else {
7387
+ // Don't send anything related to interactive signing if `next_funding_txid` is not set.
7388
+ (None, None, None)
7389
+ };
7390
+
7311
7391
Ok(ReestablishResponses {
7312
7392
channel_ready, shutdown_msg, announcement_sigs,
7313
7393
raa: required_revoke,
7314
- commitment_update: None ,
7394
+ commitment_update,
7315
7395
order: self.context.resend_order.clone(),
7396
+ tx_signatures,
7397
+ tx_abort,
7316
7398
})
7317
7399
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
7318
7400
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
@@ -7327,6 +7409,8 @@ impl<SP: Deref> FundedChannel<SP> where
7327
7409
channel_ready, shutdown_msg, announcement_sigs,
7328
7410
commitment_update: None, raa: None,
7329
7411
order: self.context.resend_order.clone(),
7412
+ tx_signatures: None,
7413
+ tx_abort: None,
7330
7414
})
7331
7415
} else {
7332
7416
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -7349,6 +7433,8 @@ impl<SP: Deref> FundedChannel<SP> where
7349
7433
channel_ready, shutdown_msg, announcement_sigs,
7350
7434
raa, commitment_update,
7351
7435
order: self.context.resend_order.clone(),
7436
+ tx_signatures: None,
7437
+ tx_abort: None,
7352
7438
})
7353
7439
}
7354
7440
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -8636,9 +8722,9 @@ impl<SP: Deref> FundedChannel<SP> where
8636
8722
// to the txid of that interactive transaction, else we MUST NOT set it.
8637
8723
if let Some(signing_session) = &self.interactive_tx_signing_session {
8638
8724
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8639
- if !signing_session.counterparty_sent_tx_signatures {
8725
+ if !signing_session.has_received_tx_signatures() {
8640
8726
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8641
- Some(self.funding_outpoint ().txid )
8727
+ Some(signing_session.unsigned_tx ().compute_txid() )
8642
8728
} else {
8643
8729
// ...and we received a `tx_signatures` from the counterparty.
8644
8730
None
0 commit comments