Skip to content

Commit a24626b

Browse files
authored
Merge pull request #2496 from dunxen/2023-08-fix2488
Send error message to peer if we drop an unfunded channel on timeout
2 parents 4a4163f + eda6e9d commit a24626b

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

lightning/src/ln/channelmanager.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -4472,20 +4472,34 @@ where
44724472
chan_id: &[u8; 32],
44734473
chan_context: &mut ChannelContext<<SP::Target as SignerProvider>::Signer>,
44744474
unfunded_chan_context: &mut UnfundedChannelContext,
4475+
pending_msg_events: &mut Vec<MessageSendEvent>,
44754476
| {
44764477
chan_context.maybe_expire_prev_config();
44774478
if unfunded_chan_context.should_expire_unfunded_channel() {
4478-
log_error!(self.logger, "Force-closing pending outbound channel {} for not establishing in a timely manner", log_bytes!(&chan_id[..]));
4479+
log_error!(self.logger,
4480+
"Force-closing pending channel with ID {} for not establishing in a timely manner",
4481+
log_bytes!(&chan_id[..]));
44794482
update_maps_on_chan_removal!(self, &chan_context);
44804483
self.issue_channel_close_events(&chan_context, ClosureReason::HolderForceClosed);
44814484
self.finish_force_close_channel(chan_context.force_shutdown(false));
4485+
pending_msg_events.push(MessageSendEvent::HandleError {
4486+
node_id: counterparty_node_id,
4487+
action: msgs::ErrorAction::SendErrorMessage {
4488+
msg: msgs::ErrorMessage {
4489+
channel_id: *chan_id,
4490+
data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned(),
4491+
},
4492+
},
4493+
});
44824494
false
44834495
} else {
44844496
true
44854497
}
44864498
};
4487-
peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context));
4488-
peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context));
4499+
peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(
4500+
chan_id, &mut chan.context, &mut chan.unfunded_context, pending_msg_events));
4501+
peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(
4502+
chan_id, &mut chan.context, &mut chan.unfunded_context, pending_msg_events));
44894503

44904504
if peer_state.ok_to_remove(true) {
44914505
pending_peers_awaiting_removal.push(counterparty_node_id);

lightning/src/ln/functional_tests.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -10036,7 +10036,15 @@ fn test_remove_expired_outbound_unfunded_channels() {
1003610036
nodes[0].node.timer_tick_occurred();
1003710037
check_outbound_channel_existence(false);
1003810038

10039-
check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000);
10039+
let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
10040+
assert_eq!(msg_events.len(), 1);
10041+
match msg_events[0] {
10042+
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
10043+
assert_eq!(msg.data, "Force-closing pending channel due to timeout awaiting establishment handshake");
10044+
},
10045+
_ => panic!("Unexpected event"),
10046+
}
10047+
check_closed_event(&nodes[0], 1, ClosureReason::HolderForceClosed, false, &[nodes[1].node.get_our_node_id()], 100000);
1004010048
}
1004110049

1004210050
#[test]
@@ -10079,5 +10087,13 @@ fn test_remove_expired_inbound_unfunded_channels() {
1007910087
nodes[1].node.timer_tick_occurred();
1008010088
check_inbound_channel_existence(false);
1008110089

10082-
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
10090+
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
10091+
assert_eq!(msg_events.len(), 1);
10092+
match msg_events[0] {
10093+
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => {
10094+
assert_eq!(msg.data, "Force-closing pending channel due to timeout awaiting establishment handshake");
10095+
},
10096+
_ => panic!("Unexpected event"),
10097+
}
10098+
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed, false, &[nodes[0].node.get_our_node_id()], 100000);
1008310099
}

0 commit comments

Comments
 (0)