@@ -1326,6 +1326,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1326
1326
self . list_channels_with_filter ( |& ( _, ref channel) | channel. is_live ( ) )
1327
1327
}
1328
1328
1329
+ /// Helper function that issues the channel close events
1330
+ fn issue_channel_close_events ( & self , channel : & Channel < Signer > , closure_reason : ClosureReason ) {
1331
+ let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1332
+ match channel. unbroadcasted_funding ( ) {
1333
+ Some ( transaction) => {
1334
+ pending_events_lock. push ( events:: Event :: DiscardFunding { channel_id : channel. channel_id ( ) , transaction } )
1335
+ } ,
1336
+ None => { } ,
1337
+ }
1338
+ pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : closure_reason } ) ;
1339
+ }
1340
+
1329
1341
fn close_channel_internal ( & self , channel_id : & [ u8 ; 32 ] , target_feerate_sats_per_1000_weight : Option < u32 > ) -> Result < ( ) , APIError > {
1330
1342
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1331
1343
@@ -1372,12 +1384,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1372
1384
msg : channel_update
1373
1385
} ) ;
1374
1386
}
1375
- if let Ok ( mut pending_events_lock) = self . pending_events . lock ( ) {
1376
- pending_events_lock. push ( events:: Event :: ChannelClosed {
1377
- channel_id : * channel_id,
1378
- reason : ClosureReason :: HolderForceClosed
1379
- } ) ;
1380
- }
1387
+ self . issue_channel_close_events ( & channel, ClosureReason :: HolderForceClosed ) ;
1381
1388
}
1382
1389
break Ok ( ( ) ) ;
1383
1390
} ,
@@ -1468,13 +1475,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1468
1475
if let Some ( short_id) = chan. get ( ) . get_short_channel_id ( ) {
1469
1476
channel_state. short_to_id . remove ( & short_id) ;
1470
1477
}
1471
- let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1472
1478
if peer_node_id. is_some ( ) {
1473
1479
if let Some ( peer_msg) = peer_msg {
1474
- pending_events_lock . push ( events :: Event :: ChannelClosed { channel_id : * channel_id , reason : ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } } ) ;
1480
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } ) ;
1475
1481
}
1476
1482
} else {
1477
- pending_events_lock . push ( events :: Event :: ChannelClosed { channel_id : * channel_id , reason : ClosureReason :: HolderForceClosed } ) ;
1483
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: HolderForceClosed ) ;
1478
1484
}
1479
1485
chan. remove_entry ( ) . 1
1480
1486
} else {
@@ -3574,7 +3580,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3574
3580
msg : update
3575
3581
} ) ;
3576
3582
}
3577
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : msg . channel_id , reason : ClosureReason :: CooperativeClosure } ) ;
3583
+ self . issue_channel_close_events ( & chan , ClosureReason :: CooperativeClosure ) ;
3578
3584
}
3579
3585
Ok ( ( ) )
3580
3586
}
@@ -3986,7 +3992,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3986
3992
msg : update
3987
3993
} ) ;
3988
3994
}
3989
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
3995
+ self . issue_channel_close_events ( & chan, ClosureReason :: CommitmentTxConfirmed ) ;
3990
3996
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3991
3997
node_id : chan. get_counterparty_node_id ( ) ,
3992
3998
action : msgs:: ErrorAction :: SendErrorMessage {
@@ -4102,12 +4108,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4102
4108
} ) ;
4103
4109
}
4104
4110
4105
- if let Ok ( mut pending_events_lock) = self . pending_events . lock ( ) {
4106
- pending_events_lock. push ( events:: Event :: ChannelClosed {
4107
- channel_id : * channel_id,
4108
- reason : ClosureReason :: CooperativeClosure
4109
- } ) ;
4110
- }
4111
+ self . issue_channel_close_events ( chan, ClosureReason :: CooperativeClosure ) ;
4111
4112
4112
4113
log_info ! ( self . logger, "Broadcasting {}" , log_tx!( tx) ) ;
4113
4114
self . tx_broadcaster . broadcast_transaction ( & tx) ;
@@ -4529,7 +4530,7 @@ where
4529
4530
msg : update
4530
4531
} ) ;
4531
4532
}
4532
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
4533
+ self . issue_channel_close_events ( channel, ClosureReason :: CommitmentTxConfirmed ) ;
4533
4534
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4534
4535
node_id : channel. get_counterparty_node_id ( ) ,
4535
4536
action : msgs:: ErrorAction :: SendErrorMessage { msg : e } ,
@@ -4720,7 +4721,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4720
4721
msg : update
4721
4722
} ) ;
4722
4723
}
4723
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4724
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4724
4725
false
4725
4726
} else {
4726
4727
true
@@ -4735,7 +4736,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4735
4736
if let Some ( short_id) = chan. get_short_channel_id ( ) {
4736
4737
short_to_id. remove ( & short_id) ;
4737
4738
}
4738
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4739
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4739
4740
return false ;
4740
4741
} else {
4741
4742
no_channels_remain = false ;
0 commit comments