Skip to content

Send error message to peer if we drop an unfunded channel on timeout #2496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4472,20 +4472,34 @@ where
chan_id: &[u8; 32],
chan_context: &mut ChannelContext<<SP::Target as SignerProvider>::Signer>,
unfunded_chan_context: &mut UnfundedChannelContext,
pending_msg_events: &mut Vec<MessageSendEvent>,
| {
chan_context.maybe_expire_prev_config();
if unfunded_chan_context.should_expire_unfunded_channel() {
log_error!(self.logger, "Force-closing pending outbound channel {} for not establishing in a timely manner", log_bytes!(&chan_id[..]));
log_error!(self.logger,
"Force-closing pending channel with ID {} for not establishing in a timely manner",
log_bytes!(&chan_id[..]));
update_maps_on_chan_removal!(self, &chan_context);
self.issue_channel_close_events(&chan_context, ClosureReason::HolderForceClosed);
self.finish_force_close_channel(chan_context.force_shutdown(false));
pending_msg_events.push(MessageSendEvent::HandleError {
node_id: counterparty_node_id,
action: msgs::ErrorAction::SendErrorMessage {
msg: msgs::ErrorMessage {
channel_id: *chan_id,
data: "Force-closing pending channel due to timeout awaiting establishment handshake".to_owned(),
},
},
});
false
} else {
true
}
};
peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context));
peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(chan_id, &mut chan.context, &mut chan.unfunded_context));
peer_state.outbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(
chan_id, &mut chan.context, &mut chan.unfunded_context, pending_msg_events));
peer_state.inbound_v1_channel_by_id.retain(|chan_id, chan| process_unfunded_channel_tick(
chan_id, &mut chan.context, &mut chan.unfunded_context, pending_msg_events));

if peer_state.ok_to_remove(true) {
pending_peers_awaiting_removal.push(counterparty_node_id);
Expand Down
20 changes: 18 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10036,7 +10036,15 @@ fn test_remove_expired_outbound_unfunded_channels() {
nodes[0].node.timer_tick_occurred();
check_outbound_channel_existence(false);

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

#[test]
Expand Down Expand Up @@ -10079,5 +10087,13 @@ fn test_remove_expired_inbound_unfunded_channels() {
nodes[1].node.timer_tick_occurred();
check_inbound_channel_existence(false);

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