@@ -548,6 +548,7 @@ struct MsgHandleErrInternal {
548548	chan_id: Option<(ChannelId, u128)>, // If Some a channel of ours has been closed
549549	shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
550550	channel_capacity: Option<u64>,
551+ 	channel_funding_txo: Option<OutPoint>,
551552}
552553impl MsgHandleErrInternal {
553554	#[inline]
@@ -565,14 +566,17 @@ impl MsgHandleErrInternal {
565566			chan_id: None,
566567			shutdown_finish: None,
567568			channel_capacity: None,
569+ 			channel_funding_txo: None,
568570		}
569571	}
570572	#[inline]
571573	fn from_no_close(err: msgs::LightningError) -> Self {
572- 		Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None }
574+ 		Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None, channel_funding_txo: None  }
573575	}
574576	#[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 {
577+ 	fn from_finish_shutdown<SP: Deref>(err: String, channel_id: ChannelId, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>, channel_context: &ChannelContext<SP>) -> Self
578+ 	where SP::Target: SignerProvider
579+ 	{
576580		let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() };
577581		let action = if shutdown_res.monitor_update.is_some() {
578582			// We have a closing `ChannelMonitorUpdate`, which means the channel was funded and we
@@ -584,9 +588,10 @@ impl MsgHandleErrInternal {
584588		};
585589		Self {
586590			err: LightningError { err, action },
587- 			chan_id: Some((channel_id, user_channel_id )),
591+ 			chan_id: Some((channel_id, channel_context.get_user_id() )),
588592			shutdown_finish: Some((shutdown_res, channel_update)),
589- 			channel_capacity: Some(channel_capacity)
593+ 			channel_capacity: Some(channel_context.get_value_satoshis()),
594+ 			channel_funding_txo: channel_context.get_funding_txo(),
590595		}
591596	}
592597	#[inline]
@@ -620,6 +625,7 @@ impl MsgHandleErrInternal {
620625			chan_id: None,
621626			shutdown_finish: None,
622627			channel_capacity: None,
628+ 			channel_funding_txo: None,
623629		}
624630	}
625631
@@ -1956,7 +1962,7 @@ macro_rules! handle_error {
19561962
19571963		match $internal {
19581964			Ok(msg) => Ok(msg),
1959- 			Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity }) => {
1965+ 			Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity, channel_funding_txo  }) => {
19601966				let mut msg_events = Vec::with_capacity(2);
19611967
19621968				if let Some((shutdown_res, update_option)) = shutdown_finish {
@@ -1972,6 +1978,7 @@ macro_rules! handle_error {
19721978							reason: ClosureReason::ProcessingError { err: err.err.clone() },
19731979							counterparty_node_id: Some($counterparty_node_id),
19741980							channel_capacity_sats: channel_capacity,
1981+ 							channel_funding_txo: channel_funding_txo,
19751982						}, None));
19761983					}
19771984				}
@@ -2040,11 +2047,9 @@ macro_rules! convert_chan_phase_err {
20402047				log_error!(logger, "Closing channel {} due to close-required error: {}", $channel_id, msg);
20412048				update_maps_on_chan_removal!($self, $channel.context);
20422049				let shutdown_res = $channel.context.force_shutdown(true);
2043- 				let user_id = $channel.context.get_user_id();
2044- 				let channel_capacity_satoshis = $channel.context.get_value_satoshis();
20452050
2046- 				(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id, 
2047- 					shutdown_res, $channel_update, channel_capacity_satoshis ))
2051+ 				(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id,
2052+ 					shutdown_res, $channel_update, &$channel.context ))
20482053			},
20492054		}
20502055	};
@@ -2718,6 +2723,7 @@ where
27182723			reason: closure_reason,
27192724			counterparty_node_id: Some(context.get_counterparty_node_id()),
27202725			channel_capacity_sats: Some(context.get_value_satoshis()),
2726+ 			channel_funding_txo: context.get_funding_txo(),
27212727		}, None));
27222728	}
27232729
@@ -3757,11 +3763,9 @@ where
37573763				let logger = WithChannelContext::from(&self.logger, &chan.context);
37583764				let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
37593765					.map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
3760- 						let channel_id = chan.context.channel_id();
3761- 						let user_id = chan.context.get_user_id();
37623766						let shutdown_res = chan.context.force_shutdown(false);
3763- 						let channel_capacity  = chan.context.get_value_satoshis( );
3764- 						(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity) )
3767+ 						let err_msg  = MsgHandleErrInternal::from_finish_shutdown(msg,  chan.context.channel_id(), shutdown_res, None, &chan.context );
3768+ 						(chan, err_msg )
37653769					} else { unreachable!(); });
37663770				match funding_res {
37673771					Ok(funding_msg) => (chan, funding_msg),
@@ -10308,6 +10312,7 @@ where
1030810312						reason: ClosureReason::OutdatedChannelManager,
1030910313						counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1031010314						channel_capacity_sats: Some(channel.context.get_value_satoshis()),
10315+ 						channel_funding_txo: channel.context.get_funding_txo(),
1031110316					}, None));
1031210317					for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
1031310318						let mut found_htlc = false;
@@ -10361,6 +10366,7 @@ where
1036110366					reason: ClosureReason::DisconnectedPeer,
1036210367					counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1036310368					channel_capacity_sats: Some(channel.context.get_value_satoshis()),
10369+ 					channel_funding_txo: channel.context.get_funding_txo(),
1036410370				}, None));
1036510371			} else {
1036610372				log_error!(logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", &channel.context.channel_id());
0 commit comments