Skip to content

Commit 2eeb795

Browse files
committed
f - remove NegotiatingChannelView
1 parent d1dfa29 commit 2eeb795

File tree

2 files changed

+46
-91
lines changed

2 files changed

+46
-91
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ use crate::ln::channelmanager::{
5858
BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5959
};
6060
use crate::ln::interactivetxs::{
61-
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteResult,
62-
InteractiveTxConstructor, InteractiveTxConstructorArgs, InteractiveTxMessageSend,
63-
InteractiveTxMessageSendResult, InteractiveTxSigningSession, SharedOwnedInput,
64-
SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
61+
calculate_change_output_value, get_output_weight, AbortReason, InteractiveTxConstructor,
62+
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession,
63+
SharedOwnedInput, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
6564
};
6665
use crate::ln::msgs;
6766
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
@@ -1734,11 +1733,11 @@ where
17341733
}
17351734
}
17361735

1737-
pub fn as_negotiating_channel(&mut self) -> Option<NegotiatingChannelView> {
1736+
pub fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
17381737
match &mut self.phase {
1739-
ChannelPhase::UnfundedV2(chan) => Some(chan.as_negotiating_channel()),
1738+
ChannelPhase::UnfundedV2(chan) => chan.interactive_tx_constructor.as_mut(),
17401739
#[cfg(splicing)]
1741-
ChannelPhase::Funded(chan) => chan.as_renegotiating_channel(),
1740+
ChannelPhase::Funded(chan) => chan.interactive_tx_constructor_mut(),
17421741
_ => None,
17431742
}
17441743
}
@@ -2958,62 +2957,6 @@ where
29582957
}
29592958
}
29602959

2961-
/// A short-lived subset view of a channel, used for V2 funding negotiation or re-negotiation.
2962-
/// Can be produced by:
2963-
/// - [`PendingV2Channel`], at V2 channel open, and
2964-
/// - [`FundedChannel`], when splicing.
2965-
pub(super) struct NegotiatingChannelView<'a>(&'a mut InteractiveTxConstructor);
2966-
2967-
impl<'a> NegotiatingChannelView<'a> {
2968-
pub(super) fn tx_add_input(
2969-
&mut self, msg: &msgs::TxAddInput,
2970-
) -> InteractiveTxMessageSendResult {
2971-
InteractiveTxMessageSendResult(
2972-
self.0
2973-
.handle_tx_add_input(msg)
2974-
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
2975-
)
2976-
}
2977-
2978-
pub(super) fn tx_add_output(
2979-
&mut self, msg: &msgs::TxAddOutput,
2980-
) -> InteractiveTxMessageSendResult {
2981-
InteractiveTxMessageSendResult(
2982-
self.0
2983-
.handle_tx_add_output(msg)
2984-
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
2985-
)
2986-
}
2987-
2988-
pub(super) fn tx_remove_input(
2989-
&mut self, msg: &msgs::TxRemoveInput,
2990-
) -> InteractiveTxMessageSendResult {
2991-
InteractiveTxMessageSendResult(
2992-
self.0
2993-
.handle_tx_remove_input(msg)
2994-
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
2995-
)
2996-
}
2997-
2998-
pub(super) fn tx_remove_output(
2999-
&mut self, msg: &msgs::TxRemoveOutput,
3000-
) -> InteractiveTxMessageSendResult {
3001-
InteractiveTxMessageSendResult(
3002-
self.0
3003-
.handle_tx_remove_output(msg)
3004-
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
3005-
)
3006-
}
3007-
3008-
pub(super) fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
3009-
HandleTxCompleteResult(
3010-
self.0
3011-
.handle_tx_complete(msg)
3012-
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
3013-
)
3014-
}
3015-
}
3016-
30172960
impl<SP: Deref> ChannelContext<SP>
30182961
where
30192962
SP::Target: SignerProvider,
@@ -6174,17 +6117,16 @@ where
61746117
self.context.force_shutdown(&self.funding, closure_reason)
61756118
}
61766119

