@@ -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
@@ -6595,6 +6579,36 @@ impl<SP: Deref> FundedChannel<SP> where
65956579 }
65966580 }
65976581
6582+ fn verify_interactive_tx_signatures(&mut self, _witnesses: &Vec<Witness>) {
6583+ if let Some(ref mut _signing_session) = self.interactive_tx_signing_session {
6584+ // Check that sighash_all was used:
6585+ // TODO(dual_funding): Check sig for sighash
6586+ }
6587+ }
6588+
6589+ pub fn funding_transaction_signed<L: Deref>(&mut self, witnesses: Vec<Witness>, logger: &L) -> Result<Option<msgs::TxSignatures>, APIError>
6590+ where L::Target: Logger
6591+ {
6592+ self.verify_interactive_tx_signatures(&witnesses);
6593+ if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6594+ let logger = WithChannelContext::from(logger, &self.context, None);
6595+ if let Some(holder_tx_signatures) = signing_session
6596+ .provide_holder_witnesses(self.context.channel_id, witnesses)
6597+ .map_err(|err| APIError::APIMisuseError { err })?
6598+ {
6599+ if self.is_awaiting_initial_mon_persist() {
6600+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6601+ self.context.monitor_pending_tx_signatures = Some(holder_tx_signatures);
6602+ return Ok(None);
6603+ }
6604+ return Ok(Some(holder_tx_signatures));
6605+ } else { return Ok(None) }
6606+ } else {
6607+ return Err(APIError::APIMisuseError {
6608+ err: format!("Channel with id {} not expecting funding signatures", self.context.channel_id)});
6609+ }
6610+ }
6611+
65986612 pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
65996613 where L::Target: Logger
66006614 {
0 commit comments