@@ -14,7 +14,7 @@ use bitcoin::transaction::{Transaction, TxIn, TxOut};
14
14
use bitcoin::sighash::EcdsaSighashType;
15
15
use bitcoin::consensus::encode;
16
16
use bitcoin::absolute::LockTime;
17
- use bitcoin::Weight;
17
+ use bitcoin::{ Weight, Witness} ;
18
18
19
19
use bitcoin::hashes::Hash;
20
20
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -2630,7 +2630,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2630
2630
},
2631
2631
};
2632
2632
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 {
2634
2634
debug_assert_eq!(our_funding_satoshis, 0);
2635
2635
if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2636
2636
debug_assert!(
@@ -2644,28 +2644,12 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2644
2644
}
2645
2645
None
2646
2646
} 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
+ })
2669
2653
};
2670
2654
2671
2655
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
@@ -2676,7 +2660,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2676
2660
self.interactive_tx_constructor.take();
2677
2661
self.interactive_tx_signing_session = Some(signing_session);
2678
2662
2679
- Ok((commitment_signed, funding_ready_for_sig_event ))
2663
+ Ok((commitment_signed, funding_ready_for_sig_event_opt ))
2680
2664
}
2681
2665
}
2682
2666
@@ -6565,6 +6549,36 @@ impl<SP: Deref> FundedChannel<SP> where
6565
6549
}
6566
6550
}
6567
6551
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
+
6568
6582
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
6569
6583
where L::Target: Logger
6570
6584
{
0 commit comments