Skip to content

Commit a5dc8f2

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 31a0456 commit a5dc8f2

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 } => {
@@ -1245,11 +1252,15 @@ impl MaybeReadable for Event {
12451252
let mut reason = UpgradableRequired(None);
12461253
let mut user_channel_id_low_opt: Option<u64> = None;
12471254
let mut user_channel_id_high_opt: Option<u64> = None;
1255+
let mut counterparty_node_id = None;
1256+
let mut channel_capacity = None;
12481257
read_tlv_fields!(reader, {
12491258
(0, channel_id, required),
12501259
(1, user_channel_id_low_opt, option),
12511260
(2, reason, upgradable_required),
12521261
(3, user_channel_id_high_opt, option),
1262+
(5, counterparty_node_id, option),
1263+
(7, channel_capacity, option),
12531264
});
12541265

12551266
// `user_channel_id` used to be a single u64 value. In order to remain
@@ -1258,7 +1269,8 @@ impl MaybeReadable for Event {
12581269
let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
12591270
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
12601271

1261-
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required) }))
1272+
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1273+
counterparty_node_id, channel_capacity }))
12621274
};
12631275
f()
12641276
},

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,9 @@ macro_rules! handle_error {
16651665
if let Some((channel_id, user_channel_id)) = chan_id {
16661666
$self.pending_events.lock().unwrap().push_back((events::Event::ChannelClosed {
16671667
channel_id, user_channel_id,
1668-
reason: ClosureReason::ProcessingError { err: err.err.clone() }
1668+
reason: ClosureReason::ProcessingError { err: err.err.clone() },
1669+
counterparty_node_id: Some($counterparty_node_id),
1670+
channel_capacity: None,
16691671
}, None));
16701672
}
16711673
}
@@ -2359,7 +2361,9 @@ where
23592361
pending_events_lock.push_back((events::Event::ChannelClosed {
23602362
channel_id: context.channel_id(),
23612363
user_channel_id: context.get_user_id(),
2362-
reason: closure_reason
2364+
reason: closure_reason,
2365+
counterparty_node_id: Some(context.get_counterparty_node_id()),
2366+
channel_capacity: Some(context.get_value_satoshis()),
23632367
}, None));
23642368
}
23652369

@@ -8262,7 +8266,9 @@ where
82628266
channel_closures.push_back((events::Event::ChannelClosed {
82638267
channel_id: channel.context.channel_id(),
82648268
user_channel_id: channel.context.get_user_id(),
8265-
reason: ClosureReason::OutdatedChannelManager
8269+
reason: ClosureReason::OutdatedChannelManager,
8270+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8271+
channel_capacity: Some(channel.context.get_value_satoshis()),
82668272
}, None));
82678273
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
82688274
let mut found_htlc = false;
@@ -8314,6 +8320,9 @@ where
83148320
channel_id: channel.context.channel_id(),
83158321
user_channel_id: channel.context.get_user_id(),
83168322
reason: ClosureReason::DisconnectedPeer,
8323+
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
8324+
channel_capacity: Some(channel.context.get_value_satoshis()),
8325+
83178326
}, None));
83188327
} else {
83198328
log_error!(args.logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", log_bytes!(channel.context.channel_id()));

0 commit comments

Comments
 (0)