Skip to content

Commit de909da

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 df237ba commit de909da

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lightning/src/events/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,12 @@ pub enum Event {
750750
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
751751
user_channel_id: u128,
752752
/// The reason the channel was closed.
753-
reason: ClosureReason
753+
reason: ClosureReason,
754+
/// Counterparty in the closed channel.
755+
counterparty_node_id: Option<PublicKey>,
756+
/// Value of the closing channel (sats).
757+
channel_capacity: Option<u64>,
758+
754759
},
755760
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
756761
/// inputs for another purpose.
@@ -951,7 +956,7 @@ impl Writeable for Event {
951956
(5, outbound_amount_forwarded_msat, option),
952957
});
953958
},
954-
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => {
959+
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason, ref counterparty_node_id, ref channel_capacity } => {
955960
9u8.write(writer)?;
956961
// `user_channel_id` used to be a single u64 value. In order to remain backwards
957962
// compatible with versions prior to 0.0.113, the u128 is serialized as two
@@ -963,6 +968,8 @@ impl Writeable for Event {
963968
(1, user_channel_id_low, required),
964969
(2, reason, required),
965970
(3, user_channel_id_high, required),
971+
(5, counterparty_node_id, option),
972+
(7, channel_capacity, option),
966973
});
967974
},
968975
&Event::DiscardFunding { ref channel_id, ref transaction } => {
@@ -1247,11 +1254,15 @@ impl MaybeReadable for Event {
12471254
let mut reason = UpgradableRequired(None);
12481255
let mut user_channel_id_low_opt: Option<u64> = None;
12491256
let mut user_channel_id_high_opt: Option<u64> = None;
1257+
let mut counterparty_node_id = None;
1258+
let mut channel_capacity = None;
12501259
read_tlv_fields!(reader, {
12511260
(0, channel_id, required),
12521261
(1, user_channel_id_low_opt, option),
12531262
(2, reason, upgradable_required),
12541263
(3, user_channel_id_high_opt, option),
1264+
(5, counterparty_node_id, option),
1265+
(7, channel_capacity, option),
12551266
});
12561267

12571268
// `user_channel_id` used to be a single u64 value. In order to remain
@@ -1260,7 +1271,8 @@ impl MaybeReadable for Event {
12601271
let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
12611272
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
12621273

1263-
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required) }))
1274+
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1275+
counterparty_node_id, channel_capacity }))
12641276
};
12651277
f()
12661278
},

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,9 @@ macro_rules! handle_error {
16721672
if let Some((channel_id, user_channel_id)) = chan_id {
16731673
$self.pending_events.lock().unwrap().push_back((events::Event::ChannelClosed {
16741674
channel_id, user_channel_id,
1675-
reason: ClosureReason::ProcessingError { err: err.err.clone() }
1675+
reason: ClosureReason::ProcessingError { err: err.err.clone() },
1676+
counterparty_node_id: Some($counterparty_node_id),
1677+
channel_capacity: None,
16761678
}, None));
16771679
}
16781680
}
@@ -2366,7 +2368,9 @@ where
23662368
pending_events_lock.push_back((events::Event::ChannelClosed {
23672369
channel_id: context.channel_id(),
23682370
user_channel_id: context.get_user_id(),
2369-
reason: closure_reason
2371+
reason: closure_reason,
2372+
counterparty_node_id: Some(context.get_counterparty_node_id()),
2373+
channel_capacity: Some(context.get_value_satoshis()),
23702374
}, None));
23712375
}
23722376

@@ -8291,7 +8295,9 @@ where
82918295
channel_closures.push_back((events::Event::ChannelClosed {
82928296
channel_id: channel.context.channel_id(),
82938297
user_channel_id: channel.context.get_user_id(),
8294-
reason: ClosureReason::OutdatedChannelManager
8298+
reason: ClosureReason::OutdatedChannelManager,
8299+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8300+
channel_capacity: Some(channel.context.get_value_satoshis()),
82958301
}, None));
82968302
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
82978303
let mut found_htlc = false;
@@ -8343,6 +8349,9 @@ where
83438349
channel_id: channel.context.channel_id(),
83448350
user_channel_id: channel.context.get_user_id(),
83458351
reason: ClosureReason::DisconnectedPeer,
8352+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8353+
channel_capacity: Some(channel.context.get_value_satoshis()),
8354+
83468355
}, None));
83478356
} else {
83488357
log_error!(args.logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", log_bytes!(channel.context.channel_id()));

0 commit comments

Comments
 (0)