@@ -205,6 +205,10 @@ pub enum MonitorEvent {
205
205
/// channel.
206
206
HolderForceClosed ( OutPoint ) ,
207
207
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
+
208
212
/// Indicates a [`ChannelMonitor`] update has completed. See
209
213
/// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
210
214
///
@@ -236,6 +240,7 @@ impl_writeable_tlv_based_enum_upgradable_legacy!(MonitorEvent,
236
240
( 4 , channel_id, required) ,
237
241
} ,
238
242
;
243
+ ( 1 , CommitmentTxConfirmed ) ,
239
244
( 2 , HTLCEvent ) ,
240
245
( 4 , HolderForceClosed ) ,
241
246
// 6 was `UpdateFailed` until LDK 0.0.117
@@ -5088,6 +5093,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
5088
5093
) ;
5089
5094
log_info ! ( logger, "Channel {} closed by funding output spend in txid {txid}" ,
5090
5095
self . channel_id( ) ) ;
5096
+ if !self . funding_spend_seen {
5097
+ self . pending_monitor_events . push ( MonitorEvent :: CommitmentTxConfirmed ( ( ) ) ) ;
5098
+ }
5091
5099
self . funding_spend_seen = true ;
5092
5100
5093
5101
let mut balance_spendable_csv = None ;
@@ -6371,6 +6379,7 @@ mod tests {
6371
6379
use bitcoin:: { Sequence , Witness } ;
6372
6380
6373
6381
use crate :: chain:: chaininterface:: LowerBoundedFeeEstimator ;
6382
+ use crate :: events:: ClosureReason ;
6374
6383
6375
6384
use super :: ChannelMonitorUpdateStep ;
6376
6385
use crate :: chain:: channelmonitor:: { ChannelMonitor , WithChannelMonitor } ;
@@ -6468,22 +6477,26 @@ mod tests {
6468
6477
// Build a new ChannelMonitorUpdate which contains both the failing commitment tx update
6469
6478
// and provides the claim preimages for the two pending HTLCs. The first update generates
6470
6479
// 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
+ } ;
6482
6494
6483
6495
let broadcaster = TestBroadcaster :: with_blocks ( Arc :: clone ( & nodes[ 1 ] . blocks ) ) ;
6484
6496
assert ! (
6485
6497
pre_update_monitor. update_monitor( & replay_update, &&broadcaster, &&chanmon_cfgs[ 1 ] . fee_estimator, & nodes[ 1 ] . logger)
6486
6498
. is_err( ) ) ;
6499
+
6487
6500
// Even though we error'd on the first update, we should still have generated an HTLC claim
6488
6501
// transaction
6489
6502
let txn_broadcasted = broadcaster. txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
@@ -6495,7 +6508,12 @@ mod tests {
6495
6508
assert_eq ! ( htlc_txn. len( ) , 2 ) ;
6496
6509
check_spends ! ( htlc_txn[ 0 ] , broadcast_tx) ;
6497
6510
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 ) ;
6498
6515
}
6516
+
6499
6517
#[ test]
6500
6518
fn test_funding_spend_refuses_updates ( ) {
6501
6519
do_test_funding_spend_refuses_updates ( true ) ;
0 commit comments