mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Merge pull request #2496 from dunxen/2023-08-fix2488
Send error message to peer if we drop an unfunded channel on timeout
This commit is contained in:
commit
a24626b919
2 changed files with 35 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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]
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue