@@ -545,9 +545,8 @@ impl Into<u16> for FailureCode {
545545
546546struct MsgHandleErrInternal {
547547 err: msgs::LightningError,
548- chan_id: Option<(ChannelId, u128)>, // If Some a channel of ours has been closed
548+ closes_channel: bool,
549549 shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
550- channel_capacity: Option<u64>,
551550}
552551impl MsgHandleErrInternal {
553552 #[inline]
@@ -562,17 +561,16 @@ impl MsgHandleErrInternal {
562561 },
563562 },
564563 },
565- chan_id: None ,
564+ closes_channel: false ,
566565 shutdown_finish: None,
567- channel_capacity: None,
568566 }
569567 }
570568 #[inline]
571569 fn from_no_close(err: msgs::LightningError) -> Self {
572- Self { err, chan_id: None , shutdown_finish: None, channel_capacity : None }
570+ Self { err, closes_channel: false , shutdown_finish: None }
573571 }
574572 #[inline]
575- fn from_finish_shutdown(err: String, channel_id: ChannelId, user_channel_id: u128, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>, channel_capacity: u64 ) -> Self {
573+ fn from_finish_shutdown(err: String, channel_id: ChannelId, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>) -> Self {
576574 let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() };
577575 let action = if shutdown_res.monitor_update.is_some() {
578576 // We have a closing `ChannelMonitorUpdate`, which means the channel was funded and we
@@ -584,9 +582,8 @@ impl MsgHandleErrInternal {
584582 };
585583 Self {
586584 err: LightningError { err, action },
587- chan_id: Some((channel_id, user_channel_id)) ,
585+ closes_channel: true ,
588586 shutdown_finish: Some((shutdown_res, channel_update)),
589- channel_capacity: Some(channel_capacity)
590587 }
591588 }
592589 #[inline]
@@ -617,14 +614,13 @@ impl MsgHandleErrInternal {
617614 },
618615 },
619616 },
620- chan_id: None ,
617+ closes_channel: false ,
621618 shutdown_finish: None,
622- channel_capacity: None,
623619 }
624620 }
625621
626622 fn closes_channel(&self) -> bool {
627- self.chan_id.is_some()
623+ self.closes_channel
628624 }
629625}
630626
@@ -1956,22 +1952,27 @@ macro_rules! handle_error {
19561952
19571953 match $internal {
19581954 Ok(msg) => Ok(msg),
1959- Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity }) => {
1955+ Err(MsgHandleErrInternal { err, shutdown_finish, .. }) => {
19601956 let mut msg_events = Vec::with_capacity(2);
19611957
19621958 if let Some((shutdown_res, update_option)) = shutdown_finish {
1959+ let counterparty_node_id = shutdown_res.counterparty_node_id;
1960+ let channel_id = shutdown_res.channel_id;
1961+ let logger = WithContext::from(
1962+ &$self.logger, Some(counterparty_node_id), Some(channel_id),
1963+ );
1964+ log_error!(logger, "Force-closing channel: {}", err.err);
1965+
19631966 $self.finish_close_channel(shutdown_res);
19641967 if let Some(update) = update_option {
19651968 msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
19661969 msg: update
19671970 });
19681971 }
1972+ } else {
1973+ log_error!($self.logger, "Got non-closing error: {}", err.err);
19691974 }
19701975
1971- let logger = WithContext::from(
1972- &$self.logger, Some($counterparty_node_id), chan_id.map(|(chan_id, _)| chan_id)
1973- );
1974- log_error!(logger, "{}", err.err);
19751976 if let msgs::ErrorAction::IgnoreError = err.action {
19761977 } else {
19771978 msg_events.push(events::MessageSendEvent::HandleError {
@@ -2033,11 +2034,9 @@ macro_rules! convert_chan_phase_err {
20332034 update_maps_on_chan_removal!($self, $channel.context);
20342035 let reason = ClosureReason::ProcessingError { err: msg.clone() };
20352036 let shutdown_res = $channel.context.force_shutdown(true, reason);
2036- let user_id = $channel.context.get_user_id();
2037- let channel_capacity_satoshis = $channel.context.get_value_satoshis();
2038-
2039- (true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
2040- shutdown_res, $channel_update, channel_capacity_satoshis))
2037+ let err =
2038+ MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, shutdown_res, $channel_update);
2039+ (true, err)
20412040 },
20422041 }
20432042 };
@@ -2834,7 +2833,8 @@ where
28342833 &self.logger, Some(shutdown_res.counterparty_node_id), Some(shutdown_res.channel_id),
28352834 );
28362835
2837- log_debug!(logger, "Finishing closure of channel with {} HTLCs to fail", shutdown_res.dropped_outbound_htlcs.len());
2836+ log_debug!(logger, "Finishing closure of channel due to {} with {} HTLCs to fail",
2837+ shutdown_res.closure_reason, shutdown_res.dropped_outbound_htlcs.len());
28382838 for htlc_source in shutdown_res.dropped_outbound_htlcs.drain(..) {
28392839 let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
28402840 let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
@@ -3746,11 +3746,9 @@ where
37463746 let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
37473747 .map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
37483748 let channel_id = chan.context.channel_id();
3749- let user_id = chan.context.get_user_id();
37503749 let reason = ClosureReason::ProcessingError { err: msg.clone() };
37513750 let shutdown_res = chan.context.force_shutdown(false, reason);
3752- let channel_capacity = chan.context.get_value_satoshis();
3753- (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity))
3751+ (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None))
37543752 } else { unreachable!(); });
37553753 match funding_res {
37563754 Ok(funding_msg) => (chan, funding_msg),
0 commit comments