@@ -2004,6 +2004,14 @@ macro_rules! convert_chan_phase_err {
20042004 ChannelPhase::UnfundedInboundV1(channel) => {
20052005 convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
20062006 },
2007+ #[cfg(dual_funding)]
2008+ ChannelPhase::UnfundedOutboundV2(channel) => {
2009+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2010+ },
2011+ #[cfg(dual_funding)]
2012+ ChannelPhase::UnfundedInboundV2(channel) => {
2013+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2014+ },
20072015 }
20082016 };
20092017}
@@ -2880,6 +2888,13 @@ where
28802888 // Unfunded channel has no update
28812889 (None, chan_phase.context().get_counterparty_node_id())
28822890 },
2891+ // TODO(dual_funding): Combine this match arm with above.
2892+ #[cfg(dual_funding)]
2893+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
2894+ self.finish_close_channel(chan_phase.context_mut().force_shutdown(false));
2895+ // Unfunded channel has no update
2896+ (None, chan_phase.context().get_counterparty_node_id())
2897+ },
28832898 }
28842899 } else if peer_state.inbound_channel_request_by_id.remove(channel_id).is_some() {
28852900 log_error!(logger, "Force-closing channel {}", &channel_id);
@@ -4887,6 +4902,16 @@ where
48874902 process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
48884903 pending_msg_events, counterparty_node_id)
48894904 },
4905+ #[cfg(dual_funding)]
4906+ ChannelPhase::UnfundedInboundV2(chan) => {
4907+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4908+ pending_msg_events, counterparty_node_id)
4909+ },
4910+ #[cfg(dual_funding)]
4911+ ChannelPhase::UnfundedOutboundV2(chan) => {
4912+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4913+ pending_msg_events, counterparty_node_id)
4914+ },
48904915 }
48914916 });
48924917
@@ -5981,14 +6006,27 @@ where
59816006 num_unfunded_channels += 1;
59826007 }
59836008 },
5984- ChannelPhase::UnfundedInboundV1(chan) => {
5985- if chan.context.minimum_depth().unwrap_or(1) != 0 {
6009+ ChannelPhase::UnfundedInboundV1(_) => {
6010+ if phase.context().minimum_depth().unwrap_or(1) != 0 {
6011+ num_unfunded_channels += 1;
6012+ }
6013+ },
6014+ // TODO(dual_funding): Combine this match arm with above.
6015+ #[cfg(dual_funding)]
6016+ ChannelPhase::UnfundedInboundV2(_) => {
6017+ if phase.context().minimum_depth().unwrap_or(1) != 0 {
59866018 num_unfunded_channels += 1;
59876019 }
59886020 },
59896021 ChannelPhase::UnfundedOutboundV1(_) => {
59906022 // Outbound channels don't contribute to the unfunded count in the DoS context.
59916023 continue;
6024+ },
6025+ // TODO(dual_funding): Combine this match arm with above.
6026+ #[cfg(dual_funding)]
6027+ ChannelPhase::UnfundedOutboundV2(_) => {
6028+ // Outbound channels don't contribute to the unfunded count in the DoS context.
6029+ continue;
59926030 }
59936031 }
59946032 }
@@ -6164,7 +6202,7 @@ where
61646202 },
61656203 }
61666204 },
6167- Some(ChannelPhase::Funded(_)) | Some(ChannelPhase::UnfundedOutboundV1(_) ) => {
6205+ Some(_ ) => {
61686206 return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got an unexpected funding_created message from peer with counterparty_node_id {}", counterparty_node_id), msg.temporary_channel_id));
61696207 },
61706208 None => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.temporary_channel_id))
@@ -6366,6 +6404,15 @@ where
63666404 let mut chan = remove_channel_phase!(self, chan_phase_entry);
63676405 finish_shutdown = Some(chan.context_mut().force_shutdown(false));
63686406 },
6407+ // TODO(dual_funding): Combine this match arm with above.
6408+ #[cfg(dual_funding)]
6409+ ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
6410+ let context = phase.context_mut();
6411+ log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6412+ self.issue_channel_close_events(&context, ClosureReason::CounterpartyCoopClosedUnfundedChannel);
6413+ let mut chan = remove_channel_phase!(self, chan_phase_entry);
6414+ finish_shutdown = Some(chan.context_mut().force_shutdown(false));
6415+ },
63696416 }
63706417 } else {
63716418 return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id))
@@ -8174,6 +8221,9 @@ where
81748221 match phase {
81758222 // Retain unfunded channels.
81768223 ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
8224+ // TODO(dual_funding): Combine this match arm with above.
8225+ #[cfg(dual_funding)]
8226+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
81778227 ChannelPhase::Funded(channel) => {
81788228 let res = f(channel);
81798229 if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8641,6 +8691,14 @@ where
86418691 ChannelPhase::UnfundedInboundV1(chan) => {
86428692 &mut chan.context
86438693 },
8694+ #[cfg(dual_funding)]
8695+ ChannelPhase::UnfundedOutboundV2(chan) => {
8696+ &mut chan.context
8697+ },
8698+ #[cfg(dual_funding)]
8699+ ChannelPhase::UnfundedInboundV2(chan) => {
8700+ &mut chan.context
8701+ },
86448702 };
86458703 // Clean up for removal.
86468704 update_maps_on_chan_removal!(self, &context);
0 commit comments