@@ -1786,9 +1786,8 @@ where
17861786 ChannelPhase::UnfundedV2(chan) => {
17871787 let mut signing_session =
17881788 chan.interactive_tx_constructor.take().expect("TODO").into_signing_session();
1789- let result = funding_tx_constructed(
1789+ let result = chan.context. funding_tx_constructed(
17901790 &mut chan.funding,
1791- &mut chan.context,
17921791 &mut signing_session,
17931792 false,
17941793 chan.unfunded_context.transaction_number(),
@@ -1811,9 +1810,8 @@ where
18111810 {
18121811 let mut signing_session =
18131812 interactive_tx_constructor.into_signing_session();
1814- let result = funding_tx_constructed(
1813+ let result = chan.context. funding_tx_constructed(
18151814 &mut funding,
1816- &mut chan.context,
18171815 &mut signing_session,
18181816 true,
18191817 chan.holder_commitment_point.transaction_number(),
@@ -2966,99 +2964,6 @@ where
29662964/// - [`FundedChannel`], when splicing.
29672965pub(super) struct NegotiatingChannelView<'a>(&'a mut InteractiveTxConstructor);
29682966
2969- #[rustfmt::skip]
2970- fn funding_tx_constructed<SP:Deref, L: Deref>(
2971- funding: &mut FundingScope, context: &mut ChannelContext<SP>,
2972- signing_session: &mut InteractiveTxSigningSession, is_splice: bool,
2973- holder_commitment_transaction_number: u64, logger: &L
2974- ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2975- where
2976- SP::Target: SignerProvider,
2977- L::Target: Logger
2978- {
2979- let mut output_index = None;
2980- let expected_spk = funding.get_funding_redeemscript().to_p2wsh();
2981- for (idx, outp) in signing_session.unsigned_tx().outputs().enumerate() {
2982- if outp.script_pubkey() == &expected_spk && outp.value() == funding.get_value_satoshis() {
2983- if output_index.is_some() {
2984- let msg = "Multiple outputs matched the expected script and value";
2985- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
2986- return Err(ChannelError::Close((msg.to_owned(), reason)));
2987- }
2988- output_index = Some(idx as u16);
2989- }
2990- }
2991- let outpoint = if let Some(output_index) = output_index {
2992- OutPoint { txid: signing_session.unsigned_tx().compute_txid(), index: output_index }
2993- } else {
2994- let msg = "No output matched the funding script_pubkey";
2995- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
2996- return Err(ChannelError::Close((msg.to_owned(), reason)));
2997- };
2998- funding
2999- .channel_transaction_parameters.funding_outpoint = Some(outpoint);
3000-
3001- if is_splice {
3002- let message = "TODO Forced error, incomplete implementation".to_owned();
3003- // TODO(splicing) Forced error, as the use case is not complete
3004- return Err(ChannelError::Close((
3005- message.clone(),
3006- ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false), message }
3007- )));
3008- }
3009-
3010- context.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
3011- let commitment_signed = context.get_initial_commitment_signed(&funding, logger);
3012- let commitment_signed = match commitment_signed {
3013- Ok(commitment_signed) => commitment_signed,
3014- Err(e) => {
3015- funding.channel_transaction_parameters.funding_outpoint = None;
3016- return Err(e)
3017- },
3018- };
3019-
3020- let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
3021- if signing_session.provide_holder_witnesses(context.channel_id, Vec::new()).is_err() {
3022- debug_assert!(
3023- false,
3024- "Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
3025- );
3026- let msg = "V2 channel rejected due to sender error";
3027- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
3028- return Err(ChannelError::Close((msg.to_owned(), reason)));
3029- }
3030- None
3031- } else {
3032- // TODO(dual_funding): Send event for signing if we've contributed funds.
3033- // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
3034- // inputs/signatures.
3035- // Also warn the user that we don't do anything to prevent the counterparty from
3036- // providing non-standard witnesses which will prevent the funding transaction from
3037- // confirming. This warning must appear in doc comments wherever the user is contributing
3038- // funds, whether they are initiator or acceptor.
3039- //
3040- // The following warning can be used when the APIs allowing contributing inputs become available:
3041- // <div class="warning">
3042- // WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
3043- // will prevent the funding transaction from being relayed on the bitcoin network and hence being
3044- // confirmed.
3045- // </div>
3046- debug_assert!(
3047- false,
3048- "We don't support users providing inputs but somehow we had more than zero inputs",
3049- );
3050- let msg = "V2 channel rejected due to sender error";
3051- let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
3052- return Err(ChannelError::Close((msg.to_owned(), reason)));
3053- };
3054-
3055- let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
3056- channel_state.set_interactive_signing();
3057- context.channel_state = channel_state;
3058-
3059- Ok((commitment_signed, funding_ready_for_sig_event))
3060- }
3061-
30622967impl<'a> NegotiatingChannelView<'a> {
30632968 pub(super) fn tx_add_input(
30642969 &mut self, msg: &msgs::TxAddInput,
@@ -5575,6 +5480,97 @@ where
55755480 Ok(())
55765481 }
55775482
5483+ #[rustfmt::skip]
5484+ fn funding_tx_constructed<L: Deref>(
5485+ &mut self, funding: &mut FundingScope, signing_session: &mut InteractiveTxSigningSession,
5486+ is_splice: bool, holder_commitment_transaction_number: u64, logger: &L
5487+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
5488+ where
5489+ L::Target: Logger
5490+ {
5491+ let mut output_index = None;
5492+ let expected_spk = funding.get_funding_redeemscript().to_p2wsh();
5493+ for (idx, outp) in signing_session.unsigned_tx().outputs().enumerate() {
5494+ if outp.script_pubkey() == &expected_spk && outp.value() == funding.get_value_satoshis() {
5495+ if output_index.is_some() {
5496+ let msg = "Multiple outputs matched the expected script and value";
5497+ let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5498+ return Err(ChannelError::Close((msg.to_owned(), reason)));
5499+ }
5500+ output_index = Some(idx as u16);
5501+ }
5502+ }
5503+ let outpoint = if let Some(output_index) = output_index {
5504+ OutPoint { txid: signing_session.unsigned_tx().compute_txid(), index: output_index }
5505+ } else {
5506+ let msg = "No output matched the funding script_pubkey";
5507+ let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5508+ return Err(ChannelError::Close((msg.to_owned(), reason)));
5509+ };
5510+ funding
5511+ .channel_transaction_parameters.funding_outpoint = Some(outpoint);
5512+
5513+ if is_splice {
5514+ let message = "TODO Forced error, incomplete implementation".to_owned();
5515+ // TODO(splicing) Forced error, as the use case is not complete
5516+ return Err(ChannelError::Close((
5517+ message.clone(),
5518+ ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false), message }
5519+ )));
5520+ }
5521+
5522+ self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
5523+ let commitment_signed = self.get_initial_commitment_signed(&funding, logger);
5524+ let commitment_signed = match commitment_signed {
5525+ Ok(commitment_signed) => commitment_signed,
5526+ Err(e) => {
5527+ funding.channel_transaction_parameters.funding_outpoint = None;
5528+ return Err(e)
5529+ },
5530+ };
5531+
5532+ let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
5533+ if signing_session.provide_holder_witnesses(self.channel_id, Vec::new()).is_err() {
5534+ debug_assert!(
5535+ false,
5536+ "Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
5537+ );
5538+ let msg = "V2 channel rejected due to sender error";
5539+ let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5540+ return Err(ChannelError::Close((msg.to_owned(), reason)));
5541+ }
5542+ None
5543+ } else {
5544+ // TODO(dual_funding): Send event for signing if we've contributed funds.
5545+ // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
5546+ // inputs/signatures.
5547+ // Also warn the user that we don't do anything to prevent the counterparty from
5548+ // providing non-standard witnesses which will prevent the funding transaction from
5549+ // confirming. This warning must appear in doc comments wherever the user is contributing
5550+ // funds, whether they are initiator or acceptor.
5551+ //
5552+ // The following warning can be used when the APIs allowing contributing inputs become available:
5553+ // <div class="warning">
5554+ // WARNING: LDK makes no attempt to prevent the counterparty from using non-standard inputs which
5555+ // will prevent the funding transaction from being relayed on the bitcoin network and hence being
5556+ // confirmed.
5557+ // </div>
5558+ debug_assert!(
5559+ false,
5560+ "We don't support users providing inputs but somehow we had more than zero inputs",
5561+ );
5562+ let msg = "V2 channel rejected due to sender error";
5563+ let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5564+ return Err(ChannelError::Close((msg.to_owned(), reason)));
5565+ };
5566+
5567+ let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5568+ channel_state.set_interactive_signing();
5569+ self.channel_state = channel_state;
5570+
5571+ Ok((commitment_signed, funding_ready_for_sig_event))
5572+ }
5573+
55785574 /// Asserts that the commitment tx numbers have not advanced from their initial number.
55795575 #[rustfmt::skip]
55805576 fn assert_no_commitment_advancement(&self, holder_commitment_transaction_number: u64, msg_name: &str) {
0 commit comments