@@ -1682,6 +1682,10 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1682
1682
1683
1683
fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor>;
1684
1684
1685
+ fn interactive_tx_signing_session(&self) -> &Option<InteractiveTxSigningSession>;
1686
+
1687
+ fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession>;
1688
+
1685
1689
fn dual_funding_context(&self) -> &DualFundingChannelContext;
1686
1690
1687
1691
fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
@@ -1755,17 +1759,25 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1755
1759
}
1756
1760
1757
1761
fn funding_tx_constructed<L: Deref>(
1758
- &mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
1762
+ &mut self, logger: &L
1759
1763
) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
1760
1764
where
1761
1765
L::Target: Logger
1762
1766
{
1763
1767
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
+ };
1765
1776
1777
+ let context = self.context_mut();
1766
1778
let mut output_index = None;
1767
1779
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() {
1769
1781
if outp.script_pubkey() == &expected_spk && outp.value() == context.get_value_satoshis() {
1770
1782
if output_index.is_some() {
1771
1783
return Err(ChannelError::Close(
@@ -1778,7 +1790,7 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1778
1790
}
1779
1791
}
1780
1792
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 }
1782
1794
} else {
1783
1795
return Err(ChannelError::Close(
1784
1796
(
@@ -1792,15 +1804,19 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1792
1804
let commitment_signed = context.get_initial_commitment_signed(logger);
1793
1805
let commitment_signed = match commitment_signed {
1794
1806
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());
1796
1808
commitment_signed
1797
1809
},
1798
1810
Err(err) => return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }))),
1799
1811
};
1800
1812
1801
1813
let funding_ready_for_sig_event = None;
1802
1814
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());
1804
1820
} else {
1805
1821
// TODO(dual_funding): Send event for signing if we've contributed funds.
1806
1822
// 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
1818
1834
// </div>
1819
1835
}
1820
1836
1821
- context .channel_state = ChannelState::FundingNegotiated;
1837
+ self.context_mut() .channel_state = ChannelState::FundingNegotiated;
1822
1838
1823
1839
// Clear the interactive transaction constructor
1824
1840
self.interactive_tx_constructor_mut().take();
@@ -1840,6 +1856,12 @@ impl<SP: Deref> InteractivelyFunded<SP> for OutboundV2Channel<SP> where SP::Targ
1840
1856
fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
1841
1857
&mut self.interactive_tx_constructor
1842
1858
}
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
+ }
1843
1865
}
1844
1866
1845
1867
impl<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
1855
1877
fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
1856
1878
&mut self.interactive_tx_constructor
1857
1879
}
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
+ }
1858
1886
}
1859
1887
1860
1888
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
@@ -4028,9 +4056,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4028
4056
}
4029
4057
}
4030
4058
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>
4034
4060
where
4035
4061
SP::Target: SignerProvider,
4036
4062
L::Target: Logger
@@ -8719,6 +8745,7 @@ pub(super) struct OutboundV2Channel<SP: Deref> where SP::Target: SignerProvider
8719
8745
pub dual_funding_context: DualFundingChannelContext,
8720
8746
/// The current interactive transaction construction session under negotiation.
8721
8747
interactive_tx_constructor: Option<InteractiveTxConstructor>,
8748
+ signing_session: Option<InteractiveTxSigningSession>,
8722
8749
}
8723
8750
8724
8751
impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
@@ -8778,6 +8805,7 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
8778
8805
our_funding_inputs: funding_inputs,
8779
8806
},
8780
8807
interactive_tx_constructor: None,
8808
+ signing_session: None,
8781
8809
};
8782
8810
Ok(chan)
8783
8811
}
@@ -8845,10 +8873,11 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
8845
8873
}
8846
8874
}
8847
8875
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());
8849
8878
let channel = Channel {
8850
8879
context: self.context,
8851
- interactive_tx_signing_session: Some( signing_session) ,
8880
+ interactive_tx_signing_session: self. signing_session,
8852
8881
};
8853
8882
8854
8883
Ok(channel)
@@ -8862,6 +8891,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
8862
8891
pub dual_funding_context: DualFundingChannelContext,
8863
8892
/// The current interactive transaction construction session under negotiation.
8864
8893
interactive_tx_constructor: Option<InteractiveTxConstructor>,
8894
+ signing_session: Option<InteractiveTxSigningSession>,
8865
8895
}
8866
8896
8867
8897
impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
@@ -8964,6 +8994,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
8964
8994
dual_funding_context,
8965
8995
interactive_tx_constructor,
8966
8996
unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
8997
+ signing_session: None,
8967
8998
})
8968
8999
}
8969
9000
@@ -9039,10 +9070,11 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
9039
9070
self.generate_accept_channel_v2_message()
9040
9071
}
9041
9072
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());
9043
9075
let channel = Channel {
9044
9076
context: self.context,
9045
- interactive_tx_signing_session: Some( signing_session) ,
9077
+ interactive_tx_signing_session: self. signing_session,
9046
9078
};
9047
9079
9048
9080
Ok(channel)
0 commit comments