Skip to content

Commit 01e3ef1

Browse files
Add counterparty_node_id & channel_capacity to ChannelClosed
The current ChannelClosed event does not let you know the counterparty during a channel close event. This change adds the counterparty_node_id and the channel_capacity to the ChannelClosed event. This helps users to have more context during a channel close event. Solves #2343
1 parent c5214c2 commit 01e3ef1

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lightning/src/events/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,12 @@ pub enum Event {
733733
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
734734
user_channel_id: u128,
735735
/// The reason the channel was closed.
736-
reason: ClosureReason
736+
reason: ClosureReason,
737+
/// Counterparty in the closed channel
738+
counterparty_node_id: Option<PublicKey>,
739+
/// Value of the closing channel
740+
channel_capacity: Option<u64>,
741+
737742
},
738743
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
739744
/// inputs for another purpose.
@@ -929,7 +934,7 @@ impl Writeable for Event {
929934
(5, outbound_amount_forwarded_msat, option),
930935
});
931936
},
932-
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => {
937+
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason, ref counterparty_node_id, ref channel_capacity } => {
933938
9u8.write(writer)?;
934939
// `user_channel_id` used to be a single u64 value. In order to remain backwards
935940
// compatible with versions prior to 0.0.113, the u128 is serialized as two
@@ -941,6 +946,8 @@ impl Writeable for Event {
941946
(1, user_channel_id_low, required),
942947
(2, reason, required),
943948
(3, user_channel_id_high, required),
949+
(5, counterparty_node_id, option),
950+
(7, channel_capacity, option),
944951
});
945952
},
946953
&Event::DiscardFunding { ref channel_id, ref transaction } => {
@@ -1221,11 +1228,15 @@ impl MaybeReadable for Event {
12211228
let mut reason = UpgradableRequired(None);
12221229
let mut user_channel_id_low_opt: Option<u64> = None;
12231230
let mut user_channel_id_high_opt: Option<u64> = None;
1231+
let mut counterparty_node_id = None;
1232+
let mut channel_capacity = None;
12241233
read_tlv_fields!(reader, {
12251234
(0, channel_id, required),
12261235
(1, user_channel_id_low_opt, option),
12271236
(2, reason, upgradable_required),
12281237
(3, user_channel_id_high_opt, option),
1238+
(5, counterparty_node_id, option),
1239+
(7, channel_capacity, option),
12291240
});
12301241

12311242
// `user_channel_id` used to be a single u64 value. In order to remain
@@ -1234,7 +1245,7 @@ impl MaybeReadable for Event {
12341245
let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
12351246
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
12361247

1237-
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required) }))
1248+
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required), counterparty_node_id, channel_capacity }))
12381249
};
12391250
f()
12401251
},

lightning/src/ln/channelmanager.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,9 @@ macro_rules! handle_error {
16081608
if let Some((channel_id, user_channel_id)) = chan_id {
16091609
$self.pending_events.lock().unwrap().push_back((events::Event::ChannelClosed {
16101610
channel_id, user_channel_id,
1611-
reason: ClosureReason::ProcessingError { err: err.err.clone() }
1611+
reason: ClosureReason::ProcessingError { err: err.err.clone() },
1612+
counterparty_node_id: Some($counterparty_node_id),
1613+
channel_capacity: None,
16121614
}, None));
16131615
}
16141616
}
@@ -2270,7 +2272,9 @@ where
22702272
pending_events_lock.push_back((events::Event::ChannelClosed {
22712273
channel_id: context.channel_id(),
22722274
user_channel_id: context.get_user_id(),
2273-
reason: closure_reason
2275+
reason: closure_reason,
2276+
counterparty_node_id: Some(context.get_counterparty_node_id()),
2277+
channel_capacity: Some(context.get_value_satoshis()),
22742278
}, None));
22752279
}
22762280

@@ -8056,7 +8060,9 @@ where
80568060
channel_closures.push_back((events::Event::ChannelClosed {
80578061
channel_id: channel.context.channel_id(),
80588062
user_channel_id: channel.context.get_user_id(),
8059-
reason: ClosureReason::OutdatedChannelManager
8063+
reason: ClosureReason::OutdatedChannelManager,
8064+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8065+
channel_capacity: Some(channel.context.get_value_satoshis()),
80608066
}, None));
80618067
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
80628068
let mut found_htlc = false;
@@ -8109,6 +8115,9 @@ where
81098115
channel_id: channel.context.channel_id(),
81108116
user_channel_id: channel.context.get_user_id(),
81118117
reason: ClosureReason::DisconnectedPeer,
8118+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8119+
channel_capacity: Some(channel.context.get_value_satoshis()),
8120+
81128121
}, None));
81138122
} else {
81148123
log_error!(args.logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", log_bytes!(channel.context.channel_id()));

0 commit comments

Comments
 (0)