@@ -205,6 +205,10 @@ pub enum MonitorEvent {
205205 /// channel.
206206 HolderForceClosed ( OutPoint ) ,
207207
208+ /// Indicates that we've detected a commitment transaction (either holder's or counterparty's)
209+ /// be included in a block and should consider the channel closed.
210+ CommitmentTxConfirmed ( ( ) ) ,
211+
208212 /// Indicates a [`ChannelMonitor`] update has completed. See
209213 /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
210214 ///
@@ -236,6 +240,7 @@ impl_writeable_tlv_based_enum_upgradable_legacy!(MonitorEvent,
236240 ( 4 , channel_id, required) ,
237241 } ,
238242;
243+ ( 1 , CommitmentTxConfirmed ) ,
239244 ( 2 , HTLCEvent ) ,
240245 ( 4 , HolderForceClosed ) ,
241246 // 6 was `UpdateFailed` until LDK 0.0.117
@@ -5088,6 +5093,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
50885093 ) ;
50895094 log_info ! ( logger, "Channel {} closed by funding output spend in txid {txid}" ,
50905095 self . channel_id( ) ) ;
5096+ if !self . funding_spend_seen {
5097+ self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxConfirmed ( ( ) ) ) ;
5098+ }
50915099 self . funding_spend_seen = true ;
50925100
50935101 let mut balance_spendable_csv = None ;
@@ -6371,6 +6379,7 @@ mod tests {
63716379 use bitcoin:: { Sequence , Witness } ;
63726380
63736381 use crate :: chain:: chaininterface:: LowerBoundedFeeEstimator ;
6382+ use crate :: events:: ClosureReason ;
63746383
63756384 use super :: ChannelMonitorUpdateStep ;
63766385 use crate :: chain:: channelmonitor:: { ChannelMonitor , WithChannelMonitor } ;
@@ -6468,22 +6477,26 @@ mod tests {
64686477 // Build a new ChannelMonitorUpdate which contains both the failing commitment tx update
64696478 // and provides the claim preimages for the two pending HTLCs. The first update generates
64706479 // an error, but the point of this test is to ensure the later updates are still applied.
6471- let monitor_updates = nodes[ 1 ] . chain_monitor . monitor_updates . lock ( ) . unwrap ( ) ;
6472- let mut replay_update = monitor_updates. get ( & channel. 2 ) . unwrap ( ) . iter ( ) . next_back ( ) . unwrap ( ) . clone ( ) ;
6473- assert_eq ! ( replay_update. updates. len( ) , 1 ) ;
6474- if let ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. } = replay_update. updates [ 0 ] {
6475- } else { panic ! ( ) ; }
6476- replay_update. updates . push ( ChannelMonitorUpdateStep :: PaymentPreimage {
6477- payment_preimage : payment_preimage_1, payment_info : None ,
6478- } ) ;
6479- replay_update. updates . push ( ChannelMonitorUpdateStep :: PaymentPreimage {
6480- payment_preimage : payment_preimage_2, payment_info : None ,
6481- } ) ;
6480+ let replay_update = {
6481+ let monitor_updates = nodes[ 1 ] . chain_monitor . monitor_updates . lock ( ) . unwrap ( ) ;
6482+ let mut replay_update = monitor_updates. get ( & channel. 2 ) . unwrap ( ) . iter ( ) . next_back ( ) . unwrap ( ) . clone ( ) ;
6483+ assert_eq ! ( replay_update. updates. len( ) , 1 ) ;
6484+ if let ChannelMonitorUpdateStep :: LatestCounterpartyCommitmentTXInfo { .. } = replay_update. updates [ 0 ] {
6485+ } else { panic ! ( ) ; }
6486+ replay_update. updates . push ( ChannelMonitorUpdateStep :: PaymentPreimage {
6487+ payment_preimage : payment_preimage_1, payment_info : None ,
6488+ } ) ;
6489+ replay_update. updates . push ( ChannelMonitorUpdateStep :: PaymentPreimage {
6490+ payment_preimage : payment_preimage_2, payment_info : None ,
6491+ } ) ;
6492+ replay_update
6493+ } ;
64826494
64836495 let broadcaster = TestBroadcaster :: with_blocks ( Arc :: clone ( & nodes[ 1 ] . blocks ) ) ;
64846496 assert ! (
64856497 pre_update_monitor. update_monitor( & replay_update, &&broadcaster, &&chanmon_cfgs[ 1 ] . fee_estimator, & nodes[ 1 ] . logger)
64866498 . is_err( ) ) ;
6499+
64876500 // Even though we error'd on the first update, we should still have generated an HTLC claim
64886501 // transaction
64896502 let txn_broadcasted = broadcaster. txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -6495,7 +6508,12 @@ mod tests {
64956508 assert_eq ! ( htlc_txn. len( ) , 2 ) ;
64966509 check_spends ! ( htlc_txn[ 0 ] , broadcast_tx) ;
64976510 check_spends ! ( htlc_txn[ 1 ] , broadcast_tx) ;
6511+
6512+ check_closed_broadcast ( & nodes[ 1 ] , 1 , true ) ;
6513+ check_closed_event ( & nodes[ 1 ] , 1 , ClosureReason :: CommitmentTxConfirmed , false , & [ nodes[ 0 ] . node . get_our_node_id ( ) ] , 100000 ) ;
6514+ check_added_monitors ( & nodes[ 1 ] , 1 ) ;
64986515 }
6516+
64996517 #[ test]
65006518 fn test_funding_spend_refuses_updates ( ) {
65016519 do_test_funding_spend_refuses_updates ( true ) ;
0 commit comments