@@ -16,7 +16,7 @@ use bitcoin::transaction::{Transaction, TxIn, TxOut};
16
16
use bitcoin::sighash::EcdsaSighashType;
17
17
use bitcoin::consensus::encode;
18
18
use bitcoin::absolute::LockTime;
19
- use bitcoin::Weight;
19
+ use bitcoin::{ Weight, Witness} ;
20
20
21
21
use bitcoin::hashes::Hash;
22
22
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -2637,7 +2637,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2637
2637
},
2638
2638
};
2639
2639
2640
- let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
2640
+ let funding_ready_for_sig_event_opt = if signing_session.local_inputs_count() == 0 {
2641
2641
debug_assert_eq!(our_funding_satoshis, 0);
2642
2642
if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2643
2643
debug_assert!(
@@ -2651,28 +2651,12 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2651
2651
}
2652
2652
None
2653
2653
} else {
2654
- // TODO(dual_funding): Send event for signing if we've contributed funds.
2655
- // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
2656
- // inputs/signatures.
2657
- // Also warn the user that we don't do anything to prevent the counterparty from
2658
- // providing non-standard witnesses which will prevent the funding transaction from
2659
- // confirming. This warning must appear in doc comments wherever the user is contributing
2660
- // funds, whether they are initiator or acceptor.
2661
- //
2662
- // The following warning can be used when the APIs allowing contributing inputs become available:
2663
- // <div class="warning">
2664
- // WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
2665
- // will prevent the funding transaction from being relayed on the bitcoin network and hence being
2666
- // confirmed.
2667
- // </div>
2668
- debug_assert!(
2669
- false,
2670
- "We don't support users providing inputs but somehow we had more than zero inputs",
2671
- );
2672
- return Err(ChannelError::Close((
2673
- "V2 channel rejected due to sender error".into(),
2674
- ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2675
- )));
2654
+ Some(Event::FundingTransactionReadyForSigning {
2655
+ channel_id: self.context.channel_id,
2656
+ counterparty_node_id: self.context.counterparty_node_id,
2657
+ user_channel_id: self.context.user_id,
2658
+ unsigned_transaction: signing_session.unsigned_tx().build_unsigned_tx(),
2659
+ })
2676
2660
};
2677
2661
2678
2662
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
@@ -2683,7 +2667,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2683
2667
self.interactive_tx_constructor.take();
2684
2668
self.interactive_tx_signing_session = Some(signing_session);
2685
2669
2686
- Ok((commitment_signed, funding_ready_for_sig_event ))
2670
+ Ok((commitment_signed, funding_ready_for_sig_event_opt ))
2687
2671
}
2688
2672
}
2689
2673
@@ -6651,6 +6635,36 @@ impl<SP: Deref> FundedChannel<SP> where
6651
6635
}
6652
6636
}
6653
6637
6638
+ fn verify_interactive_tx_signatures(&mut self, _witnesses: &Vec<Witness>) {
6639
+ if let Some(ref mut _signing_session) = self.interactive_tx_signing_session {
6640
+ // Check that sighash_all was used:
6641
+ // TODO(dual_funding): Check sig for sighash
6642
+ }
6643
+ }
6644
+
6645
+ pub fn funding_transaction_signed<L: Deref>(&mut self, witnesses: Vec<Witness>, logger: &L) -> Result<Option<msgs::TxSignatures>, APIError>
6646
+ where L::Target: Logger
6647
+ {
6648
+ self.verify_interactive_tx_signatures(&witnesses);
6649
+ if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
6650
+ let logger = WithChannelContext::from(logger, &self.context, None);
6651
+ if let Some(holder_tx_signatures) = signing_session
6652
+ .provide_holder_witnesses(self.context.channel_id, witnesses)
6653
+ .map_err(|err| APIError::APIMisuseError { err })?
6654
+ {
6655
+ if self.is_awaiting_initial_mon_persist() {
6656
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6657
+ self.context.monitor_pending_tx_signatures = Some(holder_tx_signatures);
6658
+ return Ok(None);
6659
+ }
6660
+ return Ok(Some(holder_tx_signatures));
6661
+ } else { return Ok(None) }
6662
+ } else {
6663
+ return Err(APIError::APIMisuseError {
6664
+ err: format!("Channel with id {} not expecting funding signatures", self.context.channel_id)});
6665
+ }
6666
+ }
6667
+
6654
6668
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
6655
6669
where L::Target: Logger
6656
6670
{
0 commit comments