Skip to content

Commit 23febee

Browse files
committed
Add V2 ChannelPhase variants
1 parent 5c68d10 commit 23febee

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ impl_writeable_tlv_based!(PendingChannelMonitorUpdate, {
895895
pub(super) enum ChannelPhase<SP: Deref> where SP::Target: SignerProvider {
896896
UnfundedOutboundV1(OutboundV1Channel<SP>),
897897
UnfundedInboundV1(InboundV1Channel<SP>),
898+
#[cfg(dual_funding)]
899+
UnfundedOutboundV2(OutboundV2Channel<SP>),
900+
#[cfg(dual_funding)]
901+
UnfundedInboundV2(InboundV2Channel<SP>),
898902
Funded(Channel<SP>),
899903
}
900904

@@ -907,6 +911,10 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
907911
ChannelPhase::Funded(chan) => &chan.context,
908912
ChannelPhase::UnfundedOutboundV1(chan) => &chan.context,
909913
ChannelPhase::UnfundedInboundV1(chan) => &chan.context,
914+
#[cfg(dual_funding)]
915+
ChannelPhase::UnfundedOutboundV2(chan) => &chan.context,
916+
#[cfg(dual_funding)]
917+
ChannelPhase::UnfundedInboundV2(chan) => &chan.context,
910918
}
911919
}
912920

@@ -915,6 +923,10 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
915923
ChannelPhase::Funded(ref mut chan) => &mut chan.context,
916924
ChannelPhase::UnfundedOutboundV1(ref mut chan) => &mut chan.context,
917925
ChannelPhase::UnfundedInboundV1(ref mut chan) => &mut chan.context,
926+
#[cfg(dual_funding)]
927+
ChannelPhase::UnfundedOutboundV2(ref mut chan) => &mut chan.context,
928+
#[cfg(dual_funding)]
929+
ChannelPhase::UnfundedInboundV2(ref mut chan) => &mut chan.context,
918930
}
919931
}
920932
}

lightning/src/ln/channelmanager.rs

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,14 @@ macro_rules! convert_chan_phase_err {
20552055
ChannelPhase::UnfundedInboundV1(channel) => {
20562056
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
20572057
},
2058+
#[cfg(dual_funding)]
2059+
ChannelPhase::UnfundedOutboundV2(channel) => {
2060+
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2061+
},
2062+
#[cfg(dual_funding)]
2063+
ChannelPhase::UnfundedInboundV2(channel) => {
2064+
convert_chan_phase_err!($self, $err, channel, $channel_id, UNFUNDED_CHANNEL)
2065+
},
20582066
}
20592067
};
20602068
}
@@ -2923,6 +2931,13 @@ where
29232931
// Unfunded channel has no update
29242932
(None, chan_phase.context().get_counterparty_node_id())
29252933
},
2934+
// TODO(dual_funding): Combine this match arm with above.
2935+
#[cfg(dual_funding)]
2936+
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => {
2937+
self.finish_close_channel(chan_phase.context_mut().force_shutdown(false));
2938+
// Unfunded channel has no update
2939+
(None, chan_phase.context().get_counterparty_node_id())
2940+
},
29262941
}
29272942
} else if peer_state.inbound_channel_request_by_id.remove(channel_id).is_some() {
29282943
log_error!(logger, "Force-closing channel {}", &channel_id);
@@ -4946,6 +4961,16 @@ where
49464961
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
49474962
pending_msg_events, counterparty_node_id)
49484963
},
4964+
#[cfg(dual_funding)]
4965+
ChannelPhase::UnfundedInboundV2(chan) => {
4966+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4967+
pending_msg_events, counterparty_node_id)
4968+
},
4969+
#[cfg(dual_funding)]
4970+
ChannelPhase::UnfundedOutboundV2(chan) => {
4971+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4972+
pending_msg_events, counterparty_node_id)
4973+
},
49494974
}
49504975
});
49514976

