@@ -2092,6 +2092,14 @@ macro_rules! convert_chan_phase_err {
2092
2092
ChannelPhase::UnfundedInboundV1(channel) => {
2093
2093
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2094
2094
},
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
+ },
2095
2103
}
2096
2104
};
2097
2105
}
@@ -2958,6 +2966,13 @@ where
2958
2966
// Unfunded channel has no update
2959
2967
(None, chan_phase.context().get_counterparty_node_id())
2960
2968
},
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
+ },
2961
2976
}
2962
2977
} else if peer_state.inbound_channel_request_by_id.remove(channel_id).is_some() {
2963
2978
log_error!(logger, "Force-closing channel {}", &channel_id);
@@ -5035,6 +5050,16 @@ where
5035
5050
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5036
5051
pending_msg_events, counterparty_node_id)
5037
5052
},
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
+ },
5038
5063
}
5039
5064
});
5040
5065
@@ -6182,9 +6207,25 @@ where
6182
6207
num_unfunded_channels += 1;
6183
6208
}
6184
6209
},
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
+ },
6185
6220
ChannelPhase::UnfundedOutboundV1(_) => {
6186
6221
// Outbound channels don't contribute to the unfunded count in the DoS context.
6187
6222
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;
6188
6229
}
6189
6230
}
6190
6231
}
@@ -6607,6 +6648,14 @@ where
6607
6648
let mut chan = remove_channel_phase!(self, chan_phase_entry);
6608
6649
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6609
6650
},
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
+ },
6610
6659
}
6611
6660
} else {
6612
6661
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
8474
8523
match phase {
8475
8524
// Retain unfunded channels.
8476
8525
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,
8477
8529
ChannelPhase::Funded(channel) => {
8478
8530
let res = f(channel);
8479
8531
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8943,6 +8995,14 @@ where
8943
8995
ChannelPhase::UnfundedInboundV1(chan) => {
8944
8996
&mut chan.context
8945
8997
},
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
+ },
8946
9006
};
8947
9007
// Clean up for removal.
8948
9008
update_maps_on_chan_removal!(self, &context);
@@ -9095,12 +9155,30 @@ where
9095
9155
});
9096
9156
}
9097
9157
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
+
9098
9167
ChannelPhase::UnfundedInboundV1(_) => {
9099
9168
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9100
9169
// they are not persisted and won't be recovered after a crash.
9101
9170
// Therefore, they shouldn't exist at this point.
9102
9171
debug_assert!(false);
9103
9172
}
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
+ },
9104
9182
}
9105
9183
}
9106
9184
}
0 commit comments