]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Send error message to peer if we drop an unfunded channel on timeout
authorDuncan Dean <git@dunxen.dev>
Mon, 14 Aug 2023 14:21:35 +0000 (16:21 +0200)
committerDuncan Dean <git@dunxen.dev>
Mon, 14 Aug 2023 14:22:33 +0000 (16:22 +0200)
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_tests.rs

index 961f25cc664ad3425d39dcf5e099b66c44eb4949..b7c7e03322725d2d34f957249f1fe049ac18b68f 100644 (file)
@@ -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);
index 53aa75d82777caa661989f276cb1789b90127cf4..6e96e269f3bc427e9c7c9717f726864b85a67ea8 100644 (file)
@@ -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);
 }