Skip to content

Commit 3b7674b

Browse files
committed
Add channel funding txo to Channel Event::ChannelClosed
1 parent 4deb263 commit 3b7674b

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lightning/src/events/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use bump_transaction::BumpTransactionEvent;
2121
use crate::sign::SpendableOutputDescriptor;
2222
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
2323
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
24+
use crate::chain::transaction;
2425
use crate::ln::features::ChannelTypeFeatures;
2526
use crate::ln::msgs;
2627
use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
@@ -886,6 +887,8 @@ pub enum Event {
886887
///
887888
/// This field will be `None` for objects serialized prior to LDK 0.0.117.
888889
channel_capacity_sats: Option<u64>,
890+
/// The original channel funding TXO; this helps checking for the existence and confirmation status of the closing tx
891+
channel_funding_txo: Option<transaction::OutPoint>,
889892
},
890893
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
891894
/// inputs for another purpose.
@@ -1091,7 +1094,7 @@ impl Writeable for Event {
10911094
});
10921095
},
10931096
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
1094-
ref counterparty_node_id, ref channel_capacity_sats
1097+
ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo
10951098
} => {
10961099
9u8.write(writer)?;
10971100
// `user_channel_id` used to be a single u64 value. In order to remain backwards
@@ -1106,6 +1109,7 @@ impl Writeable for Event {
11061109
(3, user_channel_id_high, required),
11071110
(5, counterparty_node_id, option),
11081111
(7, channel_capacity_sats, option),
1112+
(9, channel_funding_txo, option),
11091113
});
11101114
},
11111115
&Event::DiscardFunding { ref channel_id, ref transaction } => {
@@ -1405,13 +1409,15 @@ impl MaybeReadable for Event {
14051409
let mut user_channel_id_high_opt: Option<u64> = None;
14061410
let mut counterparty_node_id = None;
14071411
let mut channel_capacity_sats = None;
1412+
let mut channel_funding_txo = None;
14081413
read_tlv_fields!(reader, {
14091414
(0, channel_id, required),
14101415
(1, user_channel_id_low_opt, option),
14111416
(2, reason, upgradable_required),
14121417
(3, user_channel_id_high_opt, option),
14131418
(5, counterparty_node_id, option),
14141419
(7, channel_capacity_sats, option),
1420+
(9, channel_funding_txo, option),
14151421
});
14161422

14171423
// `user_channel_id` used to be a single u64 value. In order to remain
@@ -1421,7 +1427,7 @@ impl MaybeReadable for Event {
14211427
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
14221428

14231429
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1424-
counterparty_node_id, channel_capacity_sats }))
1430+
counterparty_node_id, channel_capacity_sats, channel_funding_txo }))
14251431
};
14261432
f()
14271433
},

lightning/src/ln/channelmanager.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,10 @@ impl Into<u16> for FailureCode {
546546
struct MsgHandleErrInternal {
547547
err: msgs::LightningError,
548548
chan_id: Option<(ChannelId, u128)>, // If Some a channel of ours has been closed
549-
shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
549+
shutdown_finish: Option<(ShutdownResult,
550+
Option<msgs::ChannelUpdate>)>,
550551
channel_capacity: Option<u64>,
552+
channel_funding_txo: Option<OutPoint>,
551553
}
552554
impl MsgHandleErrInternal {
553555
#[inline]
@@ -565,14 +567,15 @@ impl MsgHandleErrInternal {
565567
chan_id: None,
566568
shutdown_finish: None,
567569
channel_capacity: None,
570+
channel_funding_txo: None,
568571
}
569572
}
570573
#[inline]
571574
fn from_no_close(err: msgs::LightningError) -> Self {
572-
Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None }
575+
Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None, channel_funding_txo: None }
573576
}
574577
#[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 {
578+
fn from_finish_shutdown(err: String, channel_id: ChannelId, user_channel_id: u128, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>, channel_capacity: u64, channel_funding_txo: Option<OutPoint>) -> Self {
576579
let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() };
577580
let action = if shutdown_res.monitor_update.is_some() {
578581
// We have a closing `ChannelMonitorUpdate`, which means the channel was funded and we
@@ -586,7 +589,8 @@ impl MsgHandleErrInternal {
586589
err: LightningError { err, action },
587590
chan_id: Some((channel_id, user_channel_id)),
588591
shutdown_finish: Some((shutdown_res, channel_update)),
589-
channel_capacity: Some(channel_capacity)
592+
channel_capacity: Some(channel_capacity),
593+
channel_funding_txo,
590594
}
591595
}
592596
#[inline]
@@ -620,6 +624,7 @@ impl MsgHandleErrInternal {
620624
chan_id: None,
621625
shutdown_finish: None,
622626
channel_capacity: None,
627+
channel_funding_txo: None,
623628
}
624629
}
625630

@@ -1956,7 +1961,7 @@ macro_rules! handle_error {
19561961

19571962
match $internal {
19581963
Ok(msg) => Ok(msg),
1959-
Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity }) => {
1964+
Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity, channel_funding_txo }) => {
19601965
let mut msg_events = Vec::with_capacity(2);
19611966

19621967
if let Some((shutdown_res, update_option)) = shutdown_finish {
@@ -1972,6 +1977,7 @@ macro_rules! handle_error {
19721977
reason: ClosureReason::ProcessingError { err: err.err.clone() },
19731978
counterparty_node_id: Some($counterparty_node_id),
19741979
channel_capacity_sats: channel_capacity,
1980+
channel_funding_txo,
19751981
}, None));
19761982
}
19771983
}
@@ -2042,9 +2048,10 @@ macro_rules! convert_chan_phase_err {
20422048
let shutdown_res = $channel.context.force_shutdown(true);
20432049
let user_id = $channel.context.get_user_id();
20442050
let channel_capacity_satoshis = $channel.context.get_value_satoshis();
2051+
let channel_funding_txo = $channel.context.get_funding_txo();
20452052

20462053
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
2047-
shutdown_res, $channel_update, channel_capacity_satoshis))
2054+
shutdown_res, $channel_update, channel_capacity_satoshis, channel_funding_txo))
20482055
},
20492056
}
20502057
};
@@ -2718,6 +2725,7 @@ where
27182725
reason: closure_reason,
27192726
counterparty_node_id: Some(context.get_counterparty_node_id()),
27202727
channel_capacity_sats: Some(context.get_value_satoshis()),
2728+
channel_funding_txo: context.get_funding_txo(),
27212729
}, None));
27222730
}
27232731

@@ -3761,7 +3769,8 @@ where
37613769
let user_id = chan.context.get_user_id();
37623770
let shutdown_res = chan.context.force_shutdown(false);
37633771
let channel_capacity = chan.context.get_value_satoshis();
3764-
(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity))
3772+
let channel_funding_txo = chan.context.get_funding_txo();
3773+
(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity, channel_funding_txo))
37653774
} else { unreachable!(); });
37663775
match funding_res {
37673776
Ok(funding_msg) => (chan, funding_msg),
@@ -10308,6 +10317,7 @@ where
1030810317
reason: ClosureReason::OutdatedChannelManager,
1030910318
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1031010319
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
10320+
channel_funding_txo: channel.context.get_funding_txo(),
1031110321
}, None));
1031210322
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
1031310323
let mut found_htlc = false;
@@ -10361,6 +10371,7 @@ where
1036110371
reason: ClosureReason::DisconnectedPeer,
1036210372
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1036310373
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
10374+
channel_funding_txo: channel.context.get_funding_txo(),
1036410375
}, None));
1036510376
} else {
1036610377
log_error!(logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", &channel.context.channel_id());

0 commit comments

Comments
 (0)