@@ -1682,6 +1682,10 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
16821682
16831683 fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor>;
16841684
1685+ fn interactive_tx_signing_session(&self) -> &Option<InteractiveTxSigningSession>;
1686+
1687+ fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession>;
1688+
16851689 fn dual_funding_context(&self) -> &DualFundingChannelContext;
16861690
16871691 fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
@@ -1755,17 +1759,25 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17551759 }
17561760
17571761 fn funding_tx_constructed<L: Deref>(
1758- &mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
1762+ &mut self, logger: &L
17591763 ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
17601764 where
17611765 L::Target: Logger
17621766 {
17631767 let our_funding_satoshis = self.dual_funding_context().our_funding_satoshis;
1764- let context = self.context_mut();
1768+ let unsigned_tx = match self.interactive_tx_signing_session() {
1769+ Some(signing_session) => signing_session.unsigned_tx.clone(),
1770+ None => return Err(ChannelError::Close(
1771+ (
1772+ "No signing session available for commitment signing".to_owned(),
1773+ ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
1774+ ))),
1775+ };
17651776
1777+ let context = self.context_mut();
17661778 let mut output_index = None;
17671779 let expected_spk = context.get_funding_redeemscript().to_p2wsh();
1768- for (idx, outp) in signing_session. unsigned_tx.outputs().enumerate() {
1780+ for (idx, outp) in unsigned_tx.outputs().enumerate() {
17691781 if outp.script_pubkey() == &expected_spk && outp.value() == context.get_value_satoshis() {
17701782 if output_index.is_some() {
17711783 return Err(ChannelError::Close(
@@ -1778,7 +1790,7 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17781790 }
17791791 }
17801792 let outpoint = if let Some(output_index) = output_index {
1781- OutPoint { txid: signing_session. unsigned_tx.txid(), index: output_index }
1793+ OutPoint { txid: unsigned_tx.txid(), index: output_index }
17821794 } else {
17831795 return Err(ChannelError::Close(
17841796 (
@@ -1792,15 +1804,19 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17921804 let commitment_signed = context.get_initial_commitment_signed(logger);
17931805 let commitment_signed = match commitment_signed {
17941806 Ok(commitment_signed) => {
1795- context.funding_transaction = Some(signing_session. unsigned_tx.clone() .into_unsigned_tx());
1807+ context.funding_transaction = Some(unsigned_tx.into_unsigned_tx());
17961808 commitment_signed
17971809 },
17981810 Err(err) => return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }))),
17991811 };
18001812
18011813 let funding_ready_for_sig_event = None;
18021814 if our_funding_satoshis == 0 {
1803- signing_session.provide_holder_witnesses(context.channel_id, Vec::new());
1815+ let channel_id = context.channel_id;
1816+ self.interactive_tx_signing_session_mut()
1817+ .as_mut()
1818+ .expect("interactive_tx_signing_session_mut should be set")
1819+ .provide_holder_witnesses(channel_id, Vec::new());
18041820 } else {
18051821 // TODO(dual_funding): Send event for signing if we've contributed funds.
18061822 // Inform the user that SIGHASH_ALL must be used for all signatures when contributing
@@ -1818,7 +1834,7 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
18181834 // </div>
18191835 }
18201836
1821- context .channel_state = ChannelState::FundingNegotiated;
1837+ self.context_mut() .channel_state = ChannelState::FundingNegotiated;
18221838
18231839 // Clear the interactive transaction constructor
18241840 self.interactive_tx_constructor_mut().take();
@@ -1840,6 +1856,12 @@ impl<SP: Deref> InteractivelyFunded<SP> for OutboundV2Channel<SP> where SP::Targ
18401856 fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
18411857 &mut self.interactive_tx_constructor
18421858 }
1859+ fn interactive_tx_signing_session(&self) -> &Option<InteractiveTxSigningSession> {
1860+ &self.signing_session
1861+ }
1862+ fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession> {
1863+ &mut self.signing_session
1864+ }
18431865}
18441866
18451867impl<SP: Deref> InteractivelyFunded<SP> for InboundV2Channel<SP> where SP::Target: SignerProvider {
@@ -1855,6 +1877,12 @@ impl<SP: Deref> InteractivelyFunded<SP> for InboundV2Channel<SP> where SP::Targe
18551877 fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
18561878 &mut self.interactive_tx_constructor
18571879 }
1880+ fn interactive_tx_signing_session(&self) -> &Option<InteractiveTxSigningSession> {
1881+ &self.signing_session
1882+ }
1883+ fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession> {
1884+ &mut self.signing_session
1885+ }
18581886}
18591887
18601888impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
@@ -4028,9 +4056,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40284056 }
40294057 }
40304058
4031- fn get_initial_commitment_signed<L: Deref>(
4032- &mut self, logger: &L
4033- ) -> Result<msgs::CommitmentSigned, ChannelError>
4059+ fn get_initial_commitment_signed<L: Deref>(&mut self, logger: &L) -> Result<msgs::CommitmentSigned, ChannelError>
40344060 where
40354061 SP::Target: SignerProvider,
40364062 L::Target: Logger
@@ -8719,6 +8745,7 @@ pub(super) struct OutboundV2Channel<SP: Deref> where SP::Target: SignerProvider
87198745 pub dual_funding_context: DualFundingChannelContext,
87208746 /// The current interactive transaction construction session under negotiation.
87218747 interactive_tx_constructor: Option<InteractiveTxConstructor>,
8748+ signing_session: Option<InteractiveTxSigningSession>,
87228749}
87238750
87248751impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
@@ -8778,6 +8805,7 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
87788805 our_funding_inputs: funding_inputs,
87798806 },
87808807 interactive_tx_constructor: None,
8808+ signing_session: None,
87818809 };
87828810 Ok(chan)
87838811 }
@@ -8845,10 +8873,11 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
88458873 }
88468874 }
88478875
8848- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<Channel<SP>, ChannelError>{
8876+ pub fn into_channel(self) -> Result<Channel<SP>, ChannelError>{
8877+ debug_assert!(self.signing_session.is_some());
88498878 let channel = Channel {
88508879 context: self.context,
8851- interactive_tx_signing_session: Some( signing_session) ,
8880+ interactive_tx_signing_session: self. signing_session,
88528881 };
88538882
88548883 Ok(channel)
@@ -8862,6 +8891,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
88628891 pub dual_funding_context: DualFundingChannelContext,
88638892 /// The current interactive transaction construction session under negotiation.
88648893 interactive_tx_constructor: Option<InteractiveTxConstructor>,
8894+ signing_session: Option<InteractiveTxSigningSession>,
88658895}
88668896
88678897impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
@@ -8964,6 +8994,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
89648994 dual_funding_context,
89658995 interactive_tx_constructor,
89668996 unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
8997+ signing_session: None,
89678998 })
89688999 }
89699000
@@ -9039,10 +9070,11 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
90399070 self.generate_accept_channel_v2_message()
90409071 }
90419072
9042- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<Channel<SP>, ChannelError>{
9073+ pub fn into_channel(self) -> Result<Channel<SP>, ChannelError>{
9074+ debug_assert!(self.signing_session.is_some());
90439075 let channel = Channel {
90449076 context: self.context,
9045- interactive_tx_signing_session: Some( signing_session) ,
9077+ interactive_tx_signing_session: self. signing_session,
90469078 };
90479079
90489080 Ok(channel)
0 commit comments