@@ -1766,7 +1766,7 @@ where
17661766
17671767 pub fn funding_tx_constructed<L: Deref>(
17681768 &mut self, signing_session: InteractiveTxSigningSession, logger: &L,
1769- ) -> Result<( msgs::CommitmentSigned, Option<Transaction>) , ChannelError>
1769+ ) -> Result<msgs::CommitmentSigned, ChannelError>
17701770 where
17711771 L::Target: Logger,
17721772 {
@@ -1788,7 +1788,7 @@ where
17881788 #[rustfmt::skip]
17891789 pub fn commitment_signed<L: Deref>(
17901790 &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1791- ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1791+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>, Option<Transaction> ), ChannelError>
17921792 where
17931793 L::Target: Logger
17941794 {
@@ -1815,7 +1815,7 @@ where
18151815 pending_splice: None,
18161816 };
18171817 let res = funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger)
1818- .map(|monitor| (Some(monitor), None))
1818+ .map(|( monitor, funding_tx_opt) | (Some(monitor), None, funding_tx_opt ))
18191819 // TODO: Change to `inspect_err` when MSRV is high enough.
18201820 .map_err(|err| {
18211821 // We always expect a `ChannelError` close.
@@ -1842,15 +1842,15 @@ where
18421842 let res = if has_negotiated_pending_splice && !session_received_commitment_signed {
18431843 funded_channel
18441844 .splice_initial_commitment_signed(msg, logger)
1845- .map(|monitor_update_opt| (None, monitor_update_opt))
1845+ .map(|monitor_update_opt| (None, monitor_update_opt, None ))
18461846 } else {
18471847 funded_channel.commitment_signed(msg, logger)
1848- .map(|monitor_update_opt| (None, monitor_update_opt))
1848+ .map(|monitor_update_opt| (None, monitor_update_opt, None ))
18491849 };
18501850
18511851 #[cfg(not(splicing))]
18521852 let res = funded_channel.commitment_signed(msg, logger)
1853- .map(|monitor_update_opt| (None, monitor_update_opt));
1853+ .map(|monitor_update_opt| (None, monitor_update_opt, None ));
18541854
18551855 self.phase = ChannelPhase::Funded(funded_channel);
18561856 res
@@ -2928,7 +2928,7 @@ where
29282928 #[rustfmt::skip]
29292929 pub fn funding_tx_constructed<L: Deref>(
29302930 &mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2931- ) -> Result<( msgs::CommitmentSigned, Option<Transaction>) , ChannelError>
2931+ ) -> Result<msgs::CommitmentSigned, ChannelError>
29322932 where
29332933 L::Target: Logger
29342934 {
@@ -2970,7 +2970,8 @@ where
29702970 },
29712971 };
29722972
2973- let funding_tx_opt = if signing_session.local_inputs_count() == 0 {
2973+ // Check that we have the expected number of local inputs
2974+ if signing_session.local_inputs_count() == 0 {
29742975 debug_assert_eq!(our_funding_satoshis, 0);
29752976 if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
29762977 debug_assert!(
@@ -2982,10 +2983,7 @@ where
29822983 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
29832984 )));
29842985 }
2985- None
2986- } else {
2987- Some(signing_session.unsigned_tx().build_unsigned_tx())
2988- };
2986+ }
29892987
29902988 let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
29912989 channel_state.set_interactive_signing();
@@ -2995,7 +2993,7 @@ where
29952993 self.interactive_tx_constructor.take();
29962994 self.interactive_tx_signing_session = Some(signing_session);
29972995
2998- Ok(( commitment_signed, funding_tx_opt) )
2996+ Ok(commitment_signed)
29992997 }
30002998}
30012999
@@ -6632,7 +6630,7 @@ where
66326630 #[rustfmt::skip]
66336631 pub fn commitment_signed_initial_v2<L: Deref>(
66346632 &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
6635- ) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, ChannelError>
6633+ ) -> Result<( ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, Option<Transaction>) , ChannelError>
66366634 where L::Target: Logger
66376635 {
66386636 if !self.context.channel_state.is_interactive_signing()
@@ -6663,8 +6661,11 @@ where
66636661 // so they'll be sent as soon as that's done.
66646662 self.context.monitor_pending_tx_signatures = Some(tx_signatures);
66656663 }
6664+ // Only build the unsigned transaction for signing if there are any holder inputs to actually sign
6665+ let funding_tx_opt = self.interactive_tx_signing_session.as_ref().and_then(|session|
6666+ session.local_inputs_count().gt(&0).then_some(session.unsigned_tx().build_unsigned_tx()));
66666667
6667- Ok(channel_monitor)
6668+ Ok(( channel_monitor, funding_tx_opt) )
66686669 }
66696670
66706671 /// Handles an incoming `commitment_signed` message for the first commitment transaction of the
0 commit comments