@@ -2092,6 +2092,14 @@ macro_rules! convert_chan_phase_err {
20922092 ChannelPhase::UnfundedInboundV1(channel) => {
20932093 convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
20942094 },
2095+ #[cfg(dual_funding)]
2096+ ChannelPhase::UnfundedOutboundV2(channel) => {
2097+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2098+ },
2099+ #[cfg(dual_funding)]
2100+ ChannelPhase::UnfundedInboundV2(channel) => {
2101+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2102+ },
20952103 }
20962104 };
20972105}
@@ -2958,6 +2966,13 @@ where
29582966 // Unfunded channel has no update
29592967 (None, chan_phase.context().get_counterparty_node_id())
29602968 },
2969+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
2970+ #[cfg(dual_funding)]
2971+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
2972+ self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason));
2973+ // Unfunded channel has no update
2974+ (None, chan_phase.context().get_counterparty_node_id())
2975+ },
29612976 }
29622977 } else if peer_state.inbound_channel_request_by_id.remove(channel_id).is_some() {
29632978 log_error!(logger, "Force-closing channel {}", &channel_id);
@@ -5035,6 +5050,16 @@ where
50355050 process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
50365051 pending_msg_events, counterparty_node_id)
50375052 },
5053+ #[cfg(dual_funding)]
5054+ ChannelPhase::UnfundedInboundV2(chan) => {
5055+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5056+ pending_msg_events, counterparty_node_id)
5057+ },
5058+ #[cfg(dual_funding)]
5059+ ChannelPhase::UnfundedOutboundV2(chan) => {
5060+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5061+ pending_msg_events, counterparty_node_id)
5062+ },
50385063 }
50395064 });
50405065
@@ -6182,9 +6207,25 @@ where
61826207 num_unfunded_channels += 1;
61836208 }
61846209 },
6210+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6211+ #[cfg(dual_funding)]
6212+ ChannelPhase::UnfundedInboundV2(chan) => {
6213+ // Only inbound V2 channels that are not 0conf and that we do not contribute to will be
6214+ // included in the unfunded count.
6215+ if chan.context.minimum_depth().unwrap_or(1) != 0 &&
6216+ chan.dual_funding_context.our_funding_satoshis == 0 {
6217+ num_unfunded_channels += 1;
6218+ }
6219+ },
61856220 ChannelPhase::UnfundedOutboundV1(_) => {
61866221 // Outbound channels don't contribute to the unfunded count in the DoS context.
61876222 continue;
6223+ },
6224+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6225+ #[cfg(dual_funding)]
6226+ ChannelPhase::UnfundedOutboundV2(_) => {
6227+ // Outbound channels don't contribute to the unfunded count in the DoS context.
6228+ continue;
61886229 }
61896230 }
61906231 }
@@ -6607,6 +6648,14 @@ where
66076648 let mut chan = remove_channel_phase!(self, chan_phase_entry);
66086649 finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
66096650 },
6651+ // TODO(dual_funding): Combine this match arm with above.
6652+ #[cfg(dual_funding)]
6653+ ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
6654+ let context = phase.context_mut();
6655+ log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6656+ let mut chan = remove_channel_phase!(self, chan_phase_entry);
6657+ finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6658+ },
66106659 }
66116660 } else {
66126661 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))
@@ -8474,6 +8523,9 @@ where
84748523 match phase {
84758524 // Retain unfunded channels.
84768525 ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
8526+ // TODO(dual_funding): Combine this match arm with above.
8527+ #[cfg(dual_funding)]
8528+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
84778529 ChannelPhase::Funded(channel) => {
84788530 let res = f(channel);
84798531 if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8943,6 +8995,14 @@ where
89438995 ChannelPhase::UnfundedInboundV1(chan) => {
89448996 &mut chan.context
89458997 },
8998+ #[cfg(dual_funding)]
8999+ ChannelPhase::UnfundedOutboundV2(chan) => {
9000+ &mut chan.context
9001+ },
9002+ #[cfg(dual_funding)]
9003+ ChannelPhase::UnfundedInboundV2(chan) => {
9004+ &mut chan.context
9005+ },
89469006 };
89479007 // Clean up for removal.
89489008 update_maps_on_chan_removal!(self, &context);
@@ -9095,12 +9155,30 @@ where
90959155 });
90969156 }
90979157
9158+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9159+ #[cfg(dual_funding)]
9160+ ChannelPhase::UnfundedOutboundV2(chan) => {
9161+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
9162+ node_id: chan.context.get_counterparty_node_id(),
9163+ msg: chan.get_open_channel_v2(self.chain_hash),
9164+ });
9165+ },
9166+
90989167 ChannelPhase::UnfundedInboundV1(_) => {
90999168 // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
91009169 // they are not persisted and won't be recovered after a crash.
91019170 // Therefore, they shouldn't exist at this point.
91029171 debug_assert!(false);
91039172 }
9173+
9174+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9175+ #[cfg(dual_funding)]
9176+ ChannelPhase::UnfundedInboundV2(channel) => {
9177+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9178+ // they are not persisted and won't be recovered after a crash.
9179+ // Therefore, they shouldn't exist at this point.
9180+ debug_assert!(false);
9181+ },
91049182 }
91059183 }
91069184 }
0 commit comments