@@ -6042,14 +6067,27 @@ where
60426067
num_unfunded_channels += 1;
60436068
}
60446069
},
6045-
ChannelPhase::UnfundedInboundV1(chan) => {
6046-
if chan.context.minimum_depth().unwrap_or(1) != 0 {
6070+
ChannelPhase::UnfundedInboundV1(_) => {
6071+
if phase.context().minimum_depth().unwrap_or(1) != 0 {
6072+
num_unfunded_channels += 1;
6073+
}
6074+
},
6075+
// TODO(dual_funding): Combine this match arm with above.
6076+
#[cfg(dual_funding)]
6077+
ChannelPhase::UnfundedInboundV2(_) => {
6078+
if phase.context().minimum_depth().unwrap_or(1) != 0 {
60476079
num_unfunded_channels += 1;
60486080
}
60496081
},
60506082
ChannelPhase::UnfundedOutboundV1(_) => {
60516083
// Outbound channels don't contribute to the unfunded count in the DoS context.
60526084
continue;
6085+
},
6086+
// TODO(dual_funding): Combine this match arm with above.
6087+
#[cfg(dual_funding)]
6088+
ChannelPhase::UnfundedOutboundV2(_) => {
6089+
// Outbound channels don't contribute to the unfunded count in the DoS context.
6090+
continue;
60536091
}
60546092
}
60556093
}
@@ -6225,7 +6263,7 @@ where
62256263
},
62266264
}
62276265
},
6228-
Some(ChannelPhase::Funded(_)) | Some(ChannelPhase::UnfundedOutboundV1(_)) => {
6266+
Some(_) => {
62296267
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));
62306268
},
62316269
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))
@@ -6448,6 +6486,15 @@ where
64486486
let mut chan = remove_channel_phase!(self, chan_phase_entry);
64496487
finish_shutdown = Some(chan.context_mut().force_shutdown(false));
64506488
},
6489+
// TODO(dual_funding): Combine this match arm with above.
6490+
#[cfg(dual_funding)]
6491+
ChannelPhase::UnfundedInboundV2(_) | ChannelPhase::UnfundedOutboundV2(_) => {
6492+
let context = phase.context_mut();
6493+
log_error!(self.logger, "Immediately closing unfunded channel {} as peer asked to cooperatively shut it down (which is unnecessary)", &msg.channel_id);
6494+
self.issue_channel_close_events(&context, ClosureReason::CounterpartyCoopClosedUnfundedChannel);
6495+
let mut chan = remove_channel_phase!(self, chan_phase_entry);
6496+
finish_shutdown = Some(chan.context_mut().force_shutdown(false));
6497+
},
64516498
}
64526499
} else {
64536500
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))
@@ -8263,6 +8310,9 @@ where
82638310
match phase {
82648311
// Retain unfunded channels.
82658312
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => true,
8313+
// TODO(dual_funding): Combine this match arm with above.
8314+
#[cfg(dual_funding)]
8315+
ChannelPhase::UnfundedOutboundV2(_) | ChannelPhase::UnfundedInboundV2(_) => true,
82668316
ChannelPhase::Funded(channel) => {
82678317
let res = f(channel);
82688318
if let Ok((channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs)) = res {
@@ -8730,6 +8780,14 @@ where
87308780
ChannelPhase::UnfundedInboundV1(chan) => {
87318781
&mut chan.context
87328782
},
8783+
#[cfg(dual_funding)]
8784+
ChannelPhase::UnfundedOutboundV2(chan) => {
8785+
&mut chan.context
8786+
},
8787+
#[cfg(dual_funding)]
8788+
ChannelPhase::UnfundedInboundV2(chan) => {
8789+
&mut chan.context
8790+
},
87338791
};
87348792
// Clean up for removal.
87358793
update_maps_on_chan_removal!(self, &context);

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
190190
chan_context.holder_selected_channel_reserve_satoshis = 0;
191191
chan_context.holder_max_htlc_value_in_flight_msat = 100_000_000;
192192
},
193-
ChannelPhase::Funded(_) => assert!(false),
193+
_ => assert!(false),
194194
}
195195
}
196196

0 commit comments

Comments
 (0)