X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=961f25cc664ad3425d39dcf5e099b66c44eb4949;hb=131560e08fa4f66b8ce9302cde637f87602c86b0;hp=ae9744cb71c4c3ea66a748b9176418bfcef1d7f7;hpb=dec3fb316a7905284d64bb5bad88a898d04744d1;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ae9744cb..961f25cc 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -397,6 +397,7 @@ struct MsgHandleErrInternal { err: msgs::LightningError, chan_id: Option<([u8; 32], u128)>, // If Some a channel of ours has been closed shutdown_finish: Option<(ShutdownResult, Option)>, + channel_capacity: Option, } impl MsgHandleErrInternal { #[inline] @@ -413,14 +414,15 @@ impl MsgHandleErrInternal { }, chan_id: None, shutdown_finish: None, + channel_capacity: None, } } #[inline] fn from_no_close(err: msgs::LightningError) -> Self { - Self { err, chan_id: None, shutdown_finish: None } + Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None } } #[inline] - fn from_finish_shutdown(err: String, channel_id: [u8; 32], user_channel_id: u128, shutdown_res: ShutdownResult, channel_update: Option) -> Self { + fn from_finish_shutdown(err: String, channel_id: [u8; 32], user_channel_id: u128, shutdown_res: ShutdownResult, channel_update: Option, channel_capacity: u64) -> Self { Self { err: LightningError { err: err.clone(), @@ -433,6 +435,7 @@ impl MsgHandleErrInternal { }, chan_id: Some((channel_id, user_channel_id)), shutdown_finish: Some((shutdown_res, channel_update)), + channel_capacity: Some(channel_capacity) } } #[inline] @@ -465,6 +468,7 @@ impl MsgHandleErrInternal { }, chan_id: None, shutdown_finish: None, + channel_capacity: None, } } } @@ -1680,7 +1684,7 @@ macro_rules! handle_error { match $internal { Ok(msg) => Ok(msg), - Err(MsgHandleErrInternal { err, chan_id, shutdown_finish }) => { + Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity }) => { let mut msg_events = Vec::with_capacity(2); if let Some((shutdown_res, update_option)) = shutdown_finish { @@ -1693,7 +1697,9 @@ macro_rules! handle_error { if let Some((channel_id, user_channel_id)) = chan_id { $self.pending_events.lock().unwrap().push_back((events::Event::ChannelClosed { channel_id, user_channel_id, - reason: ClosureReason::ProcessingError { err: err.err.clone() } + reason: ClosureReason::ProcessingError { err: err.err.clone() }, + counterparty_node_id: Some($counterparty_node_id), + channel_capacity_sats: channel_capacity, }, None)); } } @@ -1766,7 +1772,7 @@ macro_rules! convert_chan_err { update_maps_on_chan_removal!($self, &$channel.context); let shutdown_res = $channel.context.force_shutdown(true); (true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, $channel.context.get_user_id(), - shutdown_res, $self.get_channel_update_for_broadcast(&$channel).ok())) + shutdown_res, $self.get_channel_update_for_broadcast(&$channel).ok(), $channel.context.get_value_satoshis())) }, } }; @@ -1779,7 +1785,7 @@ macro_rules! convert_chan_err { update_maps_on_chan_removal!($self, &$channel_context); let shutdown_res = $channel_context.force_shutdown(false); (true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, $channel_context.get_user_id(), - shutdown_res, None)) + shutdown_res, None, $channel_context.get_value_satoshis())) }, } } @@ -1958,7 +1964,7 @@ macro_rules! handle_new_monitor_update { let res = Err(MsgHandleErrInternal::from_finish_shutdown( "ChannelMonitor storage failure".to_owned(), $chan.context.channel_id(), $chan.context.get_user_id(), $chan.context.force_shutdown(false), - $self.get_channel_update_for_broadcast(&$chan).ok())); + $self.get_channel_update_for_broadcast(&$chan).ok(), $chan.context.get_value_satoshis())); $remove; res }, @@ -2392,7 +2398,9 @@ where pending_events_lock.push_back((events::Event::ChannelClosed { channel_id: context.channel_id(), user_channel_id: context.get_user_id(), - reason: closure_reason + reason: closure_reason, + counterparty_node_id: Some(context.get_counterparty_node_id()), + channel_capacity_sats: Some(context.get_value_satoshis()), }, None)); } @@ -3408,7 +3416,8 @@ where let channel_id = chan.context.channel_id(); let user_id = chan.context.get_user_id(); let shutdown_res = chan.context.force_shutdown(false); - (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None)) + let channel_capacity = chan.context.get_value_satoshis(); + (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity)) } else { unreachable!(); }); match funding_res { Ok((chan, funding_msg)) => (chan, funding_msg), @@ -5492,7 +5501,7 @@ where let user_id = inbound_chan.context.get_user_id(); let shutdown_res = inbound_chan.context.force_shutdown(false); return Err(MsgHandleErrInternal::from_finish_shutdown(format!("{}", err), - msg.temporary_channel_id, user_id, shutdown_res, None)); + msg.temporary_channel_id, user_id, shutdown_res, None, inbound_chan.context.get_value_satoshis())); }, } }, @@ -8442,7 +8451,9 @@ where channel_closures.push_back((events::Event::ChannelClosed { channel_id: channel.context.channel_id(), user_channel_id: channel.context.get_user_id(), - reason: ClosureReason::OutdatedChannelManager + reason: ClosureReason::OutdatedChannelManager, + counterparty_node_id: Some(channel.context.get_counterparty_node_id()), + channel_capacity_sats: Some(channel.context.get_value_satoshis()), }, None)); for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() { let mut found_htlc = false; @@ -8494,6 +8505,8 @@ where channel_id: channel.context.channel_id(), user_channel_id: channel.context.get_user_id(), reason: ClosureReason::DisconnectedPeer, + counterparty_node_id: Some(channel.context.get_counterparty_node_id()), + channel_capacity_sats: Some(channel.context.get_value_satoshis()), }, None)); } else { log_error!(args.logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", log_bytes!(channel.context.channel_id())); @@ -9710,7 +9723,7 @@ mod tests { nodes[0].node.force_close_broadcasting_latest_txn(&chan.2, &nodes[1].node.get_our_node_id()).unwrap(); check_closed_broadcast!(nodes[0], true); check_added_monitors!(nodes[0], 1); - check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed); + check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed, [nodes[1].node.get_our_node_id()], 100000); { // Assert that nodes[1] is awaiting removal for nodes[0] once nodes[1] has been @@ -9873,8 +9886,8 @@ mod tests { } let (_nodes_1_update, _none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); - check_closed_event!(nodes[0], 1, ClosureReason::CooperativeClosure); - check_closed_event!(nodes[1], 1, ClosureReason::CooperativeClosure); + check_closed_event!(nodes[0], 1, ClosureReason::CooperativeClosure, [nodes[1].node.get_our_node_id()], 1000000); + check_closed_event!(nodes[1], 1, ClosureReason::CooperativeClosure, [nodes[0].node.get_our_node_id()], 1000000); } fn check_not_connected_to_peer_error(res_err: Result, expected_public_key: PublicKey) { @@ -10267,7 +10280,7 @@ mod tests { let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert!(!open_channel_msg.channel_type.unwrap().supports_anchors_zero_fee_htlc_tx()); - check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed); + check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000); } #[test]