@@ -1127,9 +1127,7 @@ pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
1127
1127
UnfundedOutboundV1(OutboundV1Channel<SP>),
1128
1128
UnfundedInboundV1(InboundV1Channel<SP>),
1129
1129
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
1130
- UnfundedOutboundV2(OutboundV2Channel<SP>),
1131
- #[allow(dead_code)] // TODO(dual_funding): Remove once accepting V2 channels is enabled.
1132
- UnfundedInboundV2(InboundV2Channel<SP>),
1130
+ UnfundedV2(PendingV2Channel<SP>),
1133
1131
Funded(Channel<SP>),
1134
1132
}
1135
1133
@@ -1142,8 +1140,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
1142
1140
ChannelPhase::Funded(chan) => &chan.context,
1143
1141
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
1144
1142
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
1145
- ChannelPhase::UnfundedOutboundV2(chan) => &chan.context,
1146
- ChannelPhase::UnfundedInboundV2(chan) => &chan.context,
1143
+ ChannelPhase::UnfundedV2(chan) => &chan.context,
1147
1144
}
1148
1145
}
1149
1146
@@ -1152,8 +1149,7 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
1152
1149
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
1153
1150
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
1154
1151
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
1155
- ChannelPhase::UnfundedOutboundV2(ref mut chan) => &mut chan.context,
1156
- ChannelPhase::UnfundedInboundV2(ref mut chan) => &mut chan.context,
1152
+ ChannelPhase::UnfundedV2(ref mut chan) => &mut chan.context,
1157
1153
}
1158
1154
}
1159
1155
}
@@ -1684,63 +1680,53 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for Channel<SP> where SP::Ta
1684
1680
}
1685
1681
}
1686
1682
1687
- pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
1688
- fn context(&self) -> &ChannelContext<SP>;
1689
-
1690
- fn context_mut(&mut self) -> &mut ChannelContext<SP>;
1691
-
1692
- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor>;
1693
-
1694
- fn dual_funding_context(&self) -> &DualFundingChannelContext;
1695
-
1696
- fn unfunded_context(&self) -> &UnfundedChannelContext;
1697
-
1698
- fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
1699
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1683
+ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1684
+ pub fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
1685
+ InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
1700
1686
Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_input(msg).map_err(
1701
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
1687
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
1702
1688
None => Err(msgs::TxAbort {
1703
- channel_id: self.context() .channel_id(),
1689
+ channel_id: self.context.channel_id(),
1704
1690
data: b"No interactive transaction negotiation in progress".to_vec()
1705
1691
}),
1706
1692
})
1707
1693
}
1708
1694
1709
- fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
1710
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1695
+ pub fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
1696
+ InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
1711
1697
Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_output(msg).map_err(
1712
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
1698
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
1713
1699
None => Err(msgs::TxAbort {
1714
- channel_id: self.context() .channel_id(),
1700
+ channel_id: self.context.channel_id(),
1715
1701
data: b"No interactive transaction negotiation in progress".to_vec()
1716
1702
}),
1717
1703
})
1718
1704
}
1719
1705
1720
- fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
1721
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1706
+ pub fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
1707
+ InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
1722
1708
Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_input(msg).map_err(
1723
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
1709
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
1724
1710
None => Err(msgs::TxAbort {
1725
- channel_id: self.context() .channel_id(),
1711
+ channel_id: self.context.channel_id(),
1726
1712
data: b"No interactive transaction negotiation in progress".to_vec()
1727
1713
}),
1728
1714
})
1729
1715
}
1730
1716
1731
- fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
1732
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1717
+ pub fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
1718
+ InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
1733
1719
Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_output(msg).map_err(
1734
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
1720
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
1735
1721
None => Err(msgs::TxAbort {
1736
- channel_id: self.context() .channel_id(),
1722
+ channel_id: self.context.channel_id(),
1737
1723
data: b"No interactive transaction negotiation in progress".to_vec()
1738
1724
}),
1739
1725
})
1740
1726
}
1741
1727
1742
- fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
1743
- let tx_constructor = match self.interactive_tx_constructor_mut() {
1728
+ pub fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
1729
+ let tx_constructor = match &mut self.interactive_tx_constructor {
1744
1730
Some(ref mut tx_constructor) => tx_constructor,
1745
1731
None => {
1746
1732
let tx_abort = msgs::TxAbort {
@@ -1759,26 +1745,25 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1759
1745
};
1760
1746
1761
1747
if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
1762
- self.context_mut() .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
1748
+ self.context .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
1763
1749
};
1764
1750
1765
1751
HandleTxCompleteResult(Ok(tx_complete))
1766
1752
}
1767
1753
1768
- fn funding_tx_constructed<L: Deref>(
1754
+ pub fn funding_tx_constructed<L: Deref>(
1769
1755
&mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
1770
1756
) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
1771
1757
where
1772
1758
L::Target: Logger
1773
1759
{
1774
- let our_funding_satoshis = self.dual_funding_context().our_funding_satoshis;
1775
- let transaction_number = self.unfunded_context().transaction_number();
1776
- let context = self.context_mut();
1760
+ let our_funding_satoshis = self.dual_funding_context.our_funding_satoshis;
1761
+ let transaction_number = self.unfunded_context.transaction_number();
1777
1762
1778
1763
let mut output_index = None;
1779
- let expected_spk = context.get_funding_redeemscript().to_p2wsh();
1764
+ let expected_spk = self. context.get_funding_redeemscript().to_p2wsh();
1780
1765
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
1781
- if outp.script_pubkey() == &expected_spk && outp.value() == context.get_value_satoshis() {
1766
+ if outp.script_pubkey() == &expected_spk && outp.value() == self. context.get_value_satoshis() {
1782
1767
if output_index.is_some() {
1783
1768
return Err(ChannelError::Close(
1784
1769
(
@@ -1798,26 +1783,26 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1798
1783
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
1799
1784
)));
1800
1785
};
1801
- context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
1802
- context.holder_signer.as_mut().provide_channel_parameters(&context.channel_transaction_parameters);
1786
+ self. context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
1787
+ self. context.holder_signer.as_mut().provide_channel_parameters(&self. context.channel_transaction_parameters);
1803
1788
1804
- context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
1805
- let commitment_signed = context.get_initial_commitment_signed(logger);
1789
+ self. context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
1790
+ let commitment_signed = self. context.get_initial_commitment_signed(logger);
1806
1791
let commitment_signed = match commitment_signed {
1807
1792
Ok(commitment_signed) => {
1808
- context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
1793
+ self. context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
1809
1794
commitment_signed
1810
1795
},
1811
1796
Err(err) => {
1812
- context.channel_transaction_parameters.funding_outpoint = None;
1797
+ self. context.channel_transaction_parameters.funding_outpoint = None;
1813
1798
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
1814
1799
},
1815
1800
};
1816
1801
1817
1802
let funding_ready_for_sig_event = None;
1818
1803
if signing_session.local_inputs_count() == 0 {
1819
1804
debug_assert_eq!(our_funding_satoshis, 0);
1820
- if signing_session.provide_holder_witnesses(context.channel_id, Vec::new()).is_err() {
1805
+ if signing_session.provide_holder_witnesses(self. context.channel_id, Vec::new()).is_err() {
1821
1806
debug_assert!(
1822
1807
false,
1823
1808
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
@@ -1840,51 +1825,15 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
1840
1825
// </div>
1841
1826
}
1842
1827
1843
- context.channel_state = ChannelState::FundingNegotiated;
1828
+ self. context.channel_state = ChannelState::FundingNegotiated;
1844
1829
1845
1830
// Clear the interactive transaction constructor
1846
- self.interactive_tx_constructor_mut() .take();
1831
+ self.interactive_tx_constructor .take();
1847
1832
1848
1833
Ok((commitment_signed, funding_ready_for_sig_event))
1849
1834
}
1850
1835
}
1851
1836
1852
- impl<SP: Deref> InteractivelyFunded<SP> for OutboundV2Channel<SP> where SP::Target: SignerProvider {
1853
- fn context(&self) -> &ChannelContext<SP> {
1854
- &self.context
1855
- }
1856
- fn context_mut(&mut self) -> &mut ChannelContext<SP> {
1857
- &mut self.context
1858
- }
1859
- fn dual_funding_context(&self) -> &DualFundingChannelContext {
1860
- &self.dual_funding_context
1861
- }
1862
- fn unfunded_context(&self) -> &UnfundedChannelContext {
1863
- &self.unfunded_context
1864
- }
1865
- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
1866
- &mut self.interactive_tx_constructor
1867
- }
1868
- }
1869
-
1870
- impl<SP: Deref> InteractivelyFunded<SP> for InboundV2Channel<SP> where SP::Target: SignerProvider {
1871
- fn context(&self) -> &ChannelContext<SP> {
1872
- &self.context
1873
- }
1874
- fn context_mut(&mut self) -> &mut ChannelContext<SP> {
1875
- &mut self.context
1876
- }
1877
- fn dual_funding_context(&self) -> &DualFundingChannelContext {
1878
- &self.dual_funding_context
1879
- }
1880
- fn unfunded_context(&self) -> &UnfundedChannelContext {
1881
- &self.unfunded_context
1882
- }
1883
- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
1884
- &mut self.interactive_tx_constructor
1885
- }
1886
- }
1887
-
1888
1837
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1889
1838
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
1890
1839
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -8819,24 +8768,24 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8819
8768
}
8820
8769
}
8821
8770
8822
- // A not-yet-funded outbound (from holder) channel using V2 channel establishment.
8823
- pub(super) struct OutboundV2Channel <SP: Deref> where SP::Target: SignerProvider {
8771
+ // A not-yet-funded channel using V2 channel establishment.
8772
+ pub(super) struct PendingV2Channel <SP: Deref> where SP::Target: SignerProvider {
8824
8773
pub context: ChannelContext<SP>,
8825
8774
pub unfunded_context: UnfundedChannelContext,
8826
8775
pub dual_funding_context: DualFundingChannelContext,
8827
8776
/// The current interactive transaction construction session under negotiation.
8828
- interactive_tx_constructor: Option<InteractiveTxConstructor>,
8777
+ pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
8829
8778
}
8830
8779
8831
- impl<SP: Deref> OutboundV2Channel <SP> where SP::Target: SignerProvider {
8780
+ impl<SP: Deref> PendingV2Channel <SP> where SP::Target: SignerProvider {
8832
8781
#[allow(dead_code)] // TODO(dual_funding): Remove once creating V2 channels is enabled.
8833
- pub fn new <ES: Deref, F: Deref, L: Deref>(
8782
+ pub fn new_outbound <ES: Deref, F: Deref, L: Deref>(
8834
8783
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
8835
8784
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
8836
8785
funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>, user_id: u128, config: &UserConfig,
8837
8786
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
8838
8787
logger: L,
8839
- ) -> Result<OutboundV2Channel<SP> , APIError>
8788
+ ) -> Result<Self , APIError>
8840
8789
where ES::Target: EntropySource,
8841
8790
F::Target: FeeEstimator,
8842
8791
L::Target: Logger,
@@ -8908,6 +8857,10 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
8908
8857
}
8909
8858
8910
8859
pub fn get_open_channel_v2(&self, chain_hash: ChainHash) -> msgs::OpenChannelV2 {
8860
+ if !self.context.is_outbound() {
8861
+ debug_assert!(false, "Tried to send open_channel2 for an inbound channel?");
8862
+ }
8863
+
8911
8864
if self.context.have_received_message() {
8912
8865
debug_assert!(false, "Cannot generate an open_channel2 after we've moved forward");
8913
8866
}
@@ -8957,40 +8910,16 @@ impl<SP: Deref> OutboundV2Channel<SP> where SP::Target: SignerProvider {
8957
8910
}
8958
8911
}
8959
8912
8960
- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<Channel<SP>, ChannelError>{
8961
- let holder_commitment_point = self.unfunded_context.holder_commitment_point.ok_or(ChannelError::close(
8962
- format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
8963
- self.context.channel_id())))?;
8964
- let channel = Channel {
8965
- context: self.context,
8966
- interactive_tx_signing_session: Some(signing_session),
8967
- holder_commitment_point,
8968
- };
8969
-
8970
- Ok(channel)
8971
- }
8972
- }
8973
-
8974
- // A not-yet-funded inbound (from counterparty) channel using V2 channel establishment.
8975
- pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
8976
- pub context: ChannelContext<SP>,
8977
- pub unfunded_context: UnfundedChannelContext,
8978
- pub dual_funding_context: DualFundingChannelContext,
8979
- /// The current interactive transaction construction session under negotiation.
8980
- interactive_tx_constructor: Option<InteractiveTxConstructor>,
8981
- }
8982
-
8983
- impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
8984
8913
/// Creates a new dual-funded channel from a remote side's request for one.
8985
8914
/// Assumes chain_hash has already been checked and corresponds with what we expect!
8986
8915
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
8987
- pub fn new <ES: Deref, F: Deref, L: Deref>(
8916
+ pub fn new_inbound <ES: Deref, F: Deref, L: Deref>(
8988
8917
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
8989
8918
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
8990
8919
their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
8991
8920
funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>, total_witness_weight: Weight,
8992
8921
user_id: u128, config: &UserConfig, current_chain_height: u32, logger: &L,
8993
- ) -> Result<InboundV2Channel<SP> , ChannelError>
8922
+ ) -> Result<Self , ChannelError>
8994
8923
where ES::Target: EntropySource,
8995
8924
F::Target: FeeEstimator,
8996
8925
L::Target: Logger,
0 commit comments