@@ -14,7 +14,7 @@ use bitcoin::transaction::{Transaction, TxIn, TxOut};
1414use bitcoin::sighash::EcdsaSighashType;
1515use bitcoin::consensus::encode;
1616use bitcoin::absolute::LockTime;
17- use bitcoin::Weight;
17+ use bitcoin::{ Weight, Witness} ;
1818
1919use bitcoin::hashes::Hash;
2020use bitcoin::hashes::sha256::Hash as Sha256;
@@ -2630,7 +2630,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
26302630 },
26312631 };
26322632
2633- let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
2633+ let funding_ready_for_sig_event_opt = if signing_session.local_inputs_count() == 0 {
26342634 debug_assert_eq!(our_funding_satoshis, 0);
26352635 if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
26362636 debug_assert!(
@@ -2644,28 +2644,12 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
26442644 }
26452645 None
26462646 } else {
2647- // TODO(dual_funding): Send event for signing if we've contributed funds.
2648- // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
2649- // inputs/signatures.
2650- // Also warn the user that we don't do anything to prevent the counterparty from
2651- // providing non-standard witnesses which will prevent the funding transaction from
2652- // confirming. This warning must appear in doc comments wherever the user is contributing
2653- // funds, whether they are initiator or acceptor.
2654- //
2655- // The following warning can be used when the APIs allowing contributing inputs become available:
2656- // <div class="warning">
2657- // WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
2658- // will prevent the funding transaction from being relayed on the bitcoin network and hence being
2659- // confirmed.
2660- // </div>
2661- debug_assert!(
2662- false,
2663- "We don't support users providing inputs but somehow we had more than zero inputs",
2664- );
2665- return Err(ChannelError::Close((
2666- "V2 channel rejected due to sender error".into(),
2667- ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2668- )));
2647+ Some(Event::FundingTransactionReadyForSigning {
2648+ channel_id: self.context.channel_id,
2649+ counterparty_node_id: self.context.counterparty_node_id,
2650+ user_channel_id: self.context.user_id,
2651+ unsigned_transaction: signing_session.unsigned_tx().build_unsigned_tx(),
2652+ })
26692653 };
26702654
26712655 let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
@@ -2676,7 +2660,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
26762660 self.interactive_tx_constructor.take();
26772661 self.interactive_tx_signing_session = Some(signing_session);
26782662
2679- Ok((commitment_signed, funding_ready_for_sig_event ))
2663+ Ok((commitment_signed, funding_ready_for_sig_event_opt ))
26802664 }
26812665}
26822666
@@ -6565,6 +6549,36 @@ impl<SP: Deref> FundedChannel<SP> where
65656549 }
65666550 }
65676551
6552+ fn verify_interactive_tx_signatures(&mut self, _witnesses: &Vec<Witness>) {
6553+ if let Some(ref mut _signing_session) = self.interactive_tx_signing_session {
6554+ // Check that sighash_all was used:
6555+ // TODO(dual_funding): Check sig for sighash
6556+ }
6557+ }
6558+
6559+ pub fn funding_transaction_signed<L: Deref>(&mut self, witnesses: Vec<Witness>, logger: &L) -> Result<Option<msgs::TxSignatures>, APIError>
6560+ where L::Target: Logger
6561+ {
6562+ self.verify_interactive_tx_signatures(&witnesses);
6563+ if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6564+ let logger = WithChannelContext::from(logger, &self.context, None);
6565+ if let Some(holder_tx_signatures) = signing_session
6566+ .provide_holder_witnesses(self.context.channel_id, witnesses)
6567+ .map_err(|err| APIError::APIMisuseError { err })?
6568+ {
6569+ if self.is_awaiting_initial_mon_persist() {
6570+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6571+ self.context.monitor_pending_tx_signatures = Some(holder_tx_signatures);
6572+ return Ok(None);
6573+ }
6574+ return Ok(Some(holder_tx_signatures));
6575+ } else { return Ok(None) }
6576+ } else {
6577+ return Err(APIError::APIMisuseError {
6578+ err: format!("Channel with id {} not expecting funding signatures", self.context.channel_id)});
6579+ }
6580+ }
6581+
65686582 pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
65696583 where L::Target: Logger
65706584 {
0 commit comments