@@ -1188,7 +1188,6 @@ pub(super) struct MonitorRestoreUpdates {
1188
1188
pub funding_broadcastable: Option<Transaction>,
1189
1189
pub channel_ready: Option<msgs::ChannelReady>,
1190
1190
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
1191
- pub tx_signatures: Option<msgs::TxSignatures>,
1192
1191
}
1193
1192
1194
1193
/// The return value of `signer_maybe_unblocked`
@@ -1214,7 +1213,6 @@ pub(super) struct ReestablishResponses {
1214
1213
pub order: RAACommitmentOrder,
1215
1214
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
1216
1215
pub shutdown_msg: Option<msgs::Shutdown>,
1217
- pub tx_signatures: Option<msgs::TxSignatures>,
1218
1216
pub tx_abort: Option<msgs::TxAbort>,
1219
1217
}
1220
1218
@@ -1766,7 +1764,7 @@ where
1766
1764
1767
1765
pub fn funding_tx_constructed<L: Deref>(
1768
1766
&mut self, signing_session: InteractiveTxSigningSession, logger: &L,
1769
- ) -> Result<( msgs::CommitmentSigned, Option<Transaction>) , ChannelError>
1767
+ ) -> Result<msgs::CommitmentSigned, ChannelError>
1770
1768
where
1771
1769
L::Target: Logger,
1772
1770
{
@@ -1786,7 +1784,7 @@ where
1786
1784
#[rustfmt::skip]
1787
1785
pub fn commitment_signed<L: Deref>(
1788
1786
&mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1789
- ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1787
+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>, Option<Transaction> ), ChannelError>
1790
1788
where
1791
1789
L::Target: Logger
1792
1790
{
@@ -1813,7 +1811,7 @@ where
1813
1811
pending_splice: None,
1814
1812
};
1815
1813
let res = funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger)
1816
- .map(|monitor| (Some(monitor), None))
1814
+ .map(|( monitor, funding_tx_opt) | (Some(monitor), None, funding_tx_opt ))
1817
1815
// TODO: Change to `inspect_err` when MSRV is high enough.
1818
1816
.map_err(|err| {
1819
1817
// We always expect a `ChannelError` close.
@@ -1840,15 +1838,15 @@ where
1840
1838
let res = if has_negotiated_pending_splice && !session_received_commitment_signed {
1841
1839
funded_channel
1842
1840
.splice_initial_commitment_signed(msg, logger)
1843
- .map(|monitor_update_opt| (None, monitor_update_opt))
1841
+ .map(|monitor_update_opt| (None, monitor_update_opt, None ))
1844
1842
} else {
1845
1843
funded_channel.commitment_signed(msg, logger)
1846
- .map(|monitor_update_opt| (None, monitor_update_opt))
1844
+ .map(|monitor_update_opt| (None, monitor_update_opt, None ))
1847
1845
};
1848
1846
1849
1847
#[cfg(not(splicing))]
1850
1848
let res = funded_channel.commitment_signed(msg, logger)
1851
- .map(|monitor_update_opt| (None, monitor_update_opt));
1849
+ .map(|monitor_update_opt| (None, monitor_update_opt, None ));
1852
1850
1853
1851
self.phase = ChannelPhase::Funded(funded_channel);
1854
1852
res
@@ -2315,7 +2313,6 @@ where
2315
2313
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
2316
2314
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
2317
2315
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2318
- monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
2319
2316
2320
2317
/// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
2321
2318
/// we should retry at some point in the future when the signer indicates it may have a
@@ -2916,7 +2913,7 @@ where
2916
2913
#[rustfmt::skip]
2917
2914
pub fn funding_tx_constructed<L: Deref>(
2918
2915
&mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2919
- ) -> Result<( msgs::CommitmentSigned, Option<Transaction>) , ChannelError>
2916
+ ) -> Result<msgs::CommitmentSigned, ChannelError>
2920
2917
where
2921
2918
L::Target: Logger
2922
2919
{
@@ -2954,7 +2951,8 @@ where
2954
2951
},
2955
2952
};
2956
2953
2957
- let funding_tx_opt = if signing_session.local_inputs_count() == 0 {
2954
+ // Check that we have the expected number of local inputs
2955
+ if signing_session.local_inputs_count() == 0 {
2958
2956
debug_assert_eq!(our_funding_satoshis, 0);
2959
2957
if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2960
2958
debug_assert!(
@@ -2965,10 +2963,7 @@ where
2965
2963
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
2966
2964
return Err(ChannelError::Close((msg.to_owned(), reason)));
2967
2965
}
2968
- None
2969
- } else {
2970
- Some(signing_session.unsigned_tx().build_unsigned_tx())
2971
- };
2966
+ }
2972
2967
2973
2968
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
2974
2969
channel_state.set_interactive_signing();
@@ -2978,7 +2973,7 @@ where
2978
2973
self.interactive_tx_constructor.take();
2979
2974
self.interactive_tx_signing_session = Some(signing_session);
2980
2975
2981
- Ok(( commitment_signed, funding_tx_opt) )
2976
+ Ok(commitment_signed)
2982
2977
}
2983
2978
}
2984
2979
@@ -3260,7 +3255,6 @@ where
3260
3255
monitor_pending_failures: Vec::new(),
3261
3256
monitor_pending_finalized_fulfills: Vec::new(),
3262
3257
monitor_pending_update_adds: Vec::new(),
3263
- monitor_pending_tx_signatures: None,
3264
3258
3265
3259
signer_pending_revoke_and_ack: false,
3266
3260
signer_pending_commitment_update: false,
@@ -3506,7 +3500,6 @@ where
3506
3500
monitor_pending_failures: Vec::new(),
3507
3501
monitor_pending_finalized_fulfills: Vec::new(),
3508
3502
monitor_pending_update_adds: Vec::new(),
3509
- monitor_pending_tx_signatures: None,
3510
3503
3511
3504
signer_pending_revoke_and_ack: false,
3512
3505
signer_pending_commitment_update: false,
@@ -6628,7 +6621,7 @@ where
6628
6621
#[rustfmt::skip]
6629
6622
pub fn commitment_signed_initial_v2<L: Deref>(
6630
6623
&mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
6631
- ) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, ChannelError>
6624
+ ) -> Result<( ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, Option<Transaction>) , ChannelError>
6632
6625
where L::Target: Logger
6633
6626
{
6634
6627
if !self.context.channel_state.is_interactive_signing()
@@ -6650,15 +6643,12 @@ where
6650
6643
6651
6644
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6652
6645
6653
- if let Some(tx_signatures) = self.interactive_tx_signing_session.as_mut().and_then(
6654
- |session| session.received_commitment_signed()
6655
- ) {
6656
- // We're up first for submitting our tx_signatures, but our monitor has not persisted yet
6657
- // so they'll be sent as soon as that's done.
6658
- self.context.monitor_pending_tx_signatures = Some(tx_signatures);
6659
- }
6646
+ let _ = self.interactive_tx_signing_session.as_mut().and_then(|session| session.received_commitment_signed());
6647
+ // Only build the unsigned transaction for signing if there are any holder inputs to actually sign
6648
+ let funding_tx_opt = self.interactive_tx_signing_session.as_ref().and_then(|session|
6649
+ session.local_inputs_count().gt(&0).then_some(session.unsigned_tx().build_unsigned_tx()));
6660
6650
6661
- Ok(channel_monitor)
6651
+ Ok(( channel_monitor, funding_tx_opt) )
6662
6652
}
6663
6653
6664
6654
/// Handles an incoming `commitment_signed` message for the first commitment transaction of the
@@ -6739,13 +6729,12 @@ where
6739
6729
channel_id: Some(self.context.channel_id()),
6740
6730
};
6741
6731
6742
- let tx_signatures = self
6732
+ let _ = self
6743
6733
.interactive_tx_signing_session
6744
6734
.as_mut()
6745
6735
.expect("Signing session must exist for negotiated pending splice")
6746
6736
.received_commitment_signed();
6747
6737
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6748
- self.context.monitor_pending_tx_signatures = tx_signatures;
6749
6738
6750
6739
Ok(self.push_ret_blockable_mon_update(monitor_update))
6751
6740
}
@@ -7606,8 +7595,10 @@ where
7606
7595
.map_err(|err| APIError::APIMisuseError { err })?
7607
7596
{
7608
7597
if self.is_awaiting_initial_mon_persist() {
7609
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7610
- self.context.monitor_pending_tx_signatures = Some(holder_tx_signatures);
7598
+ log_debug!(
7599
+ logger,
7600
+ "Not sending tx_signatures: a monitor update is in progress."
7601
+ );
7611
7602
return Ok(None);
7612
7603
}
7613
7604
return Ok(Some(holder_tx_signatures));
@@ -7684,8 +7675,7 @@ where
7684
7675
// case checks if there is a monitor persist in progress when we need to respond with our `tx_signatures`
7685
7676
// and sets it as pending.
7686
7677
if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
7687
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7688
- self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
7678
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
7689
7679
return Ok((None, None));
7690
7680
}
7691
7681
@@ -7941,25 +7931,14 @@ where
7941
7931
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
7942
7932
let mut pending_update_adds = Vec::new();
7943
7933
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
7944
- // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7945
- // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7946
- // transaction and waits for us to do it).
7947
- let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7948
- if tx_signatures.is_some() {
7949
- if self.context.channel_state.is_their_tx_signatures_sent() {
7950
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7951
- } else {
7952
- self.context.channel_state.set_our_tx_signatures_ready();
7953
- }
7954
- }
7955
7934
7956
7935
if self.context.channel_state.is_peer_disconnected() {
7957
7936
self.context.monitor_pending_revoke_and_ack = false;
7958
7937
self.context.monitor_pending_commitment_signed = false;
7959
7938
return MonitorRestoreUpdates {
7960
7939
raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
7961
7940
accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
7962
- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
7941
+ funding_broadcastable, channel_ready, announcement_sigs
7963
7942
};
7964
7943
}
7965
7944
@@ -7989,7 +7968,7 @@ where
7989
7968
match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
7990
7969
MonitorRestoreUpdates {
7991
7970
raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
7992
- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
7971
+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs
7993
7972
}
7994
7973
}
7995
7974
@@ -8358,7 +8337,6 @@ where
8358
8337
raa: None, commitment_update: None,
8359
8338
order: RAACommitmentOrder::CommitmentFirst,
8360
8339
shutdown_msg, announcement_sigs,
8361
- tx_signatures: None,
8362
8340
tx_abort: None,
8363
8341
});
8364
8342
}
@@ -8369,7 +8347,6 @@ where
8369
8347
raa: None, commitment_update: None,
8370
8348
order: RAACommitmentOrder::CommitmentFirst,
8371
8349
shutdown_msg, announcement_sigs,
8372
- tx_signatures: None,
8373
8350
tx_abort: None,
8374
8351
});
8375
8352
}
@@ -8414,7 +8391,7 @@ where
8414
8391
}
8415
8392
8416
8393
// if next_funding_txid is set:
8417
- let (commitment_update, tx_signatures, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
8394
+ let (commitment_update, tx_abort) = if let Some(next_funding_txid) = msg.next_funding_txid {
8418
8395
if let Some(session) = &self.interactive_tx_signing_session {
8419
8396
// if next_funding_txid matches the latest interactive funding transaction:
8420
8397
let our_next_funding_txid = session.unsigned_tx().compute_txid();
@@ -8435,41 +8412,14 @@ where
8435
8412
update_fee: None,
8436
8413
})
8437
8414
} else { None };
8438
- // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
8439
- let tx_signatures = if (
8440
- // if it has not received tx_signatures for that funding transaction AND
8441
- // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
8442
- // MUST send its tx_signatures for that funding transaction.
8443
- !self.context.channel_state.is_their_tx_signatures_sent() && session.has_received_commitment_signed() && session.holder_sends_tx_signatures_first()
8444
- // else if it has already received tx_signatures for that funding transaction:
8445
- // MUST send its tx_signatures for that funding transaction.
8446
- ) || self.context.channel_state.is_their_tx_signatures_sent() {
8447
- if self.context.channel_state.is_monitor_update_in_progress() {
8448
- // The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
8449
- // if we were up first for signing and had a monitor update in progress, but check again just in case.
8450
- debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
8451
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
8452
- if self.context.monitor_pending_tx_signatures.is_none() {
8453
- self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
8454
- }
8455
- None
8456
- } else {
8457
- // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
8458
- // when the holder provides their witnesses as this will queue a `tx_signatures` if the
8459
- // holder must send one.
8460
- session.holder_tx_signatures().clone()
8461
- }
8462
- } else {
8463
- None
8464
- };
8465
8415
if !session.has_received_commitment_signed() {
8466
8416
self.context.expecting_peer_commitment_signed = true;
8467
8417
}
8468
- (commitment_update, tx_signatures, None)
8418
+ (commitment_update, None)
8469
8419
} else {
8470
8420
// The `next_funding_txid` does not match the latest interactive funding transaction so we
8471
8421
// MUST send tx_abort to let the remote know that they can forget this funding transaction.
8472
- (None, None, Some(msgs::TxAbort {
8422
+ (None, Some(msgs::TxAbort {
8473
8423
channel_id: self.context.channel_id(),
8474
8424
data: format!(
8475
8425
"next_funding_txid {} does match our latest interactive funding txid {}",
@@ -8480,22 +8430,21 @@ where
8480
8430
// We'll just send a `tx_abort` here if we don't have a signing session for this channel
8481
8431
// on reestablish and tell our peer to just forget about it.
8482
8432
// Our peer is doing something strange, but it doesn't warrant closing the channel.
8483
- (None, None, Some(msgs::TxAbort {
8433
+ (None, Some(msgs::TxAbort {
8484
8434
channel_id: self.context.channel_id(),
8485
8435
data:
8486
8436
"No active signing session. The associated funding transaction may have already been broadcast.".as_bytes().to_vec() }))
8487
8437
}
8488
8438
} else {
8489
8439
// Don't send anything related to interactive signing if `next_funding_txid` is not set.
8490
- (None, None, None )
8440
+ (None, None)
8491
8441
};
8492
8442
8493
8443
Ok(ReestablishResponses {
8494
8444
channel_ready, shutdown_msg, announcement_sigs,
8495
8445
raa: required_revoke,
8496
8446
commitment_update,
8497
8447
order: self.context.resend_order.clone(),
8498
- tx_signatures,
8499
8448
tx_abort,
8500
8449
})
8501
8450
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
@@ -8511,7 +8460,6 @@ where
8511
8460
channel_ready, shutdown_msg, announcement_sigs,
8512
8461
commitment_update: None, raa: None,
8513
8462
order: self.context.resend_order.clone(),
8514
- tx_signatures: None,
8515
8463
tx_abort: None,
8516
8464
})
8517
8465
} else {
@@ -8535,7 +8483,6 @@ where
8535
8483
channel_ready, shutdown_msg, announcement_sigs,
8536
8484
raa, commitment_update,
8537
8485
order: self.context.resend_order.clone(),
8538
- tx_signatures: None,
8539
8486
tx_abort: None,
8540
8487
})
8541
8488
}
@@ -13211,7 +13158,6 @@ where
13211
13158
monitor_pending_failures,
13212
13159
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
13213
13160
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13214
- monitor_pending_tx_signatures: None,
13215
13161
13216
13162
signer_pending_revoke_and_ack: false,
13217
13163
signer_pending_commitment_update: false,
0 commit comments