@@ -14,7 +14,7 @@ use bitcoin::constants::ChainHash;
14
14
use bitcoin::script::{Builder, Script, ScriptBuf, WScriptHash};
15
15
use bitcoin::sighash::EcdsaSighashType;
16
16
use bitcoin::transaction::{Transaction, TxIn, TxOut};
17
- use bitcoin::Weight;
17
+ use bitcoin::{ Weight, Witness} ;
18
18
19
19
use bitcoin::hash_types::{BlockHash, Txid};
20
20
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -36,7 +36,7 @@ use crate::chain::channelmonitor::{
36
36
use crate::chain::transaction::{OutPoint, TransactionData};
37
37
use crate::chain::BestBlock;
38
38
use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
39
- use crate::events::{ ClosureReason, Event} ;
39
+ use crate::events::ClosureReason;
40
40
use crate::ln::chan_utils;
41
41
#[cfg(splicing)]
42
42
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
@@ -1761,7 +1761,7 @@ where
1761
1761
1762
1762
pub fn funding_tx_constructed<L: Deref>(
1763
1763
&mut self, signing_session: InteractiveTxSigningSession, logger: &L,
1764
- ) -> Result<( msgs::CommitmentSigned, Option<Event>) , ChannelError>
1764
+ ) -> Result<msgs::CommitmentSigned, ChannelError>
1765
1765
where
1766
1766
L::Target: Logger,
1767
1767
{
@@ -2310,7 +2310,6 @@ where
2310
2310
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
2311
2311
monitor_pending_finalized_fulfills: Vec<(HTLCSource, Option<AttributionData>)>,
2312
2312
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2313
- monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
2314
2313
2315
2314
/// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
2316
2315
/// we should retry at some point in the future when the signer indicates it may have a
@@ -2910,12 +2909,11 @@ where
2910
2909
2911
2910
#[rustfmt::skip]
2912
2911
pub fn funding_tx_constructed<L: Deref>(
2913
- &mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2914
- ) -> Result<( msgs::CommitmentSigned, Option<Event>) , ChannelError>
2912
+ &mut self, signing_session: InteractiveTxSigningSession, logger: &L
2913
+ ) -> Result<msgs::CommitmentSigned, ChannelError>
2915
2914
where
2916
2915
L::Target: Logger
2917
2916
{
2918
- let our_funding_satoshis = self.dual_funding_context.our_funding_satoshis;
2919
2917
let transaction_number = self.unfunded_context.transaction_number();
2920
2918
2921
2919
let mut output_index = None;
@@ -2949,42 +2947,6 @@ where
2949
2947
},
2950
2948
};
2951
2949
2952
- let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
2953
- debug_assert_eq!(our_funding_satoshis, 0);
2954
- if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2955
- debug_assert!(
2956
- false,
2957
- "Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
2958
- );
2959
- let msg = "V2 channel rejected due to sender error";
2960
- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
2961
- return Err(ChannelError::Close((msg.to_owned(), reason)));
2962
- }
2963
- None
2964
- } else {
2965
- // TODO(dual_funding): Send event for signing if we've contributed funds.
2966
- // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
2967
- // inputs/signatures.
2968
- // Also warn the user that we don't do anything to prevent the counterparty from
2969
- // providing non-standard witnesses which will prevent the funding transaction from
2970
- // confirming. This warning must appear in doc comments wherever the user is contributing
2971
- // funds, whether they are initiator or acceptor.
2972
- //
2973
- // The following warning can be used when the APIs allowing contributing inputs become available:
2974
- // <div class="warning">
2975
- // WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
2976
- // will prevent the funding transaction from being relayed on the bitcoin network and hence being
2977
- // confirmed.
2978
- // </div>
2979
- debug_assert!(
2980
- false,
2981
- "We don't support users providing inputs but somehow we had more than zero inputs",
2982
- );
2983
- let msg = "V2 channel rejected due to sender error";
2984
- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
2985
- return Err(ChannelError::Close((msg.to_owned(), reason)));
2986
- };
2987
-
2988
2950
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
2989
2951
channel_state.set_interactive_signing();
2990
2952
self.context.channel_state = channel_state;
@@ -2993,7 +2955,7 @@ where
2993
2955
self.interactive_tx_constructor.take();
2994
2956
self.interactive_tx_signing_session = Some(signing_session);
2995
2957
2996
- Ok(( commitment_signed, funding_ready_for_sig_event) )
2958
+ Ok(commitment_signed)
2997
2959
}
2998
2960
}
2999
2961
@@ -3275,7 +3237,6 @@ where
3275
3237
monitor_pending_failures: Vec::new(),
3276
3238
monitor_pending_finalized_fulfills: Vec::new(),
3277
3239
monitor_pending_update_adds: Vec::new(),
3278
- monitor_pending_tx_signatures: None,
3279
3240
3280
3241
signer_pending_revoke_and_ack: false,
3281
3242
signer_pending_commitment_update: false,
@@ -3514,7 +3475,6 @@ where
3514
3475
monitor_pending_failures: Vec::new(),
3515
3476
monitor_pending_finalized_fulfills: Vec::new(),
3516
3477
monitor_pending_update_adds: Vec::new(),
3517
- monitor_pending_tx_signatures: None,
3518
3478
3519
3479
signer_pending_revoke_and_ack: false,
3520
3480
signer_pending_commitment_update: false,
@@ -6767,13 +6727,7 @@ where
6767
6727
6768
6728
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6769
6729
6770
- if let Some(tx_signatures) = self.interactive_tx_signing_session.as_mut().and_then(
6771
- |session| session.received_commitment_signed()
6772
- ) {
6773
- // We're up first for submitting our tx_signatures, but our monitor has not persisted yet
6774
- // so they'll be sent as soon as that's done.
6775
- self.context.monitor_pending_tx_signatures = Some(tx_signatures);
6776
- }
6730
+ self.interactive_tx_signing_session.as_mut().map(|session| session.received_commitment_signed());
6777
6731
6778
6732
Ok(channel_monitor)
6779
6733
}
@@ -6856,13 +6810,12 @@ where
6856
6810
channel_id: Some(self.context.channel_id()),
6857
6811
};
6858
6812
6859
- let tx_signatures = self
6813
+ let _ = self
6860
6814
.interactive_tx_signing_session
6861
6815
.as_mut()
6862
6816
.expect("Signing session must exist for negotiated pending splice")
6863
6817
.received_commitment_signed();
6864
6818
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6865
- self.context.monitor_pending_tx_signatures = tx_signatures;
6866
6819
6867
6820
Ok(self.push_ret_blockable_mon_update(monitor_update))
6868
6821
}
@@ -7772,10 +7725,26 @@ where
7772
7725
}
7773
7726
}
7774
7727
7728
+ pub fn funding_transaction_signed(
7729
+ &mut self, witnesses: Vec<Witness>,
7730
+ ) -> Result<Option<msgs::TxSignatures>, APIError> {
7731
+ self.interactive_tx_signing_session
7732
+ .as_mut()
7733
+ .ok_or_else(|| APIError::APIMisuseError {
7734
+ err: format!(
7735
+ "Channel with id {} not expecting funding signatures",
7736
+ self.context.channel_id
7737
+ ),
7738
+ })
7739
+ .and_then(|signing_session| {
7740
+ signing_session
7741
+ .provide_holder_witnesses(self.context.channel_id, witnesses)
7742
+ .map_err(|err| APIError::APIMisuseError { err })
7743
+ })
7744
+ }
7745
+
7775
7746
#[rustfmt::skip]
7776
- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
7777
- where L::Target: Logger
7778
- {
7747
+ pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError> {
7779
7748
if !self.context.channel_state.is_interactive_signing()
7780
7749
|| self.context.channel_state.is_their_tx_signatures_sent()
7781
7750
{
@@ -7828,15 +7797,8 @@ where
7828
7797
self.funding.funding_transaction = funding_tx_opt.clone();
7829
7798
}
7830
7799
7831
- // Note that `holder_tx_signatures_opt` will be `None` if we sent `tx_signatures` first, so this
7832
- // case checks if there is a monitor persist in progress when we need to respond with our `tx_signatures`
7833
- // and sets it as pending.
7834
- if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
7835
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7836
- self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
7837
- return Ok((None, None));
7838
- }
7839
-
7800
+ // Note that `holder_tx_signatures_opt` will be `None` if we sent `tx_signatures` first or if the
7801
+ // user still needs to provide tx_signatures and we are sending second.
7840
7802
if holder_tx_signatures_opt.is_some() {
7841
7803
self.context.channel_state.set_our_tx_signatures_ready();
7842
7804
}
@@ -8093,25 +8055,14 @@ where
8093
8055
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
8094
8056
let mut pending_update_adds = Vec::new();
8095
8057
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
8096
- // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
8097
- // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
8098
- // transaction and waits for us to do it).
8099
- let tx_signatures = self.context.monitor_pending_tx_signatures.take();
8100
- if tx_signatures.is_some() {
8101
- if self.context.channel_state.is_their_tx_signatures_sent() {
8102
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8103
- } else {
8104
- self.context.channel_state.set_our_tx_signatures_ready();
8105
- }
8106
- }
8107
8058
8108
8059
if self.context.channel_state.is_peer_disconnected() {
8109
8060
self.context.monitor_pending_revoke_and_ack = false;
8110
8061
self.context.monitor_pending_commitment_signed = false;
8111
8062
return MonitorRestoreUpdates {
8112
8063
raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
8113
8064
accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8114
- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8065
+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8115
8066
};
8116
8067
}
8117
8068
@@ -8141,7 +8092,7 @@ where
8141
8092
match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
8142
8093
MonitorRestoreUpdates {
8143
8094
raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8144
- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8095
+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8145
8096
}
8146
8097
}
8147
8098
@@ -8416,23 +8367,25 @@ where
8416
8367
log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
8417
8368
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
8418
8369
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
8419
- let commitment_signed =
8420
- if let Ok(update) = self.send_commitment_no_state_update(logger) {
8421
- if self.context.signer_pending_commitment_update {
8422
- log_trace!(
8423
- logger,
8424
- "Commitment update generated: clearing signer_pending_commitment_update"
8425
- );
8426
- self.context.signer_pending_commitment_update = false;
8427
- }
8428
- update
8429
- } else {
8430
- if !self.context.signer_pending_commitment_update {
8431
- log_trace!(logger, "Commitment update awaiting signer: setting signer_pending_commitment_update");
8432
- self.context.signer_pending_commitment_update = true;
8433
- }
8434
- return Err(());
8435
- };
8370
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger) {
8371
+ if self.context.signer_pending_commitment_update {
8372
+ log_trace!(
8373
+ logger,
8374
+ "Commitment update generated: clearing signer_pending_commitment_update"
8375
+ );
8376
+ self.context.signer_pending_commitment_update = false;
8377
+ }
8378
+ update
8379
+ } else {
8380
+ if !self.context.signer_pending_commitment_update {
8381
+ log_trace!(
8382
+ logger,
8383
+ "Commitment update awaiting signer: setting signer_pending_commitment_update"
8384
+ );
8385
+ self.context.signer_pending_commitment_update = true;
8386
+ }
8387
+ return Err(());
8388
+ };
8436
8389
Ok(msgs::CommitmentUpdate {
8437
8390
update_add_htlcs,
8438
8391
update_fulfill_htlcs,
@@ -8618,7 +8571,6 @@ where
8618
8571
update_fee: None,
8619
8572
})
8620
8573
} else { None };
8621
- // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
8622
8574
let tx_signatures = if (
8623
8575
// if it has not received tx_signatures for that funding transaction AND
8624
8576
// if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
@@ -8627,14 +8579,9 @@ where
8627
8579
// else if it has already received tx_signatures for that funding transaction:
8628
8580
// MUST send its tx_signatures for that funding transaction.
8629
8581
) || self.context.channel_state.is_their_tx_signatures_sent() {
8630
- if self.context.channel_state.is_monitor_update_in_progress() {
8631
- // The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
8632
- // if we were up first for signing and had a monitor update in progress, but check again just in case.
8633
- debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
8634
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
8635
- if self.context.monitor_pending_tx_signatures.is_none() {
8636
- self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
8637
- }
8582
+ if session.holder_tx_signatures().is_none() {
8583
+ debug_assert!(self.context.channel_state.is_monitor_update_in_progress());
8584
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
8638
8585
None
8639
8586
} else {
8640
8587
// If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
@@ -13559,7 +13506,6 @@ where
13559
13506
monitor_pending_failures,
13560
13507
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
13561
13508
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13562
- monitor_pending_tx_signatures: None,
13563
13509
13564
13510
signer_pending_revoke_and_ack: false,
13565
13511
signer_pending_commitment_update: false,
0 commit comments