@@ -14,7 +14,7 @@ use bitcoin::constants::ChainHash;
1414use bitcoin::script::{Builder, Script, ScriptBuf, WScriptHash};
1515use bitcoin::sighash::EcdsaSighashType;
1616use bitcoin::transaction::{Transaction, TxIn, TxOut};
17- use bitcoin::Weight;
17+ use bitcoin::{ Weight, Witness} ;
1818
1919use bitcoin::hash_types::{BlockHash, Txid};
2020use bitcoin::hashes::sha256::Hash as Sha256;
@@ -36,7 +36,7 @@ use crate::chain::channelmonitor::{
3636use crate::chain::transaction::{OutPoint, TransactionData};
3737use crate::chain::BestBlock;
3838use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
39- use crate::events::{ ClosureReason, Event} ;
39+ use crate::events::ClosureReason;
4040use crate::ln::chan_utils;
4141#[cfg(splicing)]
4242use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
@@ -1761,7 +1761,7 @@ where
17611761
17621762 pub fn funding_tx_constructed<L: Deref>(
17631763 &mut self, signing_session: InteractiveTxSigningSession, logger: &L,
1764- ) -> Result<( msgs::CommitmentSigned, Option<Event>) , ChannelError>
1764+ ) -> Result<msgs::CommitmentSigned, ChannelError>
17651765 where
17661766 L::Target: Logger,
17671767 {
@@ -2310,7 +2310,6 @@ where
23102310 monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
23112311 monitor_pending_finalized_fulfills: Vec<(HTLCSource, Option<AttributionData>)>,
23122312 monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2313- monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
23142313
23152314 /// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
23162315 /// we should retry at some point in the future when the signer indicates it may have a
@@ -2910,12 +2909,11 @@ where
29102909
29112910 #[rustfmt::skip]
29122911 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>
29152914 where
29162915 L::Target: Logger
29172916 {
2918- let our_funding_satoshis = self.dual_funding_context.our_funding_satoshis;
29192917 let transaction_number = self.unfunded_context.transaction_number();
29202918
29212919 let mut output_index = None;
@@ -2949,42 +2947,6 @@ where
29492947 },
29502948 };
29512949
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-
29882950 let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
29892951 channel_state.set_interactive_signing();
29902952 self.context.channel_state = channel_state;
@@ -2993,7 +2955,7 @@ where
29932955 self.interactive_tx_constructor.take();
29942956 self.interactive_tx_signing_session = Some(signing_session);
29952957
2996- Ok(( commitment_signed, funding_ready_for_sig_event) )
2958+ Ok(commitment_signed)
29972959 }
29982960}
29992961
@@ -3275,7 +3237,6 @@ where
32753237 monitor_pending_failures: Vec::new(),
32763238 monitor_pending_finalized_fulfills: Vec::new(),
32773239 monitor_pending_update_adds: Vec::new(),
3278- monitor_pending_tx_signatures: None,
32793240
32803241 signer_pending_revoke_and_ack: false,
32813242 signer_pending_commitment_update: false,
@@ -3514,7 +3475,6 @@ where
35143475 monitor_pending_failures: Vec::new(),
35153476 monitor_pending_finalized_fulfills: Vec::new(),
35163477 monitor_pending_update_adds: Vec::new(),
3517- monitor_pending_tx_signatures: None,
35183478
35193479 signer_pending_revoke_and_ack: false,
35203480 signer_pending_commitment_update: false,
@@ -6767,13 +6727,7 @@ where
67676727
67686728 self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
67696729
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());
67776731
67786732 Ok(channel_monitor)
67796733 }
@@ -6856,13 +6810,12 @@ where
68566810 channel_id: Some(self.context.channel_id()),
68576811 };
68586812
6859- let tx_signatures = self
6813+ let _ = self
68606814 .interactive_tx_signing_session
68616815 .as_mut()
68626816 .expect("Signing session must exist for negotiated pending splice")
68636817 .received_commitment_signed();
68646818 self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6865- self.context.monitor_pending_tx_signatures = tx_signatures;
68666819
68676820 Ok(self.push_ret_blockable_mon_update(monitor_update))
68686821 }
@@ -7772,6 +7725,24 @@ where
77727725 }
77737726 }
77747727
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+
77757746 #[rustfmt::skip]
77767747 pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
77777748 where L::Target: Logger
@@ -7829,11 +7800,10 @@ where
78297800 }
78307801
78317802 // 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 .
7803+ // case checks if there is a monitor persist in progress when we need to respond with our
7804+ // `tx_signatures` .
78347805 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;
7806+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
78377807 return Ok((None, None));
78387808 }
78397809
@@ -8093,25 +8063,14 @@ where
80938063 mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
80948064 let mut pending_update_adds = Vec::new();
80958065 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- }
81078066
81088067 if self.context.channel_state.is_peer_disconnected() {
81098068 self.context.monitor_pending_revoke_and_ack = false;
81108069 self.context.monitor_pending_commitment_signed = false;
81118070 return MonitorRestoreUpdates {
81128071 raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
81138072 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8114- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8073+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
81158074 };
81168075 }
81178076
@@ -8141,7 +8100,7 @@ where
81418100 match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
81428101 MonitorRestoreUpdates {
81438102 raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8144- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8103+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
81458104 }
81468105 }
81478106
@@ -8416,23 +8375,25 @@ where
84168375 log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
84178376 &self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
84188377 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- };
8378+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger) {
8379+ if self.context.signer_pending_commitment_update {
8380+ log_trace!(
8381+ logger,
8382+ "Commitment update generated: clearing signer_pending_commitment_update"
8383+ );
8384+ self.context.signer_pending_commitment_update = false;
8385+ }
8386+ update
8387+ } else {
8388+ if !self.context.signer_pending_commitment_update {
8389+ log_trace!(
8390+ logger,
8391+ "Commitment update awaiting signer: setting signer_pending_commitment_update"
8392+ );
8393+ self.context.signer_pending_commitment_update = true;
8394+ }
8395+ return Err(());
8396+ };
84368397 Ok(msgs::CommitmentUpdate {
84378398 update_add_htlcs,
84388399 update_fulfill_htlcs,
@@ -8618,7 +8579,6 @@ where
86188579 update_fee: None,
86198580 })
86208581 } else { None };
8621- // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
86228582 let tx_signatures = if (
86238583 // if it has not received tx_signatures for that funding transaction AND
86248584 // if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
@@ -8627,14 +8587,9 @@ where
86278587 // else if it has already received tx_signatures for that funding transaction:
86288588 // MUST send its tx_signatures for that funding transaction.
86298589 ) || 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- }
8590+ if session.holder_tx_signatures().is_none() {
8591+ debug_assert!(self.context.channel_state.is_monitor_update_in_progress());
8592+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
86388593 None
86398594 } else {
86408595 // If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
@@ -13559,7 +13514,6 @@ where
1355913514 monitor_pending_failures,
1356013515 monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
1356113516 monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13562- monitor_pending_tx_signatures: None,
1356313517
1356413518 signer_pending_revoke_and_ack: false,
1356513519 signer_pending_commitment_update: false,
0 commit comments