@@ -1326,6 +1326,12 @@ 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
+ pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : closure_reason } ) ;
1333
+ }
1334
+
1329
1335
fn close_channel_internal ( & self , channel_id : & [ u8 ; 32 ] , target_feerate_sats_per_1000_weight : Option < u32 > ) -> Result < ( ) , APIError > {
1330
1336
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1331
1337
@@ -1372,12 +1378,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1372
1378
msg : channel_update
1373
1379
} ) ;
1374
1380
}
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
- }
1381
+ self . issue_channel_close_events ( & channel, ClosureReason :: HolderForceClosed ) ;
1381
1382
}
1382
1383
break Ok ( ( ) ) ;
1383
1384
} ,
@@ -1468,13 +1469,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1468
1469
if let Some ( short_id) = chan. get ( ) . get_short_channel_id ( ) {
1469
1470
channel_state. short_to_id . remove ( & short_id) ;
1470
1471
}
1471
- let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1472
1472
if peer_node_id. is_some ( ) {
1473
1473
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 ( ) } } ) ;
1474
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } ) ;
1475
1475
}
1476
1476
} else {
1477
- pending_events_lock . push ( events :: Event :: ChannelClosed { channel_id : * channel_id , reason : ClosureReason :: HolderForceClosed } ) ;
1477
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: HolderForceClosed ) ;
1478
1478
}
1479
1479
chan. remove_entry ( ) . 1
1480
1480
} else {
@@ -3574,7 +3574,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3574
3574
msg : update
3575
3575
} ) ;
3576
3576
}
3577
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : msg . channel_id , reason : ClosureReason :: CooperativeClosure } ) ;
3577
+ self . issue_channel_close_events ( & chan , ClosureReason :: CooperativeClosure ) ;
3578
3578
}
3579
3579
Ok ( ( ) )
3580
3580
}
@@ -3986,7 +3986,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3986
3986
msg : update
3987
3987
} ) ;
3988
3988
}
3989
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
3989
+ self . issue_channel_close_events ( & chan, ClosureReason :: CommitmentTxConfirmed ) ;
3990
3990
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3991
3991
node_id : chan. get_counterparty_node_id ( ) ,
3992
3992
action : msgs:: ErrorAction :: SendErrorMessage {
@@ -4102,12 +4102,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4102
4102
} ) ;
4103
4103
}
4104
4104
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
- }
4105
+ self . issue_channel_close_events ( chan, ClosureReason :: CooperativeClosure ) ;
4111
4106
4112
4107
log_info ! ( self . logger, "Broadcasting {}" , log_tx!( tx) ) ;
4113
4108
self . tx_broadcaster . broadcast_transaction ( & tx) ;
@@ -4529,7 +4524,7 @@ where
4529
4524
msg : update
4530
4525
} ) ;
4531
4526
}
4532
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
4527
+ self . issue_channel_close_events ( channel, ClosureReason :: CommitmentTxConfirmed ) ;
4533
4528
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4534
4529
node_id : channel. get_counterparty_node_id ( ) ,
4535
4530
action : msgs:: ErrorAction :: SendErrorMessage { msg : e } ,
@@ -4720,7 +4715,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4720
4715
msg : update
4721
4716
} ) ;
4722
4717
}
4723
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4718
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4724
4719
false
4725
4720
} else {
4726
4721
true
@@ -4735,7 +4730,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4735
4730
if let Some ( short_id) = chan. get_short_channel_id ( ) {
4736
4731
short_to_id. remove ( & short_id) ;
4737
4732
}
4738
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4733
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4739
4734
return false ;
4740
4735
} else {
4741
4736
no_channels_remain = false ;
0 commit comments