Skip to content

Commit dd0b927

Browse files
committed
Use the new property UnacceptedChannelContext
- If the channel is not accepted on time, the channel is forced closed with an appropriate error message.
1 parent 26fb470 commit dd0b927

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4343
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4444
// construct one themselves.
4545
use crate::ln::{inbound_payment, ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
46-
use crate::ln::channel::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel};
46+
use crate::ln::channel::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnacceptedChannelContext, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel};
4747
use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4848
#[cfg(any(feature = "_test_utils", test))]
4949
use crate::ln::features::Bolt11InvoiceFeatures;
@@ -4765,13 +4765,28 @@ where
47654765
chan_id: &ChannelId,
47664766
context: &mut ChannelContext<SP>,
47674767
unfunded_context: &mut UnfundedChannelContext,
4768+
unaccepted_context: &mut Option<&mut UnacceptedChannelContext>,
47684769
pending_msg_events: &mut Vec<MessageSendEvent>,
47694770
counterparty_node_id: PublicKey,
47704771
| {
47714772
context.maybe_expire_prev_config();
4772-
if unfunded_context.should_expire_unfunded_channel() {
4773-
log_error!(self.logger,
4774-
"Force-closing pending channel with ID {} for not establishing in a timely manner", chan_id);
4773+
let should_expire_unaccepted_channel = match unaccepted_context {
4774+
Some(unaccepted_context) => unaccepted_context.should_expire_unaccepted_channel(),
4775+
None => false,
4776+
};
4777+
let should_expire_unfunded_channel = unfunded_context.should_expire_unfunded_channel();
4778+
if should_expire_unaccepted_channel || should_expire_unfunded_channel {
4779+
let log_msg = if should_expire_unaccepted_channel {
4780+
format!("Force-closing pending channel with ID {} for not accepting in a timely manner", chan_id)
4781+
} else {
4782+
format!("Force-closing pending channel with ID {} for not establishing in a timely manner", chan_id)
4783+
};
4784+
let err_msg = if should_expire_unaccepted_channel {
4785+
"Force-closing pending channel due to timeout awaiting acceptance".to_owned()
4786+
} else {
4787+
"Force-closing pending channel due to timeout awaiting establishment handshake".to_owned()
4788+
};
4789+
log_error!(self.logger, "{}", log_msg);
47754790
update_maps_on_chan_removal!(self, &context);
47764791
self.issue_channel_close_events(&context, ClosureReason::HolderForceClosed);
47774792
shutdown_channels.push(context.force_shutdown(false));
@@ -4780,7 +4795,7 @@ where
47804795
action: msgs::ErrorAction::SendErrorMessage {
47814796
msg: msgs::ErrorMessage {
47824797
channel_id: *chan_id,
4783-
data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned(),
4798+
data: err_msg.to_owned(),
47844799
},
47854800
},
47864801
});
@@ -4871,11 +4886,11 @@ where
48714886
true
48724887
},
48734888
ChannelPhase::UnfundedInboundV1(chan) => {
4874-
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4889+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut None,
48754890
pending_msg_events, counterparty_node_id)
48764891
},
48774892
ChannelPhase::UnfundedOutboundV1(chan) => {
4878-
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context,
4893+
process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context, &mut Some(&mut chan.unaccepted_context),
48794894
pending_msg_events, counterparty_node_id)
48804895
},
48814896
}
@@ -6097,6 +6112,7 @@ where
60976112
match phase.get_mut() {
60986113
ChannelPhase::UnfundedOutboundV1(chan) => {
60996114
try_chan_phase_entry!(self, chan.accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &peer_state.latest_features), phase);
6115+
chan.unaccepted_context.channel_accepted();
61006116
(chan.context.get_value_satoshis(), chan.context.get_funding_redeemscript().to_v0_p2wsh(), chan.context.get_user_id())
61016117
},
61026118
_ => {

0 commit comments

Comments
 (0)