@@ -905,7 +905,14 @@ impl <SP: Deref> PeerState<SP> where SP::Target: SignerProvider {
905
905
return false
906
906
}
907
907
!self.channel_by_id.iter().any(|(_, phase)|
908
- matches!(phase, ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_))
908
+ match phase {
909
+ ChannelPhase::Funded(_) | ChannelPhase::UnfundedOutboundV1(_) => true,
910
+ ChannelPhase::UnfundedInboundV1(_) => false,
911
+ #[cfg(dual_funding)]
912
+ ChannelPhase::UnfundedOutboundV2(_) => true,
913
+ #[cfg(dual_funding)]
914
+ ChannelPhase::UnfundedInboundV2(_) => false,
915
+ }
909
916
)
910
917
&& self.monitor_update_blocked_actions.is_empty()
911
918
&& self.in_flight_monitor_updates.is_empty()
@@ -2092,6 +2099,14 @@ macro_rules! convert_chan_phase_err {
2092
2099
ChannelPhase::UnfundedInboundV1(channel) => {
2093
2100
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2094
2101
},
2102
+ #[cfg(dual_funding)]
2103
+ ChannelPhase::UnfundedOutboundV2(channel) => {
2104
+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2105
+ },
2106
+ #[cfg(dual_funding)]
2107
+ ChannelPhase::UnfundedInboundV2(channel) => {
2108
+ convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2109
+ },
2095
2110
}
2096
2111
};
2097
2112
}
@@ -2958,6 +2973,13 @@ where
2958
2973
// Unfunded channel has no update
2959
2974
(None, chan_phase.context().get_counterparty_node_id())
2960
2975
},
2976
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
2977
+ #[cfg(dual_funding)]
2978
+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
2979
+ self.finish_close_channel(chan_phase.context_mut().force_shutdown(false, closure_reason));
2980
+ // Unfunded channel has no update
2981
+ (None, chan_phase.context().get_counterparty_node_id())
2982
+ },
2961
2983
}
2962
2984
} else if peer_state.inbound_channel_request_by_id.remove(channel_id).is_some() {
2963
2985
log_error!(logger, "Force-closing channel {}", &channel_id);
@@ -5035,6 +5057,16 @@ where
5035
5057
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5036
5058
pending_msg_events, counterparty_node_id)
5037
5059
},
5060
+ #[cfg(dual_funding)]
5061
+ ChannelPhase::UnfundedInboundV2(chan) => {
5062
+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5063
+ pending_msg_events, counterparty_node_id)
5064
+ },
5065
+ #[cfg(dual_funding)]
5066
+ ChannelPhase::UnfundedOutboundV2(chan) => {
5067
+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5068
+ pending_msg_events, counterparty_node_id)
5069
+ },
5038
5070
}
5039
5071
});
5040
5072
@@ -6182,9 +6214,25 @@ where
6182
6214
num_unfunded_channels += 1;
6183
6215
}
6184
6216
},
6217
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6218
+ #[cfg(dual_funding)]
6219
+ ChannelPhase::UnfundedInboundV2(chan) => {
6220
+ // Only inbound V2 channels that are not 0conf and that we do not contribute to will be
6221
+ // included in the unfunded count.
6222
+ if chan.context.minimum_depth().unwrap_or(1) != 0 &&
6223
+ chan.dual_funding_context.our_funding_satoshis == 0 {
6224
+ num_unfunded_channels += 1;
6225
+ }
6226
+ },
6185
6227
ChannelPhase::UnfundedOutboundV1(_) => {
6186
6228
// Outbound channels don't contribute to the unfunded count in the DoS context.
6187
6229
continue;
6230
+ },
6231
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6232
+ #[cfg(dual_funding)]
6233
+ ChannelPhase::UnfundedOutboundV2(_) => {
6234
+ // Outbound channels don't contribute to the unfunded count in the DoS context.
6235
+ continue;
6188
6236
}
6189
6237
}
6190
6238
}
@@ -6607,6 +6655,14 @@ where
6607
6655
let mut chan = remove_channel_phase!(self, chan_phase_entry);
6608
6656
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6609
6657
},
6658
+ // TODO(dual_funding): Combine this match arm with above.
6659
+ #[cfg(dual_funding)]
6660
+ ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
6661
+ let context = phase.context_mut();
6662
+ log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6663
+ let mut chan = remove_channel_phase!(self, chan_phase_entry);
6664
+ finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6665
+ },
6610
6666
}
6611
6667
} else {
6612
6668
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 +8530,9 @@ where
8474
8530
match phase {
8475
8531
// Retain unfunded channels.
8476
8532
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
8533
+ // TODO(dual_funding): Combine this match arm with above.
8534
+ #[cfg(dual_funding)]
8535
+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
8477
8536
ChannelPhase::Funded(channel) => {
8478
8537
let res = f(channel);
8479
8538
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8943,6 +9002,14 @@ where
8943
9002
ChannelPhase::UnfundedInboundV1(chan) => {
8944
9003
&mut chan.context
8945
9004
},
9005
+ #[cfg(dual_funding)]
9006
+ ChannelPhase::UnfundedOutboundV2(chan) => {
9007
+ &mut chan.context
9008
+ },
9009
+ #[cfg(dual_funding)]
9010
+ ChannelPhase::UnfundedInboundV2(chan) => {
9011
+ &mut chan.context
9012
+ },
8946
9013
};
8947
9014
// Clean up for removal.
8948
9015
update_maps_on_chan_removal!(self, &context);
@@ -9095,12 +9162,30 @@ where
9095
9162
});
9096
9163
}
9097
9164
9165
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9166
+ #[cfg(dual_funding)]
9167
+ ChannelPhase::UnfundedOutboundV2(chan) => {
9168
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
9169
+ node_id: chan.context.get_counterparty_node_id(),
9170
+ msg: chan.get_open_channel_v2(self.chain_hash),
9171
+ });
9172
+ },
9173
+
9098
9174
ChannelPhase::UnfundedInboundV1(_) => {
9099
9175
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9100
9176
// they are not persisted and won't be recovered after a crash.
9101
9177
// Therefore, they shouldn't exist at this point.
9102
9178
debug_assert!(false);
9103
9179
}
9180
+
9181
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9182
+ #[cfg(dual_funding)]
9183
+ ChannelPhase::UnfundedInboundV2(channel) => {
9184
+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9185
+ // they are not persisted and won't be recovered after a crash.
9186
+ // Therefore, they shouldn't exist at this point.
9187
+ debug_assert!(false);
9188
+ },
9104
9189
}
9105
9190
}
9106
9191
}
@@ -9178,14 +9263,29 @@ where
9178
9263
if peer_state_mutex_opt.is_none() { return; }
9179
9264
let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
9180
9265
let peer_state = &mut *peer_state_lock;
9181
- if let Some(ChannelPhase::UnfundedOutboundV1(chan)) = peer_state.channel_by_id.get_mut(&msg.channel_id) {
9182
- if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9183
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9184
- node_id: *counterparty_node_id,
9185
- msg,
9186
- });
9187
- return;
9188
- }
9266
+ match peer_state.channel_by_id.get_mut(&msg.channel_id) {
9267
+ Some(ChannelPhase::UnfundedOutboundV1(ref mut chan)) => {
9268
+ if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9269
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9270
+ node_id: *counterparty_node_id,
9271
+ msg,
9272
+ });
9273
+ return;
9274
+ }
9275
+ },
9276
+ #[cfg(dual_funding)]
9277
+ Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
9278
+ if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9279
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
9280
+ node_id: *counterparty_node_id,
9281
+ msg,
9282
+ });
9283
+ return;
9284
+ }
9285
+ },
9286
+ None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
9287
+ #[cfg(dual_funding)]
9288
+ Some(ChannelPhase::UnfundedInboundV2(_)) => (),
9189
9289
}
9190
9290
}
9191
9291
0 commit comments