@@ -9158,9 +9158,9 @@ where
9158
9158
}
9159
9159
9160
9160
if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
9161
- (msg.next_local_commitment_number == 0 && msg.next_funding_txid .is_none()) {
9161
+ (msg.next_local_commitment_number == 0 && msg.next_funding .is_none()) {
9162
9162
// Note: This also covers the following case in the V2 channel establishment specification:
9163
- // if `next_funding_txid ` is not set, and `next_commitment_number` is zero:
9163
+ // if `next_funding ` is not set, and `next_commitment_number` is zero:
9164
9164
// MUST immediately fail the channel and broadcast any relevant latest commitment transaction.
9165
9165
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
9166
9166
}
@@ -9211,34 +9211,135 @@ where
9211
9211
9212
9212
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height, logger);
9213
9213
9214
+ let mut commitment_update = None;
9215
+ let mut tx_signatures = None;
9216
+ let mut tx_abort = None;
9217
+
9218
+ // if next_funding is set:
9219
+ if let Some(next_funding) = &msg.next_funding {
9220
+ // - if `next_funding` matches the latest interactive funding transaction
9221
+ // or the current channel funding transaction:
9222
+ if let Some(session) = &self.interactive_tx_signing_session {
9223
+ let our_next_funding_txid = session.unsigned_tx().compute_txid();
9224
+ if our_next_funding_txid != next_funding.txid {
9225
+ return Err(ChannelError::close(format!(
9226
+ "Unexpected next_funding txid: {}; expected: {}",
9227
+ next_funding.txid, our_next_funding_txid,
9228
+ )));
9229
+ }
9230
+
9231
+ if !session.has_received_commitment_signed() {
9232
+ self.context.expecting_peer_commitment_signed = true;
9233
+ }
9234
+
9235
+ // TODO(splicing): Add comment for spec requirements
9236
+ if next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned) {
9237
+ #[cfg(splicing)]
9238
+ let funding = self
9239
+ .pending_splice
9240
+ .as_ref()
9241
+ .and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
9242
+ .and_then(|funding_negotiation| {
9243
+ if let FundingNegotiation::AwaitingSignatures(funding) = &funding_negotiation {
9244
+ Some(funding)
9245
+ } else {
9246
+ None
9247
+ }
9248
+ })
9249
+ .or_else(|| Some(&self.funding))
9250
+ .filter(|funding| funding.get_funding_txid() == Some(next_funding.txid))
9251
+ .ok_or_else(|| {
9252
+ let message = "Failed to find funding for new commitment_signed".to_owned();
9253
+ ChannelError::Close(
9254
+ (
9255
+ message.clone(),
9256
+ ClosureReason::HolderForceClosed { message, broadcasted_latest_txn: Some(false) },
9257
+ )
9258
+ )
9259
+ })?;
9260
+ #[cfg(not(splicing))]
9261
+ let funding = &self.funding;
9262
+
9263
+ let commitment_signed = self.context.get_initial_commitment_signed_v2(&funding, logger)
9264
+ // TODO(splicing): Support async signing
9265
+ .ok_or_else(|| {
9266
+ let message = "Failed to get signatures for new commitment_signed".to_owned();
9267
+ ChannelError::Close(
9268
+ (
9269
+ message.clone(),
9270
+ ClosureReason::HolderForceClosed { message, broadcasted_latest_txn: Some(false) },
9271
+ )
9272
+ )
9273
+ })?;
9274
+
9275
+ commitment_update = Some(msgs::CommitmentUpdate {
9276
+ commitment_signed: vec![commitment_signed],
9277
+ update_add_htlcs: vec![],
9278
+ update_fulfill_htlcs: vec![],
9279
+ update_fail_htlcs: vec![],
9280
+ update_fail_malformed_htlcs: vec![],
9281
+ update_fee: None,
9282
+ });
9283
+ }
9284
+
9285
+ // - if it has already received `commitment_signed` and it should sign first
9286
+ // - MUST send its `tx_signatures` for that funding transaction.
9287
+ //
9288
+ // - if it has already received `tx_signatures` for that funding transaction:
9289
+ // - MUST send its `tx_signatures` for that funding transaction.
9290
+ if (session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first())
9291
+ || self.context.channel_state.is_their_tx_signatures_sent()
9292
+ {
9293
+ // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
9294
+ // when the holder provides their witnesses as this will queue a `tx_signatures` if the
9295
+ // holder must send one.
9296
+ if session.holder_tx_signatures().is_none() {
9297
+ log_debug!(logger, "Waiting for funding transaction signatures to be provided");
9298
+ } else if self.context.channel_state.is_monitor_update_in_progress() {
9299
+ log_debug!(logger, "Waiting for monitor update before providing funding transaction signatures");
9300
+ } else {
9301
+ tx_signatures = session.holder_tx_signatures().clone();
9302
+ }
9303
+ }
9304
+ } else {
9305
+ // We'll just send a `tx_abort` here if we don't have a signing session for this channel
9306
+ // on reestablish and tell our peer to just forget about it.
9307
+ // Our peer is doing something strange, but it doesn't warrant closing the channel.
9308
+ tx_abort = Some(msgs::TxAbort {
9309
+ channel_id: self.context.channel_id(),
9310
+ data:
9311
+ "No active signing session. The associated funding transaction may have already been broadcast.".as_bytes().to_vec() });
9312
+ }
9313
+ }
9314
+
9214
9315
if matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
9215
9316
// If we're waiting on a monitor update, we shouldn't re-send any channel_ready's.
9216
9317
if !self.context.channel_state.is_our_channel_ready() ||
9217
9318
self.context.channel_state.is_monitor_update_in_progress() {
9218
9319
if msg.next_remote_commitment_number != 0 {
9219
9320
return Err(ChannelError::close("Peer claimed they saw a revoke_and_ack but we haven't sent channel_ready yet".to_owned()));
9220
9321
}
9221
- // Short circuit the whole handler as there is nothing we can resend them
9322
+
9222
9323
return Ok(ReestablishResponses {
9223
9324
channel_ready: None,
9224
- channel_ready_order: ChannelReadyOrder::ChannelReadyFirst ,
9225
- raa: None, commitment_update: None ,
9226
- commitment_order: RAACommitmentOrder::CommitmentFirst ,
9325
+ channel_ready_order: ChannelReadyOrder::SignaturesFirst ,
9326
+ raa: None, commitment_update,
9327
+ commitment_order: self.context.resend_order.clone() ,
9227
9328
shutdown_msg, announcement_sigs,
9228
- tx_signatures: None ,
9329
+ tx_signatures,
9229
9330
tx_abort: None,
9230
9331
});
9231
9332
}
9232
9333
9233
9334
// We have OurChannelReady set!
9234
9335
return Ok(ReestablishResponses {
9235
9336
channel_ready: self.get_channel_ready(logger),
9236
- channel_ready_order: ChannelReadyOrder::ChannelReadyFirst ,
9237
- raa: None, commitment_update: None ,
9238
- commitment_order: RAACommitmentOrder::CommitmentFirst ,
9337
+ channel_ready_order: ChannelReadyOrder::SignaturesFirst ,
9338
+ raa: None, commitment_update,
9339
+ commitment_order: self.context.resend_order.clone() ,
9239
9340
shutdown_msg, announcement_sigs,
9240
- tx_signatures: None ,
9241
- tx_abort: None ,
9341
+ tx_signatures,
9342
+ tx_abort,
9242
9343
});
9243
9344
}
9244
9345
@@ -9281,88 +9382,6 @@ where
9281
9382
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
9282
9383
}
9283
9384
9284
- // if next_funding_txid is set:
9285
- let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
9286
- if let Some(session) = &self.interactive_tx_signing_session {
9287
- // if next_funding_txid matches the latest interactive funding transaction:
9288
- let our_next_funding_txid = session.unsigned_tx().compute_txid();
9289
- if our_next_funding_txid == next_funding_txid {
9290
- debug_assert_eq!(session.unsigned_tx().compute_txid(), self.maybe_get_next_funding_txid().unwrap());
9291
-
9292
- let commitment_update = if !self.context.channel_state.is_their_tx_signatures_sent() && msg.next_local_commitment_number == 0 {
9293
- // if it has not received tx_signatures for that funding transaction AND
9294
- // if next_commitment_number is zero:
9295
- // MUST retransmit its commitment_signed for that funding transaction.
9296
- let commitment_signed = self.context.get_initial_commitment_signed_v2(&self.funding, logger)
9297
- // TODO(splicing): Support async signing
9298
- .ok_or_else(|| {
9299
- let message = "Failed to get signatures for new commitment_signed".to_owned();
9300
- ChannelError::Close(
9301
- (
9302
- message.clone(),
9303
- ClosureReason::HolderForceClosed { message, broadcasted_latest_txn: Some(false) },
9304
- )
9305
- )})?;
9306
- Some(msgs::CommitmentUpdate {
9307
- commitment_signed: vec![commitment_signed],
9308
- update_add_htlcs: vec![],
9309
- update_fulfill_htlcs: vec![],
9310
- update_fail_htlcs: vec![],
9311
- update_fail_malformed_htlcs: vec![],
9312
- update_fee: None,
9313
- })
9314
- } else { None };
9315
- let tx_signatures = if (
9316
- // if it has not received tx_signatures for that funding transaction AND
9317
- // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
9318
- // MUST send its tx_signatures for that funding transaction.
9319
- !self.context.channel_state.is_their_tx_signatures_sent() && session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first()
9320
- // else if it has already received tx_signatures for that funding transaction:
9321
- // MUST send its tx_signatures for that funding transaction.
9322
- ) || self.context.channel_state.is_their_tx_signatures_sent() {
9323
- // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
9324
- // when the holder provides their witnesses as this will queue a `tx_signatures` if the
9325
- // holder must send one.
9326
- if session.holder_tx_signatures().is_none() {
9327
- log_debug!(logger, "Waiting for funding transaction signatures to be provided");
9328
- None
9329
- } else if self.context.channel_state.is_monitor_update_in_progress() {
9330
- log_debug!(logger, "Waiting for monitor update before providing funding transaction signatures");
9331
- None
9332
- } else {
9333
- session.holder_tx_signatures().clone()
9334
- }
9335
- } else {
9336
- None
9337
- };
9338
- if !session.has_received_commitment_signed() {
9339
- self.context.expecting_peer_commitment_signed = true;
9340
- }
9341
- (commitment_update, tx_signatures, None)
9342
- } else {
9343
- // The `next_funding_txid` does not match the latest interactive funding transaction so we
9344
- // MUST send tx_abort to let the remote know that they can forget this funding transaction.
9345
- (None, None, Some(msgs::TxAbort {
9346
- channel_id: self.context.channel_id(),
9347
- data: format!(
9348
- "next_funding_txid {} does match our latest interactive funding txid {}",
9349
- next_funding_txid, our_next_funding_txid,
9350
- ).into_bytes() }))
9351
- }
9352
- } else {
9353
- // We'll just send a `tx_abort` here if we don't have a signing session for this channel
9354
- // on reestablish and tell our peer to just forget about it.
9355
- // Our peer is doing something strange, but it doesn't warrant closing the channel.
9356
- (None, None, Some(msgs::TxAbort {
9357
- channel_id: self.context.channel_id(),
9358
- data:
9359
- "No active signing session. The associated funding transaction may have already been broadcast.".as_bytes().to_vec() }))
9360
- }
9361
- } else {
9362
- // Don't send anything related to interactive signing if `next_funding_txid` is not set.
9363
- (None, None, None)
9364
- };
9365
-
9366
9385
Ok(ReestablishResponses {
9367
9386
channel_ready,
9368
9387
channel_ready_order: ChannelReadyOrder::SignaturesFirst,
@@ -9375,6 +9394,12 @@ where
9375
9394
tx_abort,
9376
9395
})
9377
9396
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
9397
+ debug_assert!(commitment_update.is_none());
9398
+
9399
+ // TODO(splicing): Assert in a test that we don't retransmit tx_signatures instead
9400
+ #[cfg(test)]
9401
+ assert!(tx_signatures.is_none());
9402
+
9378
9403
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
9379
9404
log_debug!(logger, "Reconnected channel {} with lost outbound RAA and lost remote commitment tx", &self.context.channel_id());
9380
9405
} else {
@@ -9390,7 +9415,7 @@ where
9390
9415
commitment_update: None, raa: None,
9391
9416
commitment_order: self.context.resend_order.clone(),
9392
9417
tx_signatures: None,
9393
- tx_abort: None ,
9418
+ tx_abort,
9394
9419
})
9395
9420
} else {
9396
9421
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -9416,7 +9441,7 @@ where
9416
9441
raa, commitment_update,
9417
9442
commitment_order: self.context.resend_order.clone(),
9418
9443
tx_signatures: None,
9419
- tx_abort: None ,
9444
+ tx_abort,
9420
9445
})
9421
9446
}
9422
9447
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -11007,15 +11032,29 @@ where
11007
11032
}
11008
11033
11009
11034
#[rustfmt::skip]
11010
- fn maybe_get_next_funding_txid (&self) -> Option<Txid > {
11035
+ fn maybe_get_next_funding (&self) -> Option<msgs::NextFunding > {
11011
11036
// If we've sent `commtiment_signed` for an interactively constructed transaction
11012
- // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid `
11037
+ // during a signing session, but have not received `tx_signatures` we MUST set `next_funding `
11013
11038
// to the txid of that interactive transaction, else we MUST NOT set it.
11014
11039
if self.context.channel_state.is_interactive_signing() {
11015
11040
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
11016
11041
if !self.context.channel_state.is_their_tx_signatures_sent() {
11017
11042
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
11018
- self.interactive_tx_signing_session.as_ref().map(|signing_session| signing_session.unsigned_tx().compute_txid())
11043
+ self.interactive_tx_signing_session
11044
+ .as_ref()
11045
+ .map(|signing_session| {
11046
+ let mut next_funding = msgs::NextFunding {
11047
+ txid: signing_session.unsigned_tx().compute_txid(),
11048
+ retransmit_flags: 0,
11049
+ };
11050
+
11051
+ // TODO(splicing): Add comment for spec requirements
11052
+ if !signing_session.has_received_commitment_signed() {
11053
+ next_funding.retransmit(msgs::NextFundingFlag::CommitmentSigned);
11054
+ }
11055
+
11056
+ next_funding
11057
+ })
11019
11058
} else {
11020
11059
// ...and we received a `tx_signatures` from the counterparty.
11021
11060
None
@@ -11092,7 +11131,7 @@ where
11092
11131
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number - 1,
11093
11132
your_last_per_commitment_secret: remote_last_secret,
11094
11133
my_current_per_commitment_point: dummy_pubkey,
11095
- next_funding_txid : self.maybe_get_next_funding_txid (),
11134
+ next_funding : self.maybe_get_next_funding (),
11096
11135
my_current_funding_locked: self.maybe_get_my_current_funding_locked(),
11097
11136
}
11098
11137
}
0 commit comments