Skip to content

Commit 270c5ab

Browse files
committed
Remove InteractivelyFunded trait
Now that InboundV2Channel and OutboundV2Channel have been combined into a PendingV2Channel, the InteractivelyFunded trait is no longer needed.
1 parent 91ff6c1 commit 270c5ab

File tree

2 files changed

+38
-67
lines changed

2 files changed

+38
-67
lines changed

lightning/src/ln/channel.rs

+35-64
Original file line numberDiff line numberDiff line change
@@ -1684,63 +1684,53 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for Channel<SP> where SP::Ta
16841684
}
16851685
}
16861686

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() {
1687+
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1688+
pub fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
1689+
InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
17001690
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())),
1691+
|reason| reason.into_tx_abort_msg(self.context.channel_id())),
17021692
None => Err(msgs::TxAbort {
1703-
channel_id: self.context().channel_id(),
1693+
channel_id: self.context.channel_id(),
17041694
data: b"No interactive transaction negotiation in progress".to_vec()
17051695
}),
17061696
})
17071697
}
17081698

1709-
fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
1710-
InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1699+
pub fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
1700+
InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
17111701
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())),
1702+
|reason| reason.into_tx_abort_msg(self.context.channel_id())),
17131703
None => Err(msgs::TxAbort {
1714-
channel_id: self.context().channel_id(),
1704+
channel_id: self.context.channel_id(),
17151705
data: b"No interactive transaction negotiation in progress".to_vec()
17161706
}),
17171707
})
17181708
}
17191709

1720-
fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
1721-
InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1710+
pub fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
1711+
InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
17221712
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())),
1713+
|reason| reason.into_tx_abort_msg(self.context.channel_id())),
17241714
None => Err(msgs::TxAbort {
1725-
channel_id: self.context().channel_id(),
1715+
channel_id: self.context.channel_id(),
17261716
data: b"No interactive transaction negotiation in progress".to_vec()
17271717
}),
17281718
})
17291719
}
17301720

1731-
fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
1732-
InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
1721+
pub fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
1722+
InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
17331723
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())),
1724+
|reason| reason.into_tx_abort_msg(self.context.channel_id())),
17351725
None => Err(msgs::TxAbort {
1736-
channel_id: self.context().channel_id(),
1726+
channel_id: self.context.channel_id(),
17371727
data: b"No interactive transaction negotiation in progress".to_vec()
17381728
}),
17391729
})
17401730
}
17411731

1742-
fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
1743-
let tx_constructor = match self.interactive_tx_constructor_mut() {
1732+
pub fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
1733+
let tx_constructor = match &mut self.interactive_tx_constructor {
17441734
Some(ref mut tx_constructor) => tx_constructor,
17451735
None => {
17461736
let tx_abort = msgs::TxAbort {
@@ -1759,26 +1749,25 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17591749
};
17601750

17611751
if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
1762-
self.context_mut().next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
1752+
self.context.next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
17631753
};
17641754

17651755
HandleTxCompleteResult(Ok(tx_complete))
17661756
}
17671757

1768-
fn funding_tx_constructed<L: Deref>(
1758+
pub fn funding_tx_constructed<L: Deref>(
17691759
&mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
17701760
) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
17711761
where
17721762
L::Target: Logger
17731763
{
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();
1764+
let our_funding_satoshis = self.dual_funding_context.our_funding_satoshis;
1765+
let transaction_number = self.unfunded_context.transaction_number();
17771766

17781767
let mut output_index = None;
1779-
let expected_spk = context.get_funding_redeemscript().to_p2wsh();
1768+
let expected_spk = self.context.get_funding_redeemscript().to_p2wsh();
17801769
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
1781-
if outp.script_pubkey() == &expected_spk && outp.value() == context.get_value_satoshis() {
1770+
if outp.script_pubkey() == &expected_spk && outp.value() == self.context.get_value_satoshis() {
17821771
if output_index.is_some() {
17831772
return Err(ChannelError::Close(
17841773
(
@@ -1798,26 +1787,26 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17981787
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
17991788
)));
18001789
};
1801-
context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
1802-
context.holder_signer.as_mut().provide_channel_parameters(&context.channel_transaction_parameters);
1790+
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
1791+
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
18031792

1804-
context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
1805-
let commitment_signed = context.get_initial_commitment_signed(logger);
1793+
self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
1794+
let commitment_signed = self.context.get_initial_commitment_signed(logger);
18061795
let commitment_signed = match commitment_signed {
18071796
Ok(commitment_signed) => {
1808-
context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
1797+
self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
18091798
commitment_signed
18101799
},
18111800
Err(err) => {
1812-
context.channel_transaction_parameters.funding_outpoint = None;
1801+
self.context.channel_transaction_parameters.funding_outpoint = None;
18131802
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
18141803
},
18151804
};
18161805

18171806
let funding_ready_for_sig_event = None;
18181807
if signing_session.local_inputs_count() == 0 {
18191808
debug_assert_eq!(our_funding_satoshis, 0);
1820-
if signing_session.provide_holder_witnesses(context.channel_id, Vec::new()).is_err() {
1809+
if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
18211810
debug_assert!(
18221811
false,
18231812
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
@@ -1840,33 +1829,15 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
18401829
// </div>
18411830
}
18421831

1843-
context.channel_state = ChannelState::FundingNegotiated;
1832+
self.context.channel_state = ChannelState::FundingNegotiated;
18441833

18451834
// Clear the interactive transaction constructor
1846-
self.interactive_tx_constructor_mut().take();
1835+
self.interactive_tx_constructor.take();
18471836

18481837
Ok((commitment_signed, funding_ready_for_sig_event))
18491838
}
18501839
}
18511840

1852-
impl<SP: Deref> InteractivelyFunded<SP> for PendingV2Channel<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-
18701841
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
18711842
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
18721843
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -8810,7 +8781,7 @@ pub(super) struct PendingV2Channel<SP: Deref> where SP::Target: SignerProvider {
88108781
pub unfunded_context: UnfundedChannelContext,
88118782
pub dual_funding_context: DualFundingChannelContext,
88128783
/// The current interactive transaction construction session under negotiation.
8813-
interactive_tx_constructor: Option<InteractiveTxConstructor>,
8784+
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
88148785
}
88158786

88168787
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {

lightning/src/ln/channelmanager.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
4848
use crate::ln::inbound_payment;
4949
use crate::ln::types::ChannelId;
5050
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51-
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InteractivelyFunded as _};
51+
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
5252
#[cfg(any(dual_funding, splicing))]
5353
use crate::ln::channel::PendingV2Channel;
5454
use crate::ln::channel_state::ChannelDetails;
@@ -8435,8 +8435,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84358435
hash_map::Entry::Occupied(mut chan_phase_entry) => {
84368436
let channel_phase = chan_phase_entry.get_mut();
84378437
let tx_constructor = match channel_phase {
8438-
ChannelPhase::UnfundedInboundV2(chan) => chan.interactive_tx_constructor_mut(),
8439-
ChannelPhase::UnfundedOutboundV2(chan) => chan.interactive_tx_constructor_mut(),
8438+
ChannelPhase::UnfundedInboundV2(chan) => &mut chan.interactive_tx_constructor,
8439+
ChannelPhase::UnfundedOutboundV2(chan) => &mut chan.interactive_tx_constructor,
84408440
ChannelPhase::Funded(_) => {
84418441
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
84428442
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively

0 commit comments

Comments
 (0)