@@ -2765,20 +2765,25 @@ where
27652765 /// default destination address is used.
27662766 /// If error occurs, it is caused by our side, not the counterparty.
27672767 #[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled
2768- #[rustfmt::skip]
27692768 fn begin_interactive_funding_tx_construction<ES: Deref>(
27702769 &mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
2771- change_destination_opt: Option<ScriptBuf>,
2770+ is_initiator: bool, change_destination_opt: Option<ScriptBuf>,
2771+ prev_funding_input: Option<(TxIn, TransactionU16LenLimited)>,
27722772 ) -> Result<Option<InteractiveTxMessageSend>, AbortReason>
2773- where ES::Target: EntropySource
2773+ where
2774+ ES::Target: EntropySource,
27742775 {
27752776 debug_assert!(matches!(self.context.channel_state, ChannelState::NegotiatingFunding(_)));
27762777 debug_assert!(self.interactive_tx_constructor.is_none());
27772778
27782779 let mut funding_inputs = Vec::new();
27792780 mem::swap(&mut self.funding_negotiation_context.our_funding_inputs, &mut funding_inputs);
27802781
2781- // TODO(splicing): Add prev funding tx as input, must be provided as a parameter
2782+ if is_initiator {
2783+ if let Some(prev_funding_input) = prev_funding_input {
2784+ funding_inputs.push(prev_funding_input);
2785+ }
2786+ }
27822787
27832788 // Add output for funding tx
27842789 // Note: For the error case when the inputs are insufficient, it will be handled after
@@ -2791,12 +2796,11 @@ where
27912796 script_pubkey: self.funding.get_funding_redeemscript().to_p2wsh(),
27922797 };
27932798
2794- if self.funding.is_outbound() {
2795- funding_outputs.push(
2796- OutputOwned::Shared(SharedOwnedOutput::new(
2797- shared_funding_output, self.funding_negotiation_context.our_funding_satoshis,
2798- ))
2799- );
2799+ if is_initiator {
2800+ funding_outputs.push(OutputOwned::Shared(SharedOwnedOutput::new(
2801+ shared_funding_output,
2802+ self.funding_negotiation_context.our_funding_satoshis,
2803+ )));
28002804 } else {
28012805 let TxOut { value, script_pubkey } = shared_funding_output;
28022806 expected_remote_shared_funding_output = Some((script_pubkey, value.to_sat()));
@@ -2806,22 +2810,26 @@ where
28062810 let change_script = if let Some(script) = change_destination_opt {
28072811 script
28082812 } else {
2809- signer_provider.get_destination_script(self.context.channel_keys_id)
2813+ signer_provider
2814+ .get_destination_script(self.context.channel_keys_id)
28102815 .map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
28112816 };
28122817 let change_value_opt = calculate_change_output_value(
2813- self.funding.is_outbound(), self.funding_negotiation_context.our_funding_satoshis,
2814- &funding_inputs, &funding_outputs,
2818+ is_initiator,
2819+ self.funding_negotiation_context.our_funding_satoshis,
2820+ &funding_inputs,
2821+ &funding_outputs,
28152822 self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
28162823 change_script.minimal_non_dust().to_sat(),
28172824 )?;
28182825 if let Some(change_value) = change_value_opt {
2819- let mut change_output = TxOut {
2820- value: Amount::from_sat(change_value),
2821- script_pubkey: change_script,
2822- };
2826+ let mut change_output =
2827+ TxOut { value: Amount::from_sat(change_value), script_pubkey: change_script };
28232828 let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
2824- let change_output_fee = fee_for_weight(self.funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
2829+ let change_output_fee = fee_for_weight(
2830+ self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2831+ change_output_weight,
2832+ );
28252833 let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
28262834 // Check dust limit again
28272835 if change_value_decreased_with_fee > self.context.holder_dust_limit_satoshis {
@@ -2835,8 +2843,10 @@ where
28352843 holder_node_id,
28362844 counterparty_node_id: self.context.counterparty_node_id,
28372845 channel_id: self.context.channel_id(),
2838- feerate_sat_per_kw: self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2839- is_initiator: self.funding.is_outbound(),
2846+ feerate_sat_per_kw: self
2847+ .funding_negotiation_context
2848+ .funding_feerate_sat_per_1000_weight,
2849+ is_initiator,
28402850 funding_tx_locktime: self.funding_negotiation_context.funding_tx_locktime,
28412851 inputs_to_contribute: funding_inputs,
28422852 outputs_to_contribute: funding_outputs,
0 commit comments