6177-
/// If we are in splicing/refunding, return a short-lived [`NegotiatingChannelView`].
61786120
#[cfg(splicing)]
6179-
fn as_renegotiating_channel(&mut self) -> Option<NegotiatingChannelView> {
6121+
fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
61806122
self.pending_splice
61816123
.as_mut()
61826124
.and_then(|pending_splice| pending_splice.funding_negotiation.as_mut())
61836125
.and_then(|funding_negotiation| {
61846126
if let FundingNegotiation::Pending(_, interactive_tx_constructor) =
61856127
funding_negotiation
61866128
{
6187-
Some(NegotiatingChannelView(interactive_tx_constructor))
6129+
Some(interactive_tx_constructor)
61886130
} else {
61896131
None
61906132
}
@@ -12610,11 +12552,6 @@ where
1261012552
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
1261112553
self.generate_accept_channel_v2_message()
1261212554
}
12613-
12614-
/// Return a short-lived [`NegotiatingChannelView`].
12615-
fn as_negotiating_channel(&mut self) -> NegotiatingChannelView {
12616-
NegotiatingChannelView(self.interactive_tx_constructor.as_mut().expect("TODO"))
12617-
}
1261812555
}
1261912556

1262012557
// Unfunded channel utilities

lightning/src/ln/channelmanager.rs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use crate::ln::channel::{
6666
};
6767
use crate::ln::channel_state::ChannelDetails;
6868
use crate::ln::inbound_payment;
69+
use crate::ln::interactivetxs::{HandleTxCompleteResult, InteractiveTxMessageSendResult};
6970
use crate::ln::msgs;
7071
use crate::ln::msgs::{
7172
BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, DecodeError, LightningError,
@@ -8938,10 +8939,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89388939
) -> Result<(), MsgHandleErrInternal> {
89398940
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
89408941
Some(
8941-
channel
8942-
.as_negotiating_channel()?
8943-
.tx_add_input(msg)
8944-
.into_msg_send_event(counterparty_node_id),
8942+
InteractiveTxMessageSendResult(
8943+
channel
8944+
.interactive_tx_constructor_mut()?
8945+
.handle_tx_add_input(msg)
8946+
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
8947+
)
8948+
.into_msg_send_event(counterparty_node_id),
89458949
)
89468950
})
89478951
}
@@ -8951,10 +8955,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89518955
) -> Result<(), MsgHandleErrInternal> {
89528956
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
89538957
Some(
8954-
channel
8955-
.as_negotiating_channel()?
8956-
.tx_add_output(msg)
8957-
.into_msg_send_event(counterparty_node_id),
8958+
InteractiveTxMessageSendResult(
8959+
channel
8960+
.interactive_tx_constructor_mut()?
8961+
.handle_tx_add_output(msg)
8962+
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
8963+
)
8964+
.into_msg_send_event(counterparty_node_id),
89588965
)
89598966
})
89608967
}
@@ -8964,10 +8971,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89648971
) -> Result<(), MsgHandleErrInternal> {
89658972
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
89668973
Some(
8967-
channel
8968-
.as_negotiating_channel()?
8969-
.tx_remove_input(msg)
8970-
.into_msg_send_event(counterparty_node_id),
8974+
InteractiveTxMessageSendResult(
8975+
channel
8976+
.interactive_tx_constructor_mut()?
8977+
.handle_tx_remove_input(msg)
8978+
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
8979+
)
8980+
.into_msg_send_event(counterparty_node_id),
89718981
)
89728982
})
89738983
}
@@ -8977,10 +8987,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89778987
) -> Result<(), MsgHandleErrInternal> {
89788988
self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel<SP>| {
89798989
Some(
8980-
channel
8981-
.as_negotiating_channel()?
8982-
.tx_remove_output(msg)
8983-
.into_msg_send_event(counterparty_node_id),
8990+
InteractiveTxMessageSendResult(
8991+
channel
8992+
.interactive_tx_constructor_mut()?
8993+
.handle_tx_remove_output(msg)
8994+
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
8995+
)
8996+
.into_msg_send_event(counterparty_node_id),
89848997
)
89858998
})
89868999
}
@@ -8999,10 +9012,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89999012
let peer_state = &mut *peer_state_lock;
90009013
match peer_state.channel_by_id.entry(msg.channel_id) {
90019014
hash_map::Entry::Occupied(mut chan_entry) => {
9002-
let (msg_send_event_opt, ready_to_sign) = match chan_entry.get_mut().as_negotiating_channel() {
9003-
Some(mut negotiating_channel) => negotiating_channel
9004-
.tx_complete(msg)
9005-
.into_msg_send_event(counterparty_node_id),
9015+
let (msg_send_event_opt, ready_to_sign) = match chan_entry.get_mut().interactive_tx_constructor_mut() {
9016+
Some(interactive_tx_constructor) => {
9017+
HandleTxCompleteResult(
9018+
interactive_tx_constructor
9019+
.handle_tx_complete(msg)
9020+
.map_err(|reason| reason.into_tx_abort_msg(msg.channel_id)),
9021+
)
9022+
.into_msg_send_event(counterparty_node_id)
9023+
},
90069024
None => {
90079025
let err = ChannelError::Warn("Received unexpected tx_complete message".to_owned());
90089026
return Err(MsgHandleErrInternal::from_chan_no_close(err, msg.channel_id))

0 commit comments

Comments
 (0)