@@ -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);
@@ -5031,6 +5053,16 @@ where
5031
5053
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5032
5054
pending_msg_events, counterparty_node_id)
5033
5055
},
5056
+ #[cfg(dual_funding)]
5057
+ ChannelPhase::UnfundedInboundV2(chan) => {
5058
+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5059
+ pending_msg_events, counterparty_node_id)
5060
+ },
5061
+ #[cfg(dual_funding)]
5062
+ ChannelPhase::UnfundedOutboundV2(chan) => {
5063
+ process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
5064
+ pending_msg_events, counterparty_node_id)
5065
+ },
5034
5066
}
5035
5067
});
5036
5068
@@ -6178,9 +6210,25 @@ where
6178
6210
num_unfunded_channels += 1;
6179
6211
}
6180
6212
},
6213
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6214
+ #[cfg(dual_funding)]
6215
+ ChannelPhase::UnfundedInboundV2(chan) => {
6216
+ // Only inbound V2 channels that are not 0conf and that we do not contribute to will be
6217
+ // included in the unfunded count.
6218
+ if chan.context.minimum_depth().unwrap_or(1) != 0 &&
6219
+ chan.dual_funding_context.our_funding_satoshis == 0 {
6220
+ num_unfunded_channels += 1;
6221
+ }
6222
+ },
6181
6223
ChannelPhase::UnfundedOutboundV1(_) => {
6182
6224
// Outbound channels don't contribute to the unfunded count in the DoS context.
6183
6225
continue;
6226
+ },
6227
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
6228
+ #[cfg(dual_funding)]
6229
+ ChannelPhase::UnfundedOutboundV2(_) => {
6230
+ // Outbound channels don't contribute to the unfunded count in the DoS context.
6231
+ continue;
6184
6232
}
6185
6233
}
6186
6234
}
@@ -6603,6 +6651,14 @@ where
6603
6651
let mut chan = remove_channel_phase!(self, chan_phase_entry);
6604
6652
finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6605
6653
},
6654
+ // TODO(dual_funding): Combine this match arm with above.
6655
+ #[cfg(dual_funding)]
6656
+ ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
6657
+ let context = phase.context_mut();
6658
+ log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6659
+ let mut chan = remove_channel_phase!(self, chan_phase_entry);
6660
+ finish_shutdown = Some(chan.context_mut().force_shutdown(false, ClosureReason::CounterpartyCoopClosedUnfundedChannel));
6661
+ },
6606
6662
}
6607
6663
} else {
6608
6664
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))
@@ -8470,6 +8526,9 @@ where
8470
8526
match phase {
8471
8527
// Retain unfunded channels.
8472
8528
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
8529
+ // TODO(dual_funding): Combine this match arm with above.
8530
+ #[cfg(dual_funding)]
8531
+ ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
8473
8532
ChannelPhase::Funded(channel) => {
8474
8533
let res = f(channel);
8475
8534
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8939,6 +8998,14 @@ where
8939
8998
ChannelPhase::UnfundedInboundV1(chan) => {
8940
8999
&mut chan.context
8941
9000
},
9001
+ #[cfg(dual_funding)]
9002
+ ChannelPhase::UnfundedOutboundV2(chan) => {
9003
+ &mut chan.context
9004
+ },
9005
+ #[cfg(dual_funding)]
9006
+ ChannelPhase::UnfundedInboundV2(chan) => {
9007
+ &mut chan.context
9008
+ },
8942
9009
};
8943
9010
// Clean up for removal.
8944
9011
update_maps_on_chan_removal!(self, &context);
@@ -9091,12 +9158,30 @@ where
9091
9158
});
9092
9159
}
9093
9160
9161
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9162
+ #[cfg(dual_funding)]
9163
+ ChannelPhase::UnfundedOutboundV2(chan) => {
9164
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
9165
+ node_id: chan.context.get_counterparty_node_id(),
9166
+ msg: chan.get_open_channel_v2(self.chain_hash),
9167
+ });
9168
+ },
9169
+
9094
9170
ChannelPhase::UnfundedInboundV1(_) => {
9095
9171
// Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9096
9172
// they are not persisted and won't be recovered after a crash.
9097
9173
// Therefore, they shouldn't exist at this point.
9098
9174
debug_assert!(false);
9099
9175
}
9176
+
9177
+ // TODO(dual_funding): Combine this match arm with above once #[cfg(dual_funding)] is removed.
9178
+ #[cfg(dual_funding)]
9179
+ ChannelPhase::UnfundedInboundV2(channel) => {
9180
+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
9181
+ // they are not persisted and won't be recovered after a crash.
9182
+ // Therefore, they shouldn't exist at this point.
9183
+ debug_assert!(false);
9184
+ },
9100
9185
}
9101
9186
}
9102
9187
}
@@ -9174,14 +9259,29 @@ where
9174
9259
if peer_state_mutex_opt.is_none() { return; }
9175
9260
let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
9176
9261
let peer_state = &mut *peer_state_lock;
9177
- if let Some(ChannelPhase::UnfundedOutboundV1(chan)) = peer_state.channel_by_id.get_mut(&msg.channel_id) {
9178
- if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9179
- peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9180
- node_id: *counterparty_node_id,
9181
- msg,
9182
- });
9183
- return;
9184
- }
9262
+ match peer_state.channel_by_id.get_mut(&msg.channel_id) {
9263
+ Some(ChannelPhase::UnfundedOutboundV1(ref mut chan)) => {
9264
+ if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9265
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9266
+ node_id: *counterparty_node_id,
9267
+ msg,
9268
+ });
9269
+ return;
9270
+ }
9271
+ },
9272
+ #[cfg(dual_funding)]
9273
+ Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => {
9274
+ if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) {
9275
+ peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
9276
+ node_id: *counterparty_node_id,
9277
+ msg,
9278
+ });
9279
+ return;
9280
+ }
9281
+ },
9282
+ None | Some(ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::Funded(_)) => (),
9283
+ #[cfg(dual_funding)]
9284
+ Some(ChannelPhase::UnfundedInboundV2(_)) => (),
9185
9285
}
9186
9286
}
9187
9287
0 commit